diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index 866ae25f..eaa3678a 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -7,14 +7,13 @@ //----------------------------------------------------------------------------- app::app() : Main() { - mSendTicker = new Ticker(); - mFlagSend = false; + mSendTicker = 0xffffffff; + mSendInterval = 0; + mMqttTicker = 0xffffffff; + mMqttInterval = 0; mShowRebootRequest = false; - mMqttTicker = NULL; - mMqttEvt = false; - memset(mCmds, 0, sizeof(uint32_t)*DBG_CMD_LIST_LEN); //memset(mChannelStat, 0, sizeof(uint32_t) * 4); @@ -43,7 +42,6 @@ void app::setup(const char *ssid, const char *pwd, uint32_t timeout) { mWeb->on("/mqttstate", std::bind(&app::showMqtt, this)); if(mSettingsValid) { - uint16_t interval; uint64_t invSerial; char invName[MAX_NAME_LENGTH + 1] = {0}; uint8_t invType; @@ -59,10 +57,10 @@ void app::setup(const char *ssid, const char *pwd, uint32_t timeout) { } } - mEep->read(ADDR_INV_INTERVAL, &interval); - if(interval < 1000) - interval = 1000; - mSendTicker->attach_ms(interval, std::bind(&app::sendTicker, this)); + mEep->read(ADDR_INV_INTERVAL, &mSendInterval); + if(mSendInterval < 1000) + mSendInterval = 1000; + mSendTicker = 0; // pinout @@ -84,17 +82,16 @@ void app::setup(const char *ssid, const char *pwd, uint32_t timeout) { mEep->read(ADDR_MQTT_USER, mqttUser, MQTT_USER_LEN); mEep->read(ADDR_MQTT_PWD, mqttPwd, MQTT_PWD_LEN); mEep->read(ADDR_MQTT_TOPIC, mqttTopic, MQTT_TOPIC_LEN); - mEep->read(ADDR_MQTT_INTERVAL, &interval); + mEep->read(ADDR_MQTT_INTERVAL, &mMqttInterval); mEep->read(ADDR_MQTT_PORT, &mqttPort); char addr[16] = {0}; sprintf(addr, "%d.%d.%d.%d", mqttAddr[0], mqttAddr[1], mqttAddr[2], mqttAddr[3]); - if(interval < 1000) - interval = 1000; + if(mMqttInterval < 1000) + mMqttInterval = 1000; mMqtt.setup(addr, mqttTopic, mqttUser, mqttPwd, mqttPort); - mMqttTicker = new Ticker(); - mMqttTicker->attach_ms(interval, std::bind(&app::mqttTicker, this)); + mMqttTicker = 0; mMqtt.sendMsg("version", mVersion); } @@ -157,15 +154,13 @@ void app::loop(void) { mSys->BufCtrl.popBack(); } - if(mFlagSend) { - mFlagSend = false; + if(checkTicker(&mSendTicker, &mSendInterval)) { Inverter<> *inv; for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) { inv = mSys->getInverterByPos(i); if(NULL != inv) { mSys->Radio.sendTimePacket(inv->radioId.u64, mTimestamp); yield(); - //delay(100); } } } @@ -173,8 +168,7 @@ void app::loop(void) { // mqtt mMqtt.loop(); - if(mMqttEvt) { - mMqttEvt = false; + if(checkTicker(&mMqttTicker, &mMqttInterval)) { mMqtt.isConnected(true); char topic[30], val[10]; for(uint8_t id = 0; id < mSys->getNumInverters(); id++) { @@ -185,7 +179,6 @@ void app::loop(void) { snprintf(topic, 30, "%s/ch%d/%s", iv->name, iv->assign[i].ch, fields[iv->assign[i].fieldId]); snprintf(val, 10, "%.3f", iv->getValue(i)); mMqtt.sendMsg(topic, val); - //delay(20); yield(); } } @@ -193,7 +186,6 @@ void app::loop(void) { } // Serial debug - //char topic[30], val[10]; for(uint8_t id = 0; id < mSys->getNumInverters(); id++) { Inverter<> *iv = mSys->getInverterByPos(id); if(NULL != iv) { @@ -217,18 +209,6 @@ void app::handleIntr(void) { } -//----------------------------------------------------------------------------- -void app::sendTicker(void) { - mFlagSend = true; -} - - -//----------------------------------------------------------------------------- -void app::mqttTicker(void) { - mMqttEvt = true; -} - - //----------------------------------------------------------------------------- void app::showIndex(void) { String html = FPSTR(index_html); @@ -371,6 +351,8 @@ void app::showStatistics(void) { } content += String("other: ") + String(mCmds[DBG_CMD_LIST_LEN]) + String("\n\n"); + content += "Send Cnt: " + String(mSys->Radio.mSendCnt) + String("\n\n"); + /*content += "\nCHANNELs:\n"; content += String("23: ") + String(mChannelStat[0]) + String("\n"); content += String("40: ") + String(mChannelStat[1]) + String("\n"); @@ -410,7 +392,21 @@ void app::showLiveData(void) { case INV_TYPE_HM1200: modNum = 4; break; } - modHtml += "

" + String(iv->name) + "

"; + modHtml += "
"; + modHtml += "
" + String(iv->name) + ""; + uint8_t list[8] = {FLD_UAC, FLD_IAC, FLD_PAC, FLD_F, FLD_PCT, FLD_T, FLD_YT, FLD_YD}; + + for(uint8_t fld = 0; fld < 8; fld++) { + pos = (iv->getPosByChFld(CH0, list[fld])); + if(0xff != pos) { + modHtml += "
"; + modHtml += "" + String(iv->getValue(pos)); + modHtml += "" + String(iv->getUnit(pos)) + ""; + modHtml += "" + String(iv->getFieldName(pos)) + ""; + modHtml += "
"; + } + } + modHtml += "
"; for(uint8_t ch = 1; ch <= modNum; ch ++) { modHtml += "
CHANNEL " + String(ch) + ""; diff --git a/tools/esp8266/app.h b/tools/esp8266/app.h index 75ae6cd5..65225306 100644 --- a/tools/esp8266/app.h +++ b/tools/esp8266/app.h @@ -40,9 +40,6 @@ class app : public Main { } private: - void sendTicker(void); - void mqttTicker(void); - void showIndex(void); void showSetup(void); void showSave(void); @@ -74,8 +71,8 @@ class app : public Main { HmSystemType *mSys; - Ticker *mSendTicker; - bool mFlagSend; + uint32_t mSendTicker; + uint16_t mSendInterval; uint32_t mCmds[DBG_CMD_LIST_LEN+1]; //uint32_t mChannelStat[4]; @@ -83,8 +80,8 @@ class app : public Main { // mqtt mqtt mMqtt; - Ticker *mMqttTicker; - bool mMqttEvt; + uint32_t mMqttTicker; + uint16_t mMqttInterval; }; #endif /*__APP_H__*/ diff --git a/tools/esp8266/defines.h b/tools/esp8266/defines.h index 75313155..0dc7a83f 100644 --- a/tools/esp8266/defines.h +++ b/tools/esp8266/defines.h @@ -25,7 +25,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 3 -#define VERSION_PATCH 2 +#define VERSION_PATCH 3 //------------------------------------- diff --git a/tools/esp8266/hmRadio.h b/tools/esp8266/hmRadio.h index 65a098a5..10075ada 100644 --- a/tools/esp8266/hmRadio.h +++ b/tools/esp8266/hmRadio.h @@ -206,6 +206,7 @@ class HmRadio { uint8_t pinIrq; uint8_t AmplifierPower; + uint32_t mSendCnt; private: void sendPacket(uint64_t invId, uint8_t buf[], uint8_t len) { @@ -265,7 +266,6 @@ class HmRadio { RF24 mNrf24; uint8_t mSendChannel; BUFFER *mBufCtrl; - uint32_t mSendCnt; uint8_t mSendBuf[MAX_RF_PAYLOAD_SIZE]; }; diff --git a/tools/esp8266/html/h/style_css.h b/tools/esp8266/html/h/style_css.h index 491afc1e..128b9ca5 100644 --- a/tools/esp8266/html/h/style_css.h +++ b/tools/esp8266/html/h/style_css.h @@ -1,4 +1,4 @@ #ifndef __STYLE_H__ #define __STYLE_H__ -const char style_css[] PROGMEM = "h1 {margin:0;padding:20pt;font-size:22pt;color:#fff;background-color:#006ec0;display:block;text-transform:uppercase;}html, body {font-family:Arial;margin:0;padding:0;}p {text-align:justify;font-size:13pt;}.des {margin-top:35px;font-size:14pt;color:#006ec0;}.subdes {font-size:13pt;color:#006ec0;margin-left:7px;}.fw {width:60px;display:block;float:left;}.color {width:50px;height:50px;border:1px solid #ccc;}.range {width:300px;}a:link, a:visited {text-decoration:none;font-size:13pt;color:#006ec0;}a:hover, a:focus {color:#f00;}a.erase {background-color:#006ec0;color:#fff;padding:7px;display:inline-block;margin-top:30px;float:right;}#content {padding:15px 15px 60px 15px;}#footer {position:fixed;bottom:0px;height:45px;background-color:#006ec0;width:100%;}#footer p {color:#fff;padding-left:20px;padding-right:20px;font-size:10pt !important;}#footer a {color:#fff;}div.content {background-color:#fff;padding-bottom:65px;overflow:hidden;}input, select {padding:7px;font-size:13pt;}input.text, select {width:70%;box-sizing:border-box;margin-bottom:10px;border:1px solid #ccc;}input.btn {background-color:#006ec0;color:#fff;border:0px;float:right;margin:10px 0 30px;text-transform:uppercase;}input.cb {margin-bottom:20px;}label {width:20%;display:inline-block;font-size:12pt;padding-right:10px;margin-left:10px;}.left {float:left;}.right {float:right;}div.ch-group {display:inline-block;}div.ch {width:250px;height:410px;background-color:#006ec0;display:inline-block;margin-right:20px;margin-bottom:20px;}div.ch .value, div.ch .info, div.ch .head {color:#fff;display:block;width:100%;text-align:center;}div.ch .unit {font-size:19px;margin-left:10px;}div.ch .value {margin-top:20px;font-size:30px;}div.ch .info {margin-top:3px;font-size:10px;}div.ch .head {background-color:#003c80;padding:10px 0 10px 0;}"; +const char style_css[] PROGMEM = "h1 {margin:0;padding:20pt;font-size:22pt;color:#fff;background-color:#006ec0;display:block;text-transform:uppercase;}html, body {font-family:Arial;margin:0;padding:0;}p {text-align:justify;font-size:13pt;}.des {margin-top:35px;font-size:14pt;color:#006ec0;}.subdes {font-size:13pt;color:#006ec0;margin-left:7px;}.fw {width:60px;display:block;float:left;}.color {width:50px;height:50px;border:1px solid #ccc;}.range {width:300px;}a:link, a:visited {text-decoration:none;font-size:13pt;color:#006ec0;}a:hover, a:focus {color:#f00;}a.erase {background-color:#006ec0;color:#fff;padding:7px;display:inline-block;margin-top:30px;float:right;}#content {padding:15px 15px 60px 15px;}#footer {position:fixed;bottom:0px;height:45px;background-color:#006ec0;width:100%;}#footer p {color:#fff;padding-left:20px;padding-right:20px;font-size:10pt !important;}#footer a {color:#fff;}div.content {background-color:#fff;padding-bottom:65px;overflow:hidden;}input, select {padding:7px;font-size:13pt;}input.text, select {width:70%;box-sizing:border-box;margin-bottom:10px;border:1px solid #ccc;}input.btn {background-color:#006ec0;color:#fff;border:0px;float:right;margin:10px 0 30px;text-transform:uppercase;}input.cb {margin-bottom:20px;}label {width:20%;display:inline-block;font-size:12pt;padding-right:10px;margin-left:10px;}.left {float:left;}.right {float:right;}div.ch-iv {width:100%;background-color:#32b004;display:inline-block;margin-bottom:20px;padding-bottom:20px;}div.ch {width:250px;height:410px;background-color:#006ec0;display:inline-block;margin-right:20px;margin-bottom:20px;}div.ch .value, div.ch .info, div.ch .head, div.ch-iv .value, div.ch-iv .info, div.ch-iv .head {color:#fff;display:block;width:100%;text-align:center;}.subgrp {float:left;width:250px;}div.ch .unit, div.ch-iv .unit {font-size:19px;margin-left:10px;}div.ch .value, div.ch-iv .value {margin-top:20px;font-size:30px;}div.ch .info, div.ch-iv .info {margin-top:3px;font-size:10px;}div.ch .head {background-color:#003c80;padding:10px 0 10px 0;}div.ch-iv .head {background-color:#1c6800;padding:10px 0 10px 0;}div.iv {max-width:1060px;}div.ch:last-child {margin-right:0px !important;}"; #endif /*__STYLE_H__*/ diff --git a/tools/esp8266/html/style.css b/tools/esp8266/html/style.css index 88c1b57c..c92fa950 100644 --- a/tools/esp8266/html/style.css +++ b/tools/esp8266/html/style.css @@ -136,8 +136,12 @@ label { float: right; } -div.ch-group { +div.ch-iv { + width: 100%; + background-color: #32b004; display: inline-block; + margin-bottom: 20px; + padding-bottom: 20px; } div.ch { @@ -148,24 +152,29 @@ div.ch { margin-right: 20px; margin-bottom: 20px; } -div.ch .value, div.ch .info, div.ch .head { +div.ch .value, div.ch .info, div.ch .head, div.ch-iv .value, div.ch-iv .info, div.ch-iv .head { color: #fff; display: block; width: 100%; text-align: center; } -div.ch .unit { +.subgrp { + float: left; + width: 250px; +} + +div.ch .unit, div.ch-iv .unit { font-size: 19px; margin-left: 10px; } -div.ch .value { +div.ch .value, div.ch-iv .value { margin-top: 20px; font-size: 30px; } -div.ch .info { +div.ch .info, div.ch-iv .info { margin-top: 3px; font-size: 10px; } @@ -174,3 +183,16 @@ div.ch .head { background-color: #003c80; padding: 10px 0 10px 0; } + +div.ch-iv .head { + background-color: #1c6800; + padding: 10px 0 10px 0; +} + +div.iv { + max-width: 1060px; +} + +div.ch:last-child { + margin-right: 0px !important; +} diff --git a/tools/esp8266/main.cpp b/tools/esp8266/main.cpp index 25b68c71..83fbef80 100644 --- a/tools/esp8266/main.cpp +++ b/tools/esp8266/main.cpp @@ -23,10 +23,9 @@ Main::Main(void) { mEep = new eep(); Serial.begin(115200); - mUptimeSecs = 0; - mUptimeTicker = new Ticker(); - mUptimeTicker->attach(1, std::bind(&Main::uptimeTicker, this)); - + mUptimeSecs = 0; + mUptimeTicker = 0xffffffff; + mUptimeInterval = 1000; } @@ -67,6 +66,11 @@ void Main::loop(void) { if(mApActive) mDns->processNextRequest(); mWeb->handleClient(); + + if(checkTicker(&mUptimeTicker, &mUptimeInterval)) { + mUptimeSecs++; + mTimestamp++; + } } @@ -271,14 +275,6 @@ void Main::showReboot(void) { } - -//----------------------------------------------------------------------------- -void Main::uptimeTicker(void) { - mUptimeSecs++; - mTimestamp++; -} - - //----------------------------------------------------------------------------- time_t Main::getNtpTime(void) { time_t date = 0; diff --git a/tools/esp8266/main.h b/tools/esp8266/main.h index 6e096789..fede73a0 100644 --- a/tools/esp8266/main.h +++ b/tools/esp8266/main.h @@ -6,7 +6,6 @@ #include #include #include -#include #include @@ -64,6 +63,20 @@ class Main { } while(addr < ADDR_START_SETTINGS); } + inline bool checkTicker(uint32_t *ticker, uint16_t *interval) { + uint32_t mil = millis(); + if(mil >= *ticker) { + *ticker = mil + *interval; + return true; + } + else if(mil < (*ticker - *interval)) { + *ticker = mil + *interval; + return true; + } + + return false; + } + char mStationSsid[SSID_LEN]; char mStationPwd[PWD_LEN]; bool mWifiSettingsValid; @@ -87,14 +100,13 @@ class Main { void showUptime(void); void showTime(void); void showCss(void); - void uptimeTicker(void); - time_t getNtpTime(void); void sendNTPpacket(IPAddress& address); time_t offsetDayLightSaving (uint32_t local_t); - Ticker *mUptimeTicker; + uint32_t mUptimeTicker; + uint16_t mUptimeInterval; uint32_t mUptimeSecs; DNSServer *mDns;