Fixed issues in arduino temperature agent

merge-requests/1/head
mharindu 9 years ago
parent 84daf6216b
commit 0993e5125a

@ -39,8 +39,12 @@
#define DEVICE_ID "${DEVICE_ID}"
#define DEVICE_TOKEN "${DEVICE_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 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
String host, jsonPayLoad, replyMsg;
String host, jsonPayLoad, replyMsg, endPoint;
String responseMsg, subStrn;
double cpuTemperature =0;
static unsigned long pushTimestamp = 0;

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

@ -97,11 +97,16 @@ void setupResource(){
host = "Host: " + hostIP + ":" + port;
if(DEBUG) Serial.println(host);
jsonPayLoad = "{\"owner\":\"";
jsonPayLoad = "{\"event\":"
jsonPayLoad += "{\"owner\":\"";
jsonPayLoad += String(DEVICE_OWNER);
jsonPayLoad += "\",\"deviceType\":\"";
jsonPayLoad += String(DEVICE_TYPE);
jsonPayLoad += "\",\"deviceId\":\"";
jsonPayLoad += String(DEVICE_ID);
jsonPayLoad += "\",\"reply\":\"";
jsonPayLoad += "\",\"time\":";
jsonPayLoad += String(TIME);
jsonPayLoad += "}, \"payloadData\":{";
if(DEBUG) {
Serial.print("JSON Payload: ");
@ -156,3 +161,20 @@ void setupClient(){
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(){
String payLoad = "Temp";
payLoad = payLoad + "\",\"value\":\"";
String payLoad = "\"temperature\":";
payLoad+=cpuTemperature;
payLoad += "\"}";
payLoad += "}}}";
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(host.c_str()); client.fastrprint(F("\n"));
client.fastrprint(F("Content-Type: application/json")); client.fastrprint(F("\n"));
@ -104,8 +99,6 @@ void pushData(){
}
double getBoardTemp(void)
{
unsigned int wADC;

Loading…
Cancel
Save