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
Diff: emmaCode.cpp
- Revision:
- 13:e8adfe305dbc
- Parent:
- 12:96f637ed37f9
- Child:
- 14:8287f0f5d987
--- a/emmaCode.cpp Tue Jul 14 03:03:22 2015 +0000 +++ b/emmaCode.cpp Tue Jul 14 04:43:01 2015 +0000 @@ -97,10 +97,6 @@ int TPx; int TPy; - //disable sd card and enable tft lcd - //sd._cs = 1; - //TFT._cs = 0; - TFT.background(Black); TFT.foreground(White); @@ -109,7 +105,7 @@ TFT.cls(); TFT.locate(0,0); TFT.printf("Hello, I'm Emma!"); - wait(3); + wait(2); TFT.cls(); Matrix matrix; @@ -222,15 +218,10 @@ TFT.locate(25,170); TFT.printf(" "); TFT.locate(25,170); - TFT.printf("out-mode: %s is selected",menu[md].text.c_str()); - wait(3); + TFT.printf("mode: %s is selected",menu[md].text.c_str()); + wait(2); TFT.cls(); - //enable sd card and disable tft lcd - //TFT._cs = 1; - //sd._cs = 0; - //wait(2); - return md; } /*end lcd and touch*/ @@ -787,6 +778,30 @@ DBG.printf("ethConnected:%d\r\n",ethConnected); DBG.printf("wifiConnected:%d\r\n",wifiConnected); + TFT.locate(0,0); + TFT.printf(" emmaModeOperation"); + + TFT.locate(0,20); + if(ethConnected) { + TFT.printf("ETH:Avail"); + } else { + TFT.printf("ETH:N/A"); + } + + TFT.locate(80,20); + if(wifiConnected) { + TFT.printf("WiFi:Avail"); + } else { + TFT.printf("WiFi:N/A"); + } + + TFT.locate(160,20); + if(gprsConnected) { + TFT.printf("GPRS:Avail"); + } else { + TFT.printf("GPRS:N/A"); + } + //calculate hmac //for(int j=0; j<sizeof(s); j++) { // s[j]=0; } @@ -901,7 +916,9 @@ mqtt.connectedCb.attach(&mqttConnected); mqtt.disconnectedCb.attach(&mqttDisconnected); mqtt.connect(MQTT_HOST,MQTT_PORT,false); - DBG.printf("emma: success to setup mqtt\r\n"); + DBG.printf("emma: success to setup mqtt\r\n"); + TFT.locate(0,40); + TFT.printf("emma: success to setup mqtt"); } DBG.printf("emma: system started\r\n"); @@ -941,8 +958,16 @@ //init rest to server if(rest.begin(EMMA_SERVER_HOST,EMMA_SERVER_PORT,false)) { DBG.printf("rest to server is created\r\n"); + TFT.locate(0,40); + TFT.printf(" "); + TFT.locate(0,40); + TFT.printf("rest to server is created"); } else { DBG.printf("rest to server is NOT created\r\n"); + TFT.locate(0,40); + TFT.printf(" "); + TFT.locate(0,40); + TFT.printf("rest to server is NOT created"); } //check firmware update @@ -965,6 +990,14 @@ parse(jsonValue,str.c_str()); char *parameter[2] = {"mac","ip"}; + TFT.locate(0,40); + TFT.printf(" "); + TFT.locate(0,40); + TFT.printf("get %d nodes from server",jsonValue.size()); + wait(0.5); + TFT.locate(0,40); + TFT.printf(" "); + //check whether nodes valid bool validNodes = true; for(int i=0; i<jsonValue.size(); i++) { @@ -980,8 +1013,8 @@ string ipValue = jsonValue[i][parameter[1]].get<std::string>(); nodes[i].macAddr = macValue; nodes[i].ipAddr = ipValue; - DBG.printf("nodes[%d]-mac:%s\r\n",i,nodes[i].macAddr.c_str()); - DBG.printf("nodes[%d]-ip:%s\r\n",i,nodes[i].ipAddr.c_str()); + DBG.printf("nodes[%d]mac:%s\r\n",i,nodes[i].macAddr.c_str()); + DBG.printf("nodes[%d]ip:%s\r\n",i,nodes[i].ipAddr.c_str()); } } @@ -1024,8 +1057,22 @@ //panelEnergy, panelVoltage, and panelPower if(t.read_ms() > 10000) { DBG.printf("[%d]WattHR for each phase: %.2f, %.2f, %.2f\r\n", loop, AWattHr, BWattHr, CWattHr); + TFT.locate(0,60); + TFT.printf(" "); + TFT.locate(0,60); + TFT.printf("[%d]WHR: %.1f, %.1f, %.1f", loop, AWattHr, BWattHr, CWattHr); + DBG.printf("VRMS for each phase: %.2f, %.2f, %.2f\r\n", AVrms, BVrms, CVrms); + TFT.locate(0,80); + TFT.printf(" "); + TFT.locate(0,80); + TFT.printf("VRMS: %.1f, %.1f, %.1f", AVrms, BVrms, CVrms); + DBG.printf("Watt for each phase: %.2f, %.2f, %.2f\r\n", AWatt, BWatt, CWatt); + TFT.locate(0,100); + TFT.printf(" "); + TFT.locate(0,100); + TFT.printf("Watt: %.1f, %.1f, %.1f", AWatt, BWatt, CWatt); //for(int i=1; i<4; i++) { for(int i=1; i<2; i++) { @@ -1049,9 +1096,27 @@ rest.post(r,s); wait(2); if(rxBuf.find("\"status\":\"success\"") != std::string::npos) { - DBG.printf("send channel: %d success\r\n",i); + DBG.printf("send channel: %d success\r\n",i); + TFT.foreground(Green); + TFT.locate(0,120); + TFT.printf(" "); + TFT.locate(0,120); + TFT.printf("send ch%d success",i); + wait(1); + TFT.locate(0,120); + TFT.printf(" "); + TFT.foreground(White); } else { - DBG.printf("send channel: %d failed\r\n",i); + DBG.printf("send channel: %d failed\r\n",i); + TFT.foreground(Red); + TFT.locate(0,120); + TFT.printf(" "); + TFT.locate(0,120); + TFT.printf("send ch%d failed",i); + wait(1); + TFT.locate(0,120); + TFT.printf(" "); + TFT.foreground(White); } } t.reset(); @@ -1109,6 +1174,13 @@ //command if(newCommand) { DBG.printf("newCommand:\r\n%s\r\n",globalCommand.c_str()); + TFT.foreground(Orange); + TFT.locate(0,160); + TFT.printf(" "); + TFT.locate(0,160); + TFT.printf("newCommand"); + TFT.foreground(White); + MbedJSONValue jsonValue; parse(jsonValue,globalCommand.c_str()); char *parameter[5] = {"id","nType","nAddr","dType","cmd"}; @@ -1167,12 +1239,28 @@ //cmdExecuted = false; if(trial>=2) { //two times trial DBG.printf("cmd is not executed\r\n"); + TFT.foreground(Red); + TFT.locate(0,180); + TFT.printf(" "); + TFT.locate(0,180); + TFT.printf("cmd is not executed"); + TFT.locate(0,180); + TFT.printf(" "); + TFT.foreground(White); break; } nodes[idx].restConn->get("/",s); wait(2); if(rxBuf.find("REST: Sent") != std::string::npos) { - DBG.printf("cmd executed\r\n"); + DBG.printf("cmd is executed\r\n"); + TFT.foreground(Green); + TFT.locate(0,180); + TFT.printf(" "); + TFT.locate(0,180); + TFT.printf("cmd is executed"); + TFT.locate(0,180); + TFT.printf(" "); + TFT.foreground(White); execResult = "executed"; break; } @@ -1202,6 +1290,11 @@ } } } + + //clear text on lcd + TFT.locate(0,160); + TFT.printf(" "); + newCommand = false; } osDelay(5000);