revert-dabc3590
ayyoob 9 years ago
commit 441815afb9

@ -31,16 +31,16 @@
<Permission>
<name>control bulb</name>
<path>device-mgt/user/operations</path>
<path>/device-mgt/user/operations</path>
<url>/device/*/bulb</url>
<method>POST</method>
<scope>arduino_user</scope>
</Permission>
<Permission>
<name>get controls</name>
<path>device-mgt/user/operations</path>
<path>/device-mgt/user/operations</path>
<url>/device/*/controls</url>
<method>POST</method>
<method>GET</method>
<scope>arduino_device</scope>
</Permission>
<Permission>

@ -39,8 +39,14 @@
#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 DAS_SERVICE_EPOINT "/endpoints/temperature-http?deviceId=${DEVICE_ID}"
#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 PUSH_INTERVAL 10000
@ -49,19 +55,21 @@
#define SERVICE_PORT 9763 //http port of iot server
byte server[4] = {192,168,43,168}; //Ip address of iot server
byte deviceIP[4] = { 192, 168, 43,11 }; //Ststic ip address of arduino
byte server[4] = {192,168,1,10}; //Ip address of iot server
byte deviceIP[4] = { 192, 168, 1,110 }; //Ststic ip address of arduino
byte dns2[] = { 8, 8, 8, 8 }; //Ststic dns 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;
String responseMsg, subStrn;
double cpuTemperature =0;
double cpuTemperature = 0;
static unsigned long pushTimestamp = 0;
static unsigned long pollTimestamp = 0;
char charBuf[10];
String payLoad;
#endif

@ -97,11 +97,16 @@ void setupResource(){
host = "Host: " + hostIP + ":" + port;
if(DEBUG) Serial.println(host);
jsonPayLoad = "{\"owner\":\"";
jsonPayLoad = "{\"event\":{\"metaData\":";
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,4 @@ void setupClient(){
if(CON_DEBUG) Serial.println(F("client Connection failed"));
}
}

@ -23,37 +23,42 @@ void readControls() {
Serial.println("Started..");
client.fastrprint(F("GET "));
client.fastrprint(SERVICE_EPOINT);
client.fastrprint(F("readcontrols"));
client.fastrprint(IOT_SERVICE_EPOINT);
client.fastrprint(F(" HTTP/1.1"));
client.fastrprint(F("\n"));
client.fastrprint(host.c_str());
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("\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();
if(DEBUG) {
Serial.print("GET ");
Serial.print(IOT_SERVICE_EPOINT);
Serial.print(" HTTP/1.1"); Serial.println();
Serial.print(host); Serial.println();
Serial.print("Content-Type: application/json"); Serial.println();
Serial.println();
}
delay(1000);
Serial.println("Ended..");
while (client.available()) {
char response = client.read();
if(DEBUG) Serial.print(response);
responseMsg += response;
}
Serial.println();
Serial.println("Ended..");
int index = responseMsg.lastIndexOf(":");
int newLine = responseMsg.lastIndexOf("\n");
subStrn = responseMsg.substring(index + 1);
responseMsg = responseMsg.substring(newLine + 1, index);
if(DEBUG) {
Serial.print("Polling Response: ");
Serial.print(responseMsg);
Serial.println();
Serial.println("-------------------------------");
@ -70,6 +75,7 @@ void readControls() {
digitalWrite(6, LOW);
}
responseMsg = "";
}

@ -25,20 +25,22 @@
***********************************************************************************************/
void pushData(){
String payLoad = "Temp";
payLoad = payLoad + "\",\"value\":\"";
payLoad+=cpuTemperature;
payLoad += "\"}";
payLoad = "\"temperature\":";
payLoad += dtostrf(cpuTemperature, 3, 2, charBuf);
payLoad += "}}}";
client.fastrprint(F("POST "));
client.fastrprint(SERVICE_EPOINT); 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(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("Accept: application/json")); client.fastrprint(F("\n"));
client.fastrprint(F("Content-Length: "));
int payLength = jsonPayLoad.length() + payLoad.length();
@ -48,8 +50,11 @@ void pushData(){
if(DEBUG) {
Serial.print("POST ");
Serial.print(SERVICE_EPOINT);
Serial.print("pushdata");
if (strcmp(TENANT_DOMAIN, SUPER_TENANT) == 0) {
Serial.print(DAS_SERVICE_EPOINT);
} else {
Serial.print(DAS_SERVICE_TEPOINT);
}
Serial.print(" HTTP/1.1"); Serial.println();
Serial.print(host); Serial.println();
Serial.print("Content-Type: application/json"); Serial.println();
@ -104,8 +109,6 @@ void pushData(){
}
double getBoardTemp(void)
{
unsigned int wADC;

Loading…
Cancel
Save