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:
- 51:ad6410dcaf52
- Parent:
- 50:50d98fe6cc15
- Child:
- 52:cbe6d1d1efdc
diff -r 50d98fe6cc15 -r ad6410dcaf52 emmaCode.cpp --- a/emmaCode.cpp Thu Sep 03 11:19:42 2015 +0000 +++ b/emmaCode.cpp Fri Sep 04 07:29:52 2015 +0000 @@ -2408,6 +2408,17 @@ while(1) { checkVoltagePower(); //need revision to support gprs + //set allowAlertXxxx to enable controller send alert + if(tAlert.read() > 300.0f) { //300.0f is 5 minutes + allowAlertAVrms = true; + allowAlertAWatt = true; + allowAlertBVrms = true; + allowAlertBWatt = true; + allowAlertCVrms = true; + allowAlertCWatt = true; + tAlert.reset(); + } + //panelEnergy, panelVoltage, and panelPower if(tPanelEnergy.read() > 30.0f) { DBG.printf("[%d]WattHR for each phase: %.2f, %.2f, %.2f\r\n", loop, AWattHr, BWattHr, CWattHr); @@ -3145,6 +3156,19 @@ } } allowAlertAVrms = false; + } else if(alertType != 0 && gprsConnected && allowAlertAVrms) { + sprintf(s,"POST /%s/api/controller/alert/1 HTTP/1.0\nHost: %s\nContent-Length:%d\n\n%s\r\n\r\n",appNAME.c_str(),restSERVER.c_str(),connBodyLen,connBody); + str.clear(); + str = gprsREST(restSERVER,connPort,s); + if(str.rfind("/alert/1") != std::string::npos) { + str.erase(str.begin(),str.begin()+str.rfind("/alert/1")); + if(str.find("\"status\":\"success\"") != std::string::npos) { + DBG.printf("[ph1]vrms success\r\n"); + } else { + DBG.printf("[ph1]vrms failed\r\n"); + } + } + allowAlertAVrms = false; } alertType = 0; @@ -3180,6 +3204,19 @@ } } allowAlertAWatt = false; + } else if(alertType != 0 && gprsConnected && allowAlertAWatt) { + sprintf(s,"POST /%s/api/controller/alert/1 HTTP/1.0\nHost: %s\nContent-Length:%d\n\n%s\r\n\r\n",appNAME.c_str(),restSERVER.c_str(),connBodyLen,connBody); + str.clear(); + str = gprsREST(restSERVER,connPort,s); + if(str.rfind("/alert/1") != std::string::npos) { + str.erase(str.begin(),str.begin()+str.rfind("/alert/1")); + if(str.find("\"status\":\"success\"") != std::string::npos) { + DBG.printf("[ph1]watt success\r\n"); + } else { + DBG.printf("[ph1]watt failed\r\n"); + } + } + allowAlertAWatt = false; } alertType = 0; @@ -3215,6 +3252,19 @@ } } allowAlertBVrms = false; + } else if(alertType != 0 && gprsConnected && allowAlertBVrms) { + sprintf(s,"POST /%s/api/controller/alert/2 HTTP/1.0\nHost: %s\nContent-Length:%d\n\n%s\r\n\r\n",appNAME.c_str(),restSERVER.c_str(),connBodyLen,connBody); + str.clear(); + str = gprsREST(restSERVER,connPort,s); + if(str.rfind("/alert/2") != std::string::npos) { + str.erase(str.begin(),str.begin()+str.rfind("/alert/2")); + if(str.find("\"status\":\"success\"") != std::string::npos) { + DBG.printf("[ph2]vrms success\r\n"); + } else { + DBG.printf("[ph2]vrms failed\r\n"); + } + } + allowAlertBVrms = false; } alertType = 0; @@ -3250,6 +3300,19 @@ } } allowAlertBWatt = false; + } else if(alertType != 0 && gprsConnected && allowAlertBWatt) { + sprintf(s,"POST /%s/api/controller/alert/2 HTTP/1.0\nHost: %s\nContent-Length:%d\n\n%s\r\n\r\n",appNAME.c_str(),restSERVER.c_str(),connBodyLen,connBody); + str.clear(); + str = gprsREST(restSERVER,connPort,s); + if(str.rfind("/alert/2") != std::string::npos) { + str.erase(str.begin(),str.begin()+str.rfind("/alert/2")); + if(str.find("\"status\":\"success\"") != std::string::npos) { + DBG.printf("[ph2]watt success\r\n"); + } else { + DBG.printf("[ph2]watt failed\r\n"); + } + } + allowAlertBWatt = false; } alertType = 0; @@ -3285,6 +3348,19 @@ } } allowAlertCVrms = false; + } else if(alertType != 0 && gprsConnected && allowAlertCVrms) { + sprintf(s,"POST /%s/api/controller/alert/3 HTTP/1.0\nHost: %s\nContent-Length:%d\n\n%s\r\n\r\n",appNAME.c_str(),restSERVER.c_str(),connBodyLen,connBody); + str.clear(); + str = gprsREST(restSERVER,connPort,s); + if(str.rfind("/alert/3") != std::string::npos) { + str.erase(str.begin(),str.begin()+str.rfind("/alert/3")); + if(str.find("\"status\":\"success\"") != std::string::npos) { + DBG.printf("[ph3]vrms success\r\n"); + } else { + DBG.printf("[ph3]vrms failed\r\n"); + } + } + allowAlertCVrms = false; } alertType = 0; @@ -3320,6 +3396,19 @@ } } allowAlertCWatt = false; + } else if(alertType != 0 && gprsConnected && allowAlertCWatt) { + sprintf(s,"POST /%s/api/controller/alert/3 HTTP/1.0\nHost: %s\nContent-Length:%d\n\n%s\r\n\r\n",appNAME.c_str(),restSERVER.c_str(),connBodyLen,connBody); + str.clear(); + str = gprsREST(restSERVER,connPort,s); + if(str.rfind("/alert/3") != std::string::npos) { + str.erase(str.begin(),str.begin()+str.rfind("/alert/3")); + if(str.find("\"status\":\"success\"") != std::string::npos) { + DBG.printf("[ph3]watt success\r\n"); + } else { + DBG.printf("[ph3]watt failed\r\n"); + } + } + allowAlertCWatt = false; } //DBG.printf("checkVoltagePower-finish\r\n"); }