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:
18:87f30ba9ddc5
Parent:
17:b3ced0e67916
Child:
19:7e3e9332f719
--- a/emmaCode.cpp	Wed Jul 15 12:41:19 2015 +0000
+++ b/emmaCode.cpp	Wed Jul 15 15:38:08 2015 +0000
@@ -286,6 +286,8 @@
 }
 void emmaModeWiFiConfig(void) {
     string str;
+    TFT.locate(0,0);
+    TFT.printf(" please wait");
     
     if(wifiAvailable) {
         DBG.printf("emmaModeWiFiConfig\r\n");
@@ -299,6 +301,12 @@
             if(str.find("SC_STATUS_FIND_CHANNEL") != std::string::npos)
                 break;
         }
+        
+        TFT.locate(0,0);
+        TFT.printf(" emmaModeWiFiConfig");
+        TFT.locate(0,20);
+        TFT.printf(" connect with emma app now");
+        
         DBG.printf("entering wifi configuration mode\r\n");
         while(1) {
             char rcv[128] = {};
@@ -321,16 +329,41 @@
                             int st = writeSetting(parameter[i],val.c_str());
                             if(st) {
                                 DBG.printf("%s is saved\r\n",parameter[i]);
+                                TFT.locate(0,40);
+                                TFT.printf(" %s is saved\r\n",parameter[i]);
+                                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\r\n",parameter[i]);
+                                wait(3);
+                                TFT.locate(0,40);
+                                TFT.printf("                              ");
                             }
                         }
                     }
+                    
+                    //wificonfig finish
+                    TFT.locate(0,20);
+                    TFT.printf("                                             ");
+                    TFT.locate(0,20);
+                    TFT.printf(" wificonfig finish. please restart.");
+                    
                 } 
+            } else if(str.find("SC_STATUS_GETTING_SSID_PSWD") != std::string::npos){
+                DBG.printf("app connected\r\n");
+                TFT.locate(0,20);
+                TFT.printf("                              ");
+                TFT.locate(0,20);
+                TFT.printf(" app connected");
             }
         }    
     } else {
         DBG.printf("no wifi found\r\n");
+        TFT.locate(0,20);
+        TFT.printf(" no wifi found");
     }
 }
 void emmaModeSettings(void) {
@@ -339,6 +372,9 @@
     char s[32];
     string str;
     
+    TFT.locate(0,0);
+    TFT.printf(" please wait");
+    
     //create settings dir
     mkdir("/sd/settings",0777);
     
@@ -348,9 +384,6 @@
     uid = s;
     writeSetting("emmaUID",uid);
     
-    TFT.locate(0,0);
-    TFT.printf(" please wait");
-    
     if(ethAvailable) {
         DBG.printf("emmaModeSettings - eth\r\n");
         
@@ -450,7 +483,7 @@
         TFT.locate(0,0);
         TFT.printf(" emmaModeSettings");
         TFT.locate(0,20);
-        TFT.printf("open emma app now");
+        TFT.printf(" connect with emma app now");
         
         while(1) {
             char rcv[512] = {};
@@ -475,14 +508,14 @@
                             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());
+                                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]);
+                                TFT.printf(" %s is not saved",parameter[i]);
                                 wait(3);
                                 TFT.locate(0,40);
                                 TFT.printf("                                             ");
@@ -498,24 +531,30 @@
                         set_time(seconds);
                         DBG.printf("time is set\r\n");
                         TFT.locate(0,40);
-                        TFT.printf("time is set");
+                        TFT.printf(" time is set");
                         wait(3);
                         TFT.locate(0,40);
                         TFT.printf("                                             ");
                     }
+                    
+                    //setting finish
+                    TFT.locate(0,20);
+                    TFT.printf("                                             ");
+                    TFT.locate(0,20);
+                    TFT.printf(" settings finish. please restart.");    
                 }    
             } 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");
+                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!");
+        TFT.printf(" no iface avail, please restart!");
     }
 }
 void emmaModeRegister(void) {
@@ -532,6 +571,9 @@
     string regKey;
     Timer t;
     
+    TFT.locate(0,0);
+    TFT.printf(" please wait");
+    
     //check connected interface
     //connectedIface();
     isEthConnected();
@@ -681,6 +723,8 @@
             connHost = EMMA_SERVER_HOST;
             connPort = EMMA_SERVER_PORT;
         }
+        TFT.locate(0,0);
+        TFT.printf(" emmaModeRegister");
         
         //rest begin
         if(!rest.begin(connHost.c_str(),connPort,false)) {
@@ -745,6 +789,10 @@
                             val.erase(val.begin()+val.find(")"),val.end());
                             regKey = val;
                             DBG.printf("%s: %s\r\n",parameter[3],regKey.c_str());
+                            
+                            TFT.locate(0,20);
+                            TFT.printf(" %s: %s\r\n",parameter[3],regKey.c_str());
+                            
                             emmaGetRegKey = true;
                         }
                     }
@@ -778,6 +826,10 @@
                     s[i]=0; }
                 rest.getResponse(s,sizeof(s));
                 DBG.printf("rsp vrf:%s\r\n",s);
+                TFT.locate(0,40);
+                TFT.printf("                              ");
+                TFT.locate(0,40);
+                TFT.printf(" wait:%d\r\n",loop);
                 
                 //check verification
                 str = s;
@@ -789,7 +841,11 @@
                     parse(jsonValue,str.c_str());
                     if(jsonValue.hasMember("user")) {
                         string val = jsonValue["user"].get<std::string>();
-                        DBG.printf("%s is registered\r\n",val.c_str());
+                        DBG.printf(" %s is registered\r\n",val.c_str());
+                        TFT.locate(0,40);
+                        TFT.printf("                              ");
+                        TFT.locate(0,40);
+                        TFT.printf(" %s is registered\r\n",val.c_str());
                         emmaRegistered = true;
                     }
                 }
@@ -800,8 +856,12 @@
             //check whether registration success
             if(emmaRegistered) {
                 DBG.printf("registration successful\r\n");
+                TFT.locate(0,60);
+                TFT.printf(" registration successful\r\n");
             } else {
                 DBG.printf("registration unsuccessful\r\n");
+                TFT.locate(0,60);
+                TFT.printf(" egistration unsuccessful. please restart.\r\n");
             }
             while(1);
         }
@@ -811,6 +871,8 @@
         
     } else {
         DBG.printf("no eth, wifi, or gprs is connected\r\n");
+        TFT.locate(0,60);
+        TFT.printf(" no iface connected. please restart.\r\n");
     }
 }