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:
- 57:4241a1711069
- Parent:
- 56:f5611e58d7f9
- Child:
- 58:5f953f303551
--- a/emmaCode.cpp Wed Sep 16 11:05:38 2015 +0000 +++ b/emmaCode.cpp Thu Sep 17 03:50:47 2015 +0000 @@ -116,7 +116,7 @@ bool gprsConnected = false; bool useProxy = false; bool newCommand = false; -bool espFreeMemory = true; //for after bootup +bool espFreeMemory = false; bool espDHCPClientStart = false; bool newEnergyData = false; string globalCommand; @@ -374,11 +374,9 @@ //check available interface isEthAvailable(); //check whether cable is connected + wifiAvailable = true; //wifi module will always on the board + gprsAvailable = true; //gprs module will always on the board - wifiAvailable = true; //wifi module will always on the board - - - gprsAvailable = true; //gprs module will always on the board DBG.printf("eth:%d\r\n",ethAvailable); DBG.printf("wifi:%d\r\n",wifiAvailable); DBG.printf("gprs:%d\r\n",gprsAvailable); @@ -717,8 +715,12 @@ //check connected interface isEthConnected(); - isWiFiConnected(); - isGprsConnected(); + if(!ethConnected) { + isWiFiConnected(); + } else if(!ethConnected && !wifiConnected) { + isGprsConnected(); + } + DBG.printf("ethConnected:%d\r\n",ethConnected); DBG.printf("wifiConnected:%d\r\n",wifiConnected); DBG.printf("gprsConnected:%d\r\n",gprsConnected); @@ -1164,8 +1166,11 @@ //check connected interface isEthConnected(); - isWiFiConnected(); - isGprsConnected(); + if(!ethConnected) { + isWiFiConnected(); + } else if(!ethConnected && !wifiConnected) { + isGprsConnected(); + } DBG.printf("ethConnected:%d\r\n",ethConnected); DBG.printf("wifiConnected:%d\r\n",wifiConnected); DBG.printf("gprsConnected:%d\r\n",gprsConnected); @@ -1877,6 +1882,17 @@ DBG.printf("get dTypes from server\r\n"); str.erase(str.begin(),str.begin()+str.rfind("[{\"dtype\"")); str.erase(str.begin()+str.rfind("}]")+2,str.end()); + + //start special handler + while(1){ + if(str.find("}],") != std::string::npos) { + str.erase(str.begin()+str.find("}],")+1,str.begin()+str.find("}],")+2); + } else { + break; + } + } + //end special handler + //DBG.printf("strCrop:%s\r\n",str.c_str()); MbedJSONValue jsonValue; @@ -1910,7 +1926,7 @@ cmdComplete = cmdComplete && isExistNodeCmd(dTypeValue,cmdKey); } cmdComplete = cmdComplete && isExistNodeCmd(dTypeValue,"ok"); - DBG.printf("isCmdComplete:%d\r\n",cmdComplete); + DBG.printf("isCmdComplete[%s]:%d\r\n",dTypeValue.c_str(),cmdComplete); //get cmdCode based on dType and cmdKey if cmd are not complete @@ -1952,14 +1968,6 @@ DBG.printf("no dType from server\r\n"); } - //check if cmd of each dType are found and "ok.txt" is found - X - - //get cmdCode based on dType and cmd - X - - //write cmdCode to SD card - X - - //write "ok.txt" to SD card - X - /* //working DBG.printf("emma: setup mqtt client\r\n"); @@ -2014,7 +2022,9 @@ wait(1); while(1) { checkRxBuffer(); - checkVoltagePower(); + if(loop>0) { + checkVoltagePower(); + } //whether espFreeMemory occurs if(espFreeMemory) {