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:
25:36c6a5db50ed
Parent:
24:5d58515ba510
Child:
27:259aaa249619
--- a/emmaCode.cpp	Fri Jul 24 05:16:00 2015 +0000
+++ b/emmaCode.cpp	Fri Jul 24 15:41:47 2015 +0000
@@ -70,8 +70,8 @@
 };
 
 //ade7758 variables
-uint16_t AWattHrValue, BWattHrValue, CWattHrValue;
-uint16_t AVAHrValue, BVAHrValue, CVAHrValue;
+uint32_t AWattHrValue, BWattHrValue, CWattHrValue;
+uint32_t AVAHrValue, BVAHrValue, CVAHrValue;
 //long AWattHrSum = 0;
 //long BWattHrSum = 0;
 //long CWattHrSum = 0;
@@ -1340,7 +1340,7 @@
             
             //panel environment
             checkRxBuffer();
-            if(tPanel.read() > 60.0f) {
+            if(tPanel.read() > 900.0f) {    //900 is 15 minutes
                 int dTemp=0;
                 int dHum=0;
                 int dGas=0;
@@ -1394,7 +1394,7 @@
             
             //nodeTemp
             checkRxBuffer();
-            if(tNodes.read() > 120.0f) {
+            if(tNodes.read() > 900.0f) {    //900 is 15 minutes
                 DBG.printf("getNodesTemperature\r\n");
                 
                 for(int i=0; i<NODES_MAX; i++) {
@@ -1419,32 +1419,32 @@
                         DBG.printf("nodeTemp[%d]:%s\r\n",i,temp.c_str());
                     
                         //send node's temp
-                        seconds = time(NULL);
-                        //for(int j=0; j<sizeof(q); j++) {
-                        //    q[j]=0; }
-                        strftime(q, 32, "%Y-%m-%d %H:%M:%S",localtime(&seconds));
+                        if(temp != "0") {
+                            seconds = time(NULL);
+                            strftime(q, 32, "%Y-%m-%d %H:%M:%S",localtime(&seconds));
                         
-                        //calculate hmacTime
-                        for(int j=0; j<sizeof(p); j++) {
-                            p[j]=0; }
-                        sprintf(p,"emma-%s-%s",emmaUID.c_str(),q);   
-                        hmacTime = calculateMD5(p);
+                            //calculate hmacTime
+                            for(int j=0; j<sizeof(p); j++) {
+                                p[j]=0; }
+                            sprintf(p,"emma-%s-%s",emmaUID.c_str(),q);   
+                            hmacTime = calculateMD5(p);
                         
-                        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);
-                        wait(2);
-                        str = rxBuf;
-                        if(str.rfind("/nodetemp") != std::string::npos) {
-                            str.erase(str.begin(),str.begin()+str.rfind("/nodetemp"));
-                            if(str.find("\"status\":\"success\"") != std::string::npos) {
-                                DBG.printf("send nodeTemp success\r\n");
-                            } else {
-                                DBG.printf("send nodeTemp failed\r\n");
+                            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);
+                            wait(2);
+                            str = rxBuf;
+                            if(str.rfind("/nodetemp") != std::string::npos) {
+                                str.erase(str.begin(),str.begin()+str.rfind("/nodetemp"));
+                                if(str.find("\"status\":\"success\"") != std::string::npos) {
+                                    DBG.printf("send nodeTemp success\r\n");
+                                } else {
+                                    DBG.printf("send nodeTemp failed\r\n");
+                                }
                             }
+                            checkRxBuffer();
                         }
-                        checkRxBuffer();
                     }    
                 }
                 tNodes.reset();
@@ -1826,9 +1826,9 @@
                
         }
         
-        AWattHr = AWattHrSum * 0.0000198f;
-        BWattHr = BWattHrSum * 0.0000197f;
-        CWattHr = CWattHrSum * 0.0000196f;
+        AWattHr = AWattHrSum * 0.000044169f;    //0.0000198f;
+        BWattHr = BWattHrSum * 0.000044168f;    //0.0000197f;
+        CWattHr = CWattHrSum * 0.000044167f;    //0.0000196f;
         
         newEnergyData = true;