able to subscribe for >10hrs and still running

Dependencies:   ADE7758_v1 Crypto DHT11 MQTT MbedJSONValue SDFileSystem SPI_TFT_ILI9341 SWSPI SetRTC TFT_fonts Touch W5500Interface mbed-rtos mbed-src tuanpm

Fork of PB_emma_controller_mbed_src by Emma

Revision:
15:136526c28afb
Parent:
14:8287f0f5d987
Child:
16:3c8d0142bf63
--- a/emmaCode.cpp	Tue Jul 14 16:48:24 2015 +0000
+++ b/emmaCode.cpp	Wed Jul 15 02:36:24 2015 +0000
@@ -1117,7 +1117,7 @@
                     strftime(q, 32, "%Y-%m-%d %H:%M:%S\r\n",localtime(&seconds));
                     sprintf(s,"{\"uid\":\"%s\",\"hmac\":\"%s\",\"time\":\"%s\",\"energy\":%.2f,\"voltage\":%.2f,\"power\":%.2f}",
                     emmaUID.c_str(),hmac.c_str(),q,XWattHr,XVrms,XWatt);
-                    DBG.printf("dataEnergy:%s\r\n",s);
+                    //DBG.printf("dataEnergy:%s\r\n",s);
                     rest.post(r,s);
                     wait(2);
                     if(rxBuf.find("\"status\":\"success\"") != std::string::npos) {
@@ -1182,7 +1182,7 @@
                         strftime(q, 32, "%Y-%m-%d %H:%M:%S\r\n",localtime(&seconds));
                         sprintf(s,"{\"uid\":\"%s\",\"hmac\":\"%s\",\"time\":\"%s\",\"mac\":\"%s\",\"value\":%s}",
                         emmaUID.c_str(),hmac.c_str(),q,nodes[i].macAddr.c_str(),temp.c_str());
-                        DBG.printf("dataNodeTemp:%s\r\n",s);
+                        //DBG.printf("dataNodeTemp:%s\r\n",s);
                         rest.post("/emma/api/controller/nodetemp",s);
                         wait(2);
                         temp = rxBuf;
@@ -1211,20 +1211,21 @@
                 
                 MbedJSONValue jsonValue;
                 parse(jsonValue,globalCommand.c_str());
-                char *parameter[4] = {"nType","nAddr","dType","cmd"};
+                char *parameter[5] = {"name","nType","nAddr","dType","cmd"};
                 
                 //check whether command is valid
                 bool validCommand = true;
-                for(int i=0; i<4; i++) {
+                for(int i=0; i<5; i++) {
                     validCommand = validCommand && jsonValue.hasMember(parameter[i]);
                 }
                 DBG.printf("command validity:%d\r\n",validCommand);
                 
                 if(validCommand) {
-                    string commandNType = jsonValue[parameter[0]].get<std::string>();
-                    string commandNAddr = jsonValue[parameter[1]].get<std::string>();
-                    string commandDType = jsonValue[parameter[2]].get<std::string>();
-                    string commandCmd = jsonValue[parameter[3]].get<std::string>();
+                    string commandName = jsonValue[parameter[0]].get<std::string>();
+                    string commandNType = jsonValue[parameter[1]].get<std::string>();
+                    string commandNAddr = jsonValue[parameter[2]].get<std::string>();
+                    string commandDType = jsonValue[parameter[3]].get<std::string>();
+                    string commandCmd = jsonValue[parameter[4]].get<std::string>();
                     
                     if(commandNType == "0") {       //switch on panel controller
                         DBG.printf("command for switch\r\n");
@@ -1247,7 +1248,7 @@
                     
                         //execution process
                         int trial;
-                        string execResult = "notExecuted";
+                        string execResult = "failed";
                         if(idx != NODES_INVALID) {
                             DBG.printf("index found at %d\r\n",idx);
                         
@@ -1290,7 +1291,7 @@
                                     TFT.locate(0,180);
                                     TFT.printf("                                        ");
                                     TFT.foreground(White);
-                                    execResult = "executed";
+                                    execResult = "success";
                                     break;    
                                 }
                                 trial++;
@@ -1310,8 +1311,8 @@
                         wait(2);       
                         //send execution result
                         DBG.printf("send execution result\r\n");
-                        sprintf(s,"{\"nType\":\"%s\",\"nAddr\":\"%s\",\"dType\":\"%s\",\"cmd\":\"%s\",\"result\":\"%s\"}",
-                        commandNType.c_str(),commandNAddr.c_str(),commandDType.c_str(),commandCmd.c_str(),execResult.c_str());
+                        sprintf(s,"{\"uid\":\"%s\",\"nType\":\"%s\",\"nAddr\":\"%s\",\"dType\":\"%s\",\"cmd\":\"%s\",\"result\":\"%s\",\"name\":\"%s\"}",
+                        emmaUID.c_str(), commandNType.c_str(),commandNAddr.c_str(),commandDType.c_str(),commandCmd.c_str(),execResult.c_str(),commandName.c_str());
                     
                         trial=0;
                         while(1) {