mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
Fixed issues in arduino temperature sensor
This commit is contained in:
parent
ca40019985
commit
de265f30ac
@ -43,8 +43,10 @@
|
|||||||
#define TIME 0
|
#define TIME 0
|
||||||
#define SUPER_TENANT "carbon.super"
|
#define SUPER_TENANT "carbon.super"
|
||||||
|
|
||||||
#define SERVICE_EPOINT "/endpoints"
|
#define DAS_SERVICE_EPOINT "/endpoints/temperature-http?deviceId=${DEVICE_ID}"
|
||||||
#define EVENT_STREAM "/temperature-http"
|
#define DAS_SERVICE_TEPOINT "/endpoints/t/${TENANT_DOMAIN}/temperature-http?deviceId=${DEVICE_ID}"
|
||||||
|
|
||||||
|
#define IOT_SERVICE_EPOINT "/arduino/device/${DEVICE_ID}/controls"
|
||||||
|
|
||||||
#define POLL_INTERVAL 1000
|
#define POLL_INTERVAL 1000
|
||||||
#define PUSH_INTERVAL 10000
|
#define PUSH_INTERVAL 10000
|
||||||
@ -53,19 +55,21 @@
|
|||||||
|
|
||||||
#define SERVICE_PORT 9763 //http port of iot server
|
#define SERVICE_PORT 9763 //http port of iot server
|
||||||
|
|
||||||
byte server[4] = {192,168,43,168}; //Ip address of iot server
|
byte server[4] = {192,168,1,10}; //Ip address of iot server
|
||||||
byte deviceIP[4] = { 192, 168, 43,11 }; //Ststic ip address of arduino
|
byte deviceIP[4] = { 192, 168, 1,110 }; //Ststic ip address of arduino
|
||||||
|
|
||||||
byte dns2[] = { 8, 8, 8, 8 }; //Ststic dns of arduino
|
byte dns2[] = { 8, 8, 8, 8 }; //Ststic dns of arduino
|
||||||
byte subnet[] = { 255, 255, 255, 0 }; //Ststic subnet of arduino
|
byte subnet[] = { 255, 255, 255, 0 }; //Ststic subnet of arduino
|
||||||
byte gateway[] = { 192, 168, 43, 1 }; //Ststic gateway of arduino
|
byte gateway[] = { 192, 168, 1, 1 }; //Ststic gateway of arduino
|
||||||
|
|
||||||
|
|
||||||
String host, jsonPayLoad, replyMsg, endPoint;
|
String host, jsonPayLoad, replyMsg;
|
||||||
String responseMsg, subStrn;
|
String responseMsg, subStrn;
|
||||||
double cpuTemperature =0;
|
double cpuTemperature = 0;
|
||||||
static unsigned long pushTimestamp = 0;
|
static unsigned long pushTimestamp = 0;
|
||||||
static unsigned long pollTimestamp = 0;
|
static unsigned long pollTimestamp = 0;
|
||||||
|
char charBuf[10];
|
||||||
|
String payLoad;
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -37,7 +37,6 @@ void setup()
|
|||||||
pinMode(13, OUTPUT);
|
pinMode(13, OUTPUT);
|
||||||
connectHttp();
|
connectHttp();
|
||||||
setupResource();
|
setupResource();
|
||||||
setupEndpoint();
|
|
||||||
wdt_enable(WDTO_8S);
|
wdt_enable(WDTO_8S);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,7 +97,7 @@ void setupResource(){
|
|||||||
host = "Host: " + hostIP + ":" + port;
|
host = "Host: " + hostIP + ":" + port;
|
||||||
if(DEBUG) Serial.println(host);
|
if(DEBUG) Serial.println(host);
|
||||||
|
|
||||||
jsonPayLoad = "{\"event\":"
|
jsonPayLoad = "{\"event\":{\"metaData\":";
|
||||||
jsonPayLoad += "{\"owner\":\"";
|
jsonPayLoad += "{\"owner\":\"";
|
||||||
jsonPayLoad += String(DEVICE_OWNER);
|
jsonPayLoad += String(DEVICE_OWNER);
|
||||||
jsonPayLoad += "\",\"deviceType\":\"";
|
jsonPayLoad += "\",\"deviceType\":\"";
|
||||||
@ -162,19 +162,3 @@ void setupClient(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@ -23,37 +23,33 @@ void readControls() {
|
|||||||
Serial.println("Started..");
|
Serial.println("Started..");
|
||||||
|
|
||||||
client.fastrprint(F("GET "));
|
client.fastrprint(F("GET "));
|
||||||
client.fastrprint(SERVICE_EPOINT);
|
client.fastrprint(IOT_SERVICE_EPOINT);
|
||||||
client.fastrprint(F("readcontrols"));
|
|
||||||
client.fastrprint(F(" HTTP/1.1"));
|
client.fastrprint(F(" HTTP/1.1"));
|
||||||
client.fastrprint(F("\n"));
|
client.fastrprint(F("\n"));
|
||||||
client.fastrprint(host.c_str());
|
client.fastrprint(host.c_str());
|
||||||
|
client.fastrprint(F("Authorization: Bearer ")); client.fastrprint(F(DEVICE_TOKEN)); client.fastrprint(F("\n"));
|
||||||
|
client.fastrprint(F("Content-Type: application/json")); client.fastrprint(F("\n"));
|
||||||
|
client.fastrprint(F("Accept: application/json")); client.fastrprint(F("\n"));
|
||||||
client.fastrprint(F("\n"));
|
client.fastrprint(F("\n"));
|
||||||
client.fastrprint(DEVICE_ID);
|
|
||||||
client.fastrprint(F("owner: "));
|
|
||||||
client.fastrprint(DEVICE_OWNER);
|
|
||||||
client.fastrprint(F("\n"));
|
|
||||||
client.fastrprint(F("deviceId: "));
|
|
||||||
client.fastrprint(F(DEVICE_ID));
|
|
||||||
client.fastrprint(F("\n"));
|
|
||||||
client.fastrprint(F("deviceId: "));
|
|
||||||
client.fastrprint(F("protocol: HTTP\n"));
|
|
||||||
client.println();
|
client.println();
|
||||||
|
|
||||||
|
|
||||||
delay(1000);
|
delay(1000);
|
||||||
Serial.println("Ended..");
|
|
||||||
while (client.available()) {
|
while (client.available()) {
|
||||||
char response = client.read();
|
char response = client.read();
|
||||||
responseMsg += response;
|
responseMsg += response;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Serial.println("Ended..");
|
||||||
int index = responseMsg.lastIndexOf(":");
|
int index = responseMsg.lastIndexOf(":");
|
||||||
int newLine = responseMsg.lastIndexOf("\n");
|
int newLine = responseMsg.lastIndexOf("\n");
|
||||||
subStrn = responseMsg.substring(index + 1);
|
subStrn = responseMsg.substring(index + 1);
|
||||||
responseMsg = responseMsg.substring(newLine + 1, index);
|
responseMsg = responseMsg.substring(newLine + 1, index);
|
||||||
|
|
||||||
if(DEBUG) {
|
if(DEBUG) {
|
||||||
|
Serial.print("Polling Response: ");
|
||||||
Serial.print(responseMsg);
|
Serial.print(responseMsg);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println("-------------------------------");
|
Serial.println("-------------------------------");
|
||||||
|
|||||||
@ -25,15 +25,22 @@
|
|||||||
***********************************************************************************************/
|
***********************************************************************************************/
|
||||||
|
|
||||||
void pushData(){
|
void pushData(){
|
||||||
String payLoad = "\"temperature\":";
|
|
||||||
payLoad+=cpuTemperature;
|
payLoad = "\"temperature\":";
|
||||||
|
payLoad += dtostrf(cpuTemperature, 3, 2, charBuf);
|
||||||
payLoad += "}}}";
|
payLoad += "}}}";
|
||||||
|
|
||||||
client.fastrprint(F("POST "));
|
client.fastrprint(F("POST "));
|
||||||
client.fastrprint(endPoint); client.fastrprint(F("pushdata"));
|
if (strcmp(TENANT_DOMAIN, SUPER_TENANT) == 0) {
|
||||||
|
client.fastrprint(DAS_SERVICE_EPOINT);
|
||||||
|
} else {
|
||||||
|
client.fastrprint(DAS_SERVICE_TEPOINT);
|
||||||
|
}
|
||||||
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("Authorization: Bearer ")); client.fastrprint(F(DEVICE_TOKEN)); 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"));
|
||||||
|
client.fastrprint(F("Accept: application/json")); client.fastrprint(F("\n"));
|
||||||
client.fastrprint(F("Content-Length: "));
|
client.fastrprint(F("Content-Length: "));
|
||||||
|
|
||||||
int payLength = jsonPayLoad.length() + payLoad.length();
|
int payLength = jsonPayLoad.length() + payLoad.length();
|
||||||
@ -43,8 +50,11 @@ void pushData(){
|
|||||||
|
|
||||||
if(DEBUG) {
|
if(DEBUG) {
|
||||||
Serial.print("POST ");
|
Serial.print("POST ");
|
||||||
Serial.print(SERVICE_EPOINT);
|
if (strcmp(TENANT_DOMAIN, SUPER_TENANT) == 0) {
|
||||||
Serial.print("pushdata");
|
Serial.print(DAS_SERVICE_EPOINT);
|
||||||
|
} else {
|
||||||
|
Serial.print(DAS_SERVICE_TEPOINT);
|
||||||
|
}
|
||||||
Serial.print(" HTTP/1.1"); Serial.println();
|
Serial.print(" HTTP/1.1"); Serial.println();
|
||||||
Serial.print(host); Serial.println();
|
Serial.print(host); Serial.println();
|
||||||
Serial.print("Content-Type: application/json"); Serial.println();
|
Serial.print("Content-Type: application/json"); Serial.println();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user