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:
17:b3ced0e67916
Parent:
16:3c8d0142bf63
Child:
18:87f30ba9ddc5
--- a/emmaCode.cpp	Wed Jul 15 11:44:33 2015 +0000
+++ b/emmaCode.cpp	Wed Jul 15 12:41:19 2015 +0000
@@ -128,10 +128,10 @@
     
     TP.SetCalibration(&matrix, &ScreenSample[0]);
     
-    TFT.locate(0,0);
-    TFT.printf(" X:");
-    TFT.locate(70,0);
-    TFT.printf(" Y:");
+    //TFT.locate(0,0);
+    //TFT.printf(" X:");
+    //TFT.locate(70,0);
+    //TFT.printf(" Y:");
     
     //draw border
     TFT.line(15,15,310,15,Orange);
@@ -175,7 +175,7 @@
     menu[MODE_FIRMWARE_DOWNLOAD].yTL = 25;
     menu[MODE_FIRMWARE_DOWNLOAD].xBR = 300;
     menu[MODE_FIRMWARE_DOWNLOAD].yBR = 90;
-    menu[MODE_FIRMWARE_DOWNLOAD].text = "firmware download";
+    menu[MODE_FIRMWARE_DOWNLOAD].text = "fw dwld";
     
     //reserved mode
     menu[5].xTL = 215;
@@ -184,10 +184,17 @@
     menu[5].yBR = 165;
     menu[5].text = "reserved";
     
+    //draw main menu
     for(int i=0; i<6; i++) {
         TFT.fillrect(menu[i].xTL,menu[i].yTL,menu[i].xBR,menu[i].yBR,Orange);    
     }
     
+    //add text to main menu
+    for(int i=0; i<6; i++) {
+        TFT.locate(menu[i].xTL,menu[i].yTL);
+        TFT.printf("%s",menu[i].text.c_str());    
+    }
+    
     while(!modeSelected) {
         if(!TP._tp_irq) {
             if(TP.Read_Ads7843()) {
@@ -195,10 +202,10 @@
                 TPx = TP.display.x;
                 TPy = TP.display.y;
                 TP.TP_DrawPoint(TPx,TPy, Blue);
-                TFT.locate(25,0);
-                TFT.printf("%03d",TPx);
-                TFT.locate(95,0);
-                TFT.printf("%03d",TPy);
+                //TFT.locate(25,0);
+                //TFT.printf("%03d",TPx);
+                //TFT.locate(95,0);
+                //TFT.printf("%03d",TPy);
                 
                 for(int i=0; i<6; i++) {
                     if((menu[i].xTL < TPx && TPx < menu[i].xBR) && (menu[i].yTL < TPy && TPy < menu[i].yBR)) {
@@ -341,6 +348,9 @@
     uid = s;
     writeSetting("emmaUID",uid);
     
+    TFT.locate(0,0);
+    TFT.printf(" please wait");
+    
     if(ethAvailable) {
         DBG.printf("emmaModeSettings - eth\r\n");
         
@@ -437,6 +447,11 @@
                 break;
         }
         DBG.printf("entering settings mode\r\n");
+        TFT.locate(0,0);
+        TFT.printf(" emmaModeSettings");
+        TFT.locate(0,20);
+        TFT.printf("open emma app now");
+        
         while(1) {
             char rcv[512] = {};
             rcvReply(rcv,3000);
@@ -459,8 +474,18 @@
                             int st = writeSetting(parameter[i],val.c_str());
                             if(st) {
                                 DBG.printf("%s: %s is saved\r\n",parameter[i],val.c_str());
+                                TFT.locate(0,40);
+                                TFT.printf("%s: %s is saved",parameter[i],val.c_str());
+                                wait(3);
+                                TFT.locate(0,40);
+                                TFT.printf("                                             ");
                             } else {
                                 DBG.printf("%s is not saved\r\n",parameter[i]);
+                                TFT.locate(0,40);
+                                TFT.printf("%s is not saved",parameter[i]);
+                                wait(3);
+                                TFT.locate(0,40);
+                                TFT.printf("                                             ");
                             }
                         }
                     }
@@ -472,14 +497,25 @@
                         sscanf(epTime.c_str(),"%d",&seconds);
                         set_time(seconds);
                         DBG.printf("time is set\r\n");
+                        TFT.locate(0,40);
+                        TFT.printf("time is set");
+                        wait(3);
+                        TFT.locate(0,40);
+                        TFT.printf("                                             ");
                     }
                 }    
             } else if(str.find("connect") != std::string::npos) {
                 DBG.printf("connection success!\r\n");
+                TFT.locate(0,20);
+                TFT.printf("                                             ");
+                TFT.locate(0,20);
+                TFT.printf("connection success");
             }
         }
     } else {
         DBG.printf("no eth or wifi is available\r\n");
+        TFT.locate(0,0);
+        TFT.printf(" no iface avail, please reset!");
     }
 }
 void emmaModeRegister(void) {
@@ -1065,7 +1101,7 @@
         _ESP.attach(&rxInterrupt,Serial::RxIrq);
         
         //define thread
-        osThreadDef(energyThread, osPriorityBelowNormal, (4*DEFAULT_STACK_SIZE));
+        osThreadDef(energyThread, osPriorityBelowNormal, (8*DEFAULT_STACK_SIZE));
         //create thread
         osThreadCreate(osThread(energyThread),NULL);
         
@@ -1076,7 +1112,7 @@
             checkRxBuffer();
             checkVoltagePower();
             //panelEnergy, panelVoltage, and panelPower
-            if(t.read_ms() > 10000) {
+            if(t.read_ms() > 60000) {
                 DBG.printf("[%d]WattHR for each phase: %.2f, %.2f, %.2f\r\n", loop, AWattHr, BWattHr, CWattHr);
                 TFT.locate(0,60);
                 TFT.printf("                                                  ");
@@ -1118,7 +1154,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) {
@@ -1152,7 +1188,7 @@
             checkRxBuffer();
             checkVoltagePower();
             //nodeTemp
-            if(tNodes.read_ms() > 30000) {
+            if(tNodes.read_ms() > 120000) {
                 DBG.printf("getNodesTemperature\r\n");
                 
                 for(int i=0; i<NODES_MAX; i++) {
@@ -1539,7 +1575,7 @@
         AWattHrSum = 0;
         BWattHrSum = 0;
         CWattHrSum = 0;
-        while(period < 1*60.0) {
+        while(period < 15*60.0) {
             period += ADE.getAccumulationTime(PHASE_A);
             ADE.getAccumulatedEnergy(PHASE_A, &AWattHrValue, &BWattHrValue, &CWattHrValue, &AVAHrValue, &BVAHrValue, &CVAHrValue);
             AWattHrSum += AWattHrValue;