From 0993e5125a76c39861a18dbf76cf4bfd35bbc1de Mon Sep 17 00:00:00 2001 From: mharindu Date: Mon, 2 May 2016 16:31:48 +0530 Subject: [PATCH] Fixed issues in arduino temperature agent --- .../main/resources/agent/ArduinoBoardSketch.h | 8 ++++-- .../resources/agent/ArduinoBoardSketch.ino | 3 +- .../src/main/resources/agent/Connect.ino | 28 +++++++++++++++++-- .../src/main/resources/agent/PushData.ino | 13 ++------- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/features/iot-plugins-feature/arduino-plugin-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/ArduinoBoardSketch.h b/features/iot-plugins-feature/arduino-plugin-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/ArduinoBoardSketch.h index d52792dfc..3e731f5c9 100644 --- a/features/iot-plugins-feature/arduino-plugin-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/ArduinoBoardSketch.h +++ b/features/iot-plugins-feature/arduino-plugin-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/ArduinoBoardSketch.h @@ -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; diff --git a/features/iot-plugins-feature/arduino-plugin-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/ArduinoBoardSketch.ino b/features/iot-plugins-feature/arduino-plugin-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/ArduinoBoardSketch.ino index 50627d074..f0461ce9b 100644 --- a/features/iot-plugins-feature/arduino-plugin-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/ArduinoBoardSketch.ino +++ b/features/iot-plugins-feature/arduino-plugin-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/ArduinoBoardSketch.ino @@ -37,6 +37,7 @@ void setup() pinMode(13, OUTPUT); connectHttp(); setupResource(); + setupEndpoint(); wdt_enable(WDTO_8S); } @@ -80,4 +81,4 @@ void loop() // //Serial.println("LOOPING"); wdt_reset(); -} \ No newline at end of file +} diff --git a/features/iot-plugins-feature/arduino-plugin-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/Connect.ino b/features/iot-plugins-feature/arduino-plugin-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/Connect.ino index dbc838a89..587658abe 100644 --- a/features/iot-plugins-feature/arduino-plugin-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/Connect.ino +++ b/features/iot-plugins-feature/arduino-plugin-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/Connect.ino @@ -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: "); @@ -155,4 +160,21 @@ void setupClient(){ } if(CON_DEBUG) Serial.println(F("client Connection failed")); } -} \ No newline at end of file +} + + +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; + +} diff --git a/features/iot-plugins-feature/arduino-plugin-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/PushData.ino b/features/iot-plugins-feature/arduino-plugin-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/PushData.ino index 6b95b4155..a4ff1674e 100644 --- a/features/iot-plugins-feature/arduino-plugin-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/PushData.ino +++ b/features/iot-plugins-feature/arduino-plugin-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/PushData.ino @@ -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;