Fixed issues in arduino temperature agent

revert-dabc3590
mharindu 9 years ago
parent 84daf6216b
commit 0993e5125a

@ -39,8 +39,12 @@
#define DEVICE_ID "${DEVICE_ID}" #define DEVICE_ID "${DEVICE_ID}"
#define DEVICE_TOKEN "${DEVICE_TOKEN}" #define DEVICE_TOKEN "${DEVICE_TOKEN}"
#define REFRESH_DEVICE_TOKEN "${DEVICE_REFRESH_TOKEN}" #define REFRESH_DEVICE_TOKEN "${DEVICE_REFRESH_TOKEN}"
#define DEVICE_TYPE "arduino"
#define TIME 0
#define SUPER_TENANT "carbon.super"
#define SERVICE_EPOINT "/arduino/controller/" #define SERVICE_EPOINT "/endpoints"
#define EVENT_STREAM "/temperature-http"
#define POLL_INTERVAL 1000 #define POLL_INTERVAL 1000
#define PUSH_INTERVAL 10000 #define PUSH_INTERVAL 10000
@ -57,7 +61,7 @@ byte subnet[] = { 255, 255, 255, 0 }; //Ststic subnet of arduino
byte gateway[] = { 192, 168, 43, 1 }; //Ststic gateway of arduino byte gateway[] = { 192, 168, 43, 1 }; //Ststic gateway of arduino
String host, jsonPayLoad, replyMsg; String host, jsonPayLoad, replyMsg, endPoint;
String responseMsg, subStrn; String responseMsg, subStrn;
double cpuTemperature =0; double cpuTemperature =0;
static unsigned long pushTimestamp = 0; static unsigned long pushTimestamp = 0;

@ -37,6 +37,7 @@ void setup()
pinMode(13, OUTPUT); pinMode(13, OUTPUT);
connectHttp(); connectHttp();
setupResource(); setupResource();
setupEndpoint();
wdt_enable(WDTO_8S); wdt_enable(WDTO_8S);
} }

@ -97,11 +97,16 @@ void setupResource(){
host = "Host: " + hostIP + ":" + port; host = "Host: " + hostIP + ":" + port;
if(DEBUG) Serial.println(host); if(DEBUG) Serial.println(host);
jsonPayLoad = "{\"owner\":\""; jsonPayLoad = "{\"event\":"
jsonPayLoad += "{\"owner\":\"";
jsonPayLoad += String(DEVICE_OWNER); jsonPayLoad += String(DEVICE_OWNER);
jsonPayLoad += "\",\"deviceType\":\"";
jsonPayLoad += String(DEVICE_TYPE);
jsonPayLoad += "\",\"deviceId\":\""; jsonPayLoad += "\",\"deviceId\":\"";
jsonPayLoad += String(DEVICE_ID); jsonPayLoad += String(DEVICE_ID);
jsonPayLoad += "\",\"reply\":\""; jsonPayLoad += "\",\"time\":";
jsonPayLoad += String(TIME);
jsonPayLoad += "}, \"payloadData\":{";
if(DEBUG) { if(DEBUG) {
Serial.print("JSON Payload: "); Serial.print("JSON Payload: ");
@ -156,3 +161,20 @@ void setupClient(){
if(CON_DEBUG) Serial.println(F("client Connection failed")); if(CON_DEBUG) Serial.println(F("client Connection failed"));
} }
} }
void setupEndpoint() {
endPoint = SERVICE_EPOINT;
// check tenant domain
if (TENANT_DOMAIN.equals(SUPER_TENANT)) {
endPoint += EVENT_STREAM;
} else {
endPoint += "/t/" + TENANT_DOMAIN;
endPoint += EVENT_STREAM;
}
endPoint += "?deviceId=";
endPoint += DEVICE_ID;
}

@ -25,17 +25,12 @@
***********************************************************************************************/ ***********************************************************************************************/
void pushData(){ void pushData(){
String payLoad = "Temp"; String payLoad = "\"temperature\":";
payLoad = payLoad + "\",\"value\":\"";
payLoad+=cpuTemperature; payLoad+=cpuTemperature;
payLoad += "}}}";
payLoad += "\"}";
client.fastrprint(F("POST ")); client.fastrprint(F("POST "));
client.fastrprint(SERVICE_EPOINT); client.fastrprint(F("pushdata")); client.fastrprint(endPoint); client.fastrprint(F("pushdata"));
client.fastrprint(F(" HTTP/1.1")); client.fastrprint(F("\n")); client.fastrprint(F(" HTTP/1.1")); client.fastrprint(F("\n"));
client.fastrprint(host.c_str()); client.fastrprint(F("\n")); client.fastrprint(host.c_str()); client.fastrprint(F("\n"));
client.fastrprint(F("Content-Type: application/json")); client.fastrprint(F("\n")); client.fastrprint(F("Content-Type: application/json")); client.fastrprint(F("\n"));
@ -104,8 +99,6 @@ void pushData(){
} }
double getBoardTemp(void) double getBoardTemp(void)
{ {
unsigned int wADC; unsigned int wADC;

Loading…
Cancel
Save