emma controller code in production board v1
Dependencies: ADE7758_v1 Crypto DHT11 MQTT MbedJSONValueEmma SDFileSystem TFT_ILI9341 SWSPI SetRTC TFT_fonts Touch W5500Interface mbed-rtos mbed-src SoftSerial
Fork of emma_controller_energy by
Diff: emmaCode.cpp
- Revision:
- 43:612547648ed1
- Parent:
- 42:b32e51a374c7
- Child:
- 44:c1d11c491237
--- a/emmaCode.cpp Thu Aug 20 09:52:41 2015 +0000 +++ b/emmaCode.cpp Thu Aug 20 13:16:16 2015 +0000 @@ -689,7 +689,7 @@ s[i]=0; } //sprintf(s,"GET http://%s:%s/emma/api/controller/register?uid=%s&hmac=%s HTTP/1.0\nHost: %s\r\n\r\n",restSERVER.c_str(),restPORT.c_str(),emmaUID.c_str(),hmac.c_str(),restSERVER.c_str()); //sprintf(s,"POST http://%s:%s/emma/api/controller/register HTTP/1.0\nHost: %s\nContent-Length: 76\n\n{\"uid\":\"%s\",\"hmac\":\"%s\"}\r\n\r\n",restSERVER.c_str(),restPORT.c_str(),restSERVER.c_str(),emmaUID.c_str(),hmac.c_str()); - sprintf(s,"POST http://%s:%s/emma/api/controller/register HTTP/1.0\nHost: %s\nContent-Length: %d\n\n%s\r\n\r\n",restSERVER.c_str(),restPORT.c_str(),restSERVER.c_str(),connBodyLen,connBody); + sprintf(s,"POST http://%s:%s/%s/api/controller/register HTTP/1.0\nHost: %s\nContent-Length: %d\n\n%s\r\n\r\n",restSERVER.c_str(),restPORT.c_str(),appNAME.c_str(),restSERVER.c_str(),connBodyLen,connBody); connData = s; } else { DBG.printf("no proxy\r\n"); @@ -700,7 +700,7 @@ s[i]=0; } //sprintf(s,"GET /emma/api/controller/register?uid=%s&hmac=%s HTTP/1.0\nHost: %s\r\n\r\n",emmaUID.c_str(),hmac.c_str(),restSERVER.c_str()); //sprintf(s,"POST /emma/api/controller/register HTTP/1.0\nHost: %s\nContent-Length: 76\n\n{\"uid\":\"%s\",\"hmac\":\"%s\"}\r\n\r\n",restSERVER.c_str(),emmaUID.c_str(),hmac.c_str()); - sprintf(s,"POST /emma/api/controller/register HTTP/1.0\nHost: %s\nContent-Length: %d\n\n%s\r\n\r\n",restSERVER.c_str(),connBodyLen,connBody); + sprintf(s,"POST /%s/api/controller/register HTTP/1.0\nHost: %s\nContent-Length: %d\n\n%s\r\n\r\n",appNAME.c_str(),restSERVER.c_str(),connBodyLen,connBody); connData = s; } @@ -768,14 +768,14 @@ for(int i=0; i<sizeof(s); i++) { s[i]=0; } //sprintf(s,"GET http://%s:%s/emma/api/controller/verify?uid=%s®istrationKey=%s&hmac=%s HTTP/1.0\nHost: %s\r\n\r\n",restSERVER.c_str(),restPORT.c_str(),emmaUID.c_str(),regKey.c_str(),hmac.c_str(),restSERVER.c_str()); - sprintf(s,"POST http://%s:%s/emma/api/controller/verify HTTP/1.0\nHost: %s\nContent-Length: %d\n\n%s\r\n\r\n",restSERVER.c_str(),restPORT.c_str(),restSERVER.c_str(),connBodyLen,connBody); + sprintf(s,"POST http://%s:%s/%s/api/controller/verify HTTP/1.0\nHost: %s\nContent-Length: %d\n\n%s\r\n\r\n",restSERVER.c_str(),restPORT.c_str(),appNAME.c_str(),restSERVER.c_str(),connBodyLen,connBody); connData = s; } else { DBG.printf("no proxy\r\n"); for(int i=0; i<sizeof(s); i++) { s[i]=0; } //sprintf(s,"GET /emma/api/controller/verify?uid=%s®istrationKey=%s&hmac=%s HTTP/1.0\nHost: %s\r\n\r\n",emmaUID.c_str(),regKey.c_str(),hmac.c_str(),restSERVER.c_str()); - sprintf(s,"POST /emma/api/controller/verify HTTP/1.0\nHost: %s\nContent-Length: %d\n\n%s\r\n\r\n",restSERVER.c_str(),connBodyLen,connBody); + sprintf(s,"POST /%s/api/controller/verify HTTP/1.0\nHost: %s\nContent-Length: %d\n\n%s\r\n\r\n",appNAME.c_str(),restSERVER.c_str(),connBodyLen,connBody); connData = s; } @@ -859,12 +859,12 @@ if(wifiConnected) { //check proxy if(useProxy) { - sprintf(r,"http://%s:%s/emma/api/controller/register",restSERVER.c_str(),restPORT.c_str()); + sprintf(r,"http://%s:%s/%s/api/controller/register",restSERVER.c_str(),restPORT.c_str(),appNAME.c_str()); //sprintf(r,"http://%s:%d/emma/api/controller/register HTTP/1.0\nHost: %s:%d\nProxy-Authorization: Basic %s\nCache-Control: no-cache\nContent-Length: %d\n\n",restSERVER,restPORT,restSERVER,restPORT,proxyAUTH.c_str(),76); //sprintf(r,"http://%s:%d/emma/api/controller/register HTTP/1.0\nAccept: */*\nAccept-Encoding: gzip,deflate\nContent-Length: %d\r\n\r\n",restSERVER,restPORT,76); //sprintf(r,"http://%s:%d/emma/coba",restSERVER,REST_SERVER_PORT); } else { - sprintf(r,"/emma/api/controller/register"); + sprintf(r,"/%s/api/controller/register",appNAME.c_str()); } //register @@ -934,9 +934,9 @@ //check proxy if(useProxy) { - sprintf(r,"http://%s:%d/emma/api/controller/verify",restSERVER.c_str(),restPORT.c_str()); + sprintf(r,"http://%s:%s/%s/api/controller/verify",restSERVER.c_str(),restPORT.c_str(),appNAME.c_str()); } else { - sprintf(r,"/emma/api/controller/verify"); + sprintf(r,"/%s/api/controller/verify",appNAME.c_str()); } //verify registration @@ -1366,7 +1366,7 @@ _ESP.attach(&rxInterrupt,Serial::RxIrq); //get list of nodes from server (post) - sprintf(p,"/emma/api/controller/wifinodes"); + sprintf(p,"/%s/api/controller/wifinodes",appNAME.c_str()); sprintf(s,"{\"uid\":\"%s\",\"hmac\":\"%s\"}",emmaUID.c_str(),hmacTime.c_str()); rest.post(p,s); wait(2); @@ -1545,7 +1545,7 @@ if(XWattHr != 0.0f) { - sprintf(r,"/emma/api/controller/energy/%d",i); + sprintf(r,"/%s/api/controller/energy/%d",appNAME.c_str(),i); seconds = time(NULL); //for(int j=0; j<sizeof(q); j++) { // q[j]=0; } @@ -1643,7 +1643,9 @@ sprintf(s,"{\"uid\":\"%s\",\"hmac\":\"%s\",\"time\":\"%s\",\"temp\":%d,\"hum\":%d,\"gas\":%d}", emmaUID.c_str(),hmacTime.c_str(),q,dTemp,dHum,dGas); //DBG.printf("dataEnvironment:\r\n%s\r\n",s); - rest.post("/emma/api/controller/environment",s); + sprintf(p,"/%s/api/controller/environment",appNAME.c_str()); + rest.post(p,s); + //rest.post("/emma/api/controller/environment",s); //working wait(2); str = rxBuf; if(str.rfind("/environment") != std::string::npos) { @@ -1707,7 +1709,9 @@ sprintf(s,"{\"uid\":\"%s\",\"hmac\":\"%s\",\"time\":\"%s\",\"mac\":\"%s\",\"value\":%s}", emmaUID.c_str(),hmacTime.c_str(),q,nodes[i].macAddr.c_str(),temp.c_str()); //DBG.printf("dataNodeTemp:\r\n%s\r\n",s); - rest.post("/emma/api/controller/nodetemp",s); + sprintf(p,"/%s/api/controller/nodetemp",appNAME.c_str()); + rest.post(p,s); + //rest.post("/emma/api/controller/nodetemp",s); //working wait(2); str = rxBuf; if(str.rfind("/nodetemp") != std::string::npos) { @@ -1726,7 +1730,7 @@ } //command - sprintf(r,"/emma/api/controller/command"); + sprintf(r,"/%s/api/controller/command",appNAME.c_str()); sprintf(s,"{\"uid\":\"%s\",\"hmac\":\"%s\"}", emmaUID.c_str(),hmacTime.c_str()); //rest.get("/emma/api/controller/command"); @@ -1861,7 +1865,9 @@ DBG.printf("failed to send execution result\r\n"); break; } - rest.post("/emma/api/controller/result",s); + sprintf(p,"/%s/api/controller/result",appNAME.c_str()); + rest.post(p,s); + //rest.post("/emma/api/controller/result",s); //working wait(2); str = rxBuf; if(str.rfind("/result") != std::string::npos) { @@ -1957,7 +1963,9 @@ DBG.printf("failed to send execution result\r\n"); break; } - rest.post("/emma/api/controller/result",s); + sprintf(p,"/%s/api/controller/result",appNAME.c_str()); + rest.post(p,s); + //rest.post("/emma/api/controller/result",s); //working wait(2); str = rxBuf; if(str.rfind("/result") != std::string::npos) { @@ -2401,7 +2409,10 @@ DBG.printf("alert on ch1\r\n"); sprintf(s,"{\"uid\":\"%s\",\"hmac\":\"%s\",\"time\":\"%s\",\"voltage\":%.2f,\"power\":%.2f}", emmaUID.c_str(),hmacTime.c_str(),q,AVrms,AWatt); - rest.post("/emma/api/controller/alert/1",s); + + sprintf(p,"/%s/api/controller/alert/1",appNAME.c_str()); + rest.post(p,s); + //rest.post("/emma/api/controller/alert/1",s); //working wait(2); str = rxBuf; if(str.rfind("/alert/1") != std::string::npos) { @@ -2418,7 +2429,9 @@ DBG.printf("alert on ch2\r\n"); sprintf(s,"{\"uid\":\"%s\",\"hmac\":\"%s\",\"time\":\"%s\",\"voltage\":%.2f,\"power\":%.2f}", emmaUID.c_str(),hmacTime.c_str(),q,BVrms,BWatt); - rest.post("/emma/api/controller/alert/2",s); + sprintf(p,"/%s/api/controller/alert/2",appNAME.c_str()); + rest.post(p,s); + //rest.post("/emma/api/controller/alert/2",s); wait(2); str = rxBuf; if(str.rfind("/alert/2") != std::string::npos) { @@ -2436,7 +2449,9 @@ DBG.printf("alert on ch3\r\n"); sprintf(s,"{\"uid\":\"%s\",\"hmac\":\"%s\",\"time\":\"%s\",\"voltage\":%.2f,\"power\":%.2f}", emmaUID.c_str(),hmacTime.c_str(),q,CVrms,CWatt); - rest.post("/emma/api/controller/alert/3",s); + sprintf(p,"/%s/api/controller/alert/3",appNAME.c_str()); + rest.post(p,s); + //rest.post("/emma/api/controller/alert/3",s); wait(2); str = rxBuf; if(str.rfind("/alert/3") != std::string::npos) { @@ -2956,14 +2971,14 @@ sscanf(proxyPORT.c_str(),"%d",&connPort); for(int i=0; i<sizeof(s); i++) { s[i]=0; } - sprintf(s,"GET http://%s:%s/emma/api/controller/test HTTP/1.0\nHost: %s\r\n\r\n",restSERVER.c_str(),restPORT.c_str(),restSERVER.c_str()); + sprintf(s,"GET http://%s:%s/%s/api/controller/test HTTP/1.0\nHost: %s\r\n\r\n",restSERVER.c_str(),restPORT.c_str(),appNAME.c_str(),restSERVER.c_str()); } else { connHost = restSERVER; //connPort = restPORT; sscanf(restPORT.c_str(),"%d",&connPort); for(int i=0; i<sizeof(s); i++) { s[i]=0; } - strcpy(s,"GET /emma/api/controller/test HTTP/1.0\nHost: %s\r\n\r\n"); + sprintf(s,"GET /%s/api/controller/test HTTP/1.0\nHost: %s\r\n\r\n",appNAME.c_str(),restSERVER.c_str()); } t.start(); @@ -3033,14 +3048,14 @@ sscanf(proxyPORT.c_str(),"%d",&connPort); for(int i=0; i<sizeof(s); i++) { s[i]=0; } - sprintf(s,"http://%s:%s/emma/api/controller/test HTTP/1.0\nHost: %s\r\n\r\n",restSERVER.c_str(),restPORT.c_str(),restSERVER.c_str()); + sprintf(s,"http://%s:%s/%s/api/controller/test HTTP/1.0\nHost: %s\r\n\r\n",restSERVER.c_str(),restPORT.c_str(),appNAME.c_str(),restSERVER.c_str()); } else { connHost = restSERVER; //connPort = restPORT; sscanf(restPORT.c_str(),"%d",&connPort); for(int i=0; i<sizeof(s); i++) { s[i]=0; } - sprintf(s,"/emma/api/controller/test"); + sprintf(s,"/%s/api/controller/test",appNAME.c_str()); } wait(2); t.start();