diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index 8b8828df..720393a0 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -3,7 +3,6 @@ #include "html/h/index_html.h" #include "html/h/setup_html.h" #include "html/h/hoymiles_html.h" -#include "html/h/debug_html.h" //----------------------------------------------------------------------------- @@ -24,12 +23,9 @@ app::app() : Main() { mSerialValues = true; mSerialDebug = false; - memset(mCmds, 0, sizeof(uint32_t)*DBG_CMD_LIST_LEN); - //memset(mChannelStat, 0, sizeof(uint32_t) * 4); + memset(mPacketIds, 0, sizeof(uint32_t)*DBG_CMD_LIST_LEN); mSys = new HmSystemType(); - - memset(mPayload, 0, ((MAX_RF_PAYLOAD_SIZE-11) * MAX_NUM_PAC_PER_PAYLOAD)); } @@ -50,7 +46,6 @@ void app::setup(uint32_t timeout) { mWeb->on("/cmdstat", std::bind(&app::showStatistics, this)); mWeb->on("/hoymiles", std::bind(&app::showHoymiles, this)); mWeb->on("/livedata", std::bind(&app::showLiveData, this)); - mWeb->on("/debug", std::bind(&app::showDebug, this)); if(mSettingsValid) { uint64_t invSerial; @@ -67,11 +62,9 @@ void app::setup(uint32_t timeout) { DPRINTLN("add inverter: " + String(invName) + ", SN: " + String(invSerial, HEX) + ", type: " + String(invType)); } } - // @TODO reenable - //mEep->read(ADDR_INV_INTERVAL, &mSendInterval); - //if(mSendInterval < 5) - // mSendInterval = 5; - mSendInterval = 5; + mEep->read(ADDR_INV_INTERVAL, &mSendInterval); + if(mSendInterval < 5) + mSendInterval = 5; // pinout mEep->read(ADDR_PINOUT, &mSys->Radio.pinCs); @@ -152,29 +145,29 @@ void app::loop(void) { if(mSys->Radio.checkPaketCrc(p->packet, &len, &rptCnt, p->rxCh)) { // process buffer only on first occurrence if((0 != len) && (0 == rptCnt)) { - uint8_t *cmd = &p->packet[9]; - //DPRINTLN("CMD " + String(*cmd, HEX)); + uint8_t *packetId = &p->packet[9]; + //DPRINTLN("CMD " + String(*packetId, HEX)); if(mSerialDebug) mSys->Radio.dumpBuf("Payload ", p->packet, len); Inverter<> *iv = mSys->findInverter(&p->packet[1]); if(NULL != iv) { for(uint8_t i = 0; i < iv->listLen; i++) { - if(iv->assign[i].cmdId == *cmd) + if(iv->assign[i].cmdId == *packetId) iv->addValue(i, &p->packet[9]); } iv->doCalculations(); - //memcpy(mPayload[(*cmd & 0x7F) - 1], &p->packet[9], MAX_RF_PAYLOAD_SIZE - 11); + //memcpy(mPayload[(*packetId & 0x7F) - 1], &p->packet[9], MAX_RF_PAYLOAD_SIZE - 11); } - if(*cmd == 0x01) mCmds[0]++; - else if(*cmd == 0x02) mCmds[1]++; - else if(*cmd == 0x03) mCmds[2]++; - else if(*cmd == 0x81) mCmds[3]++; - else if(*cmd == 0x82) mCmds[4]++; - else if(*cmd == 0x83) mCmds[5]++; - else if(*cmd == 0x84) mCmds[6]++; - else mCmds[7]++; + if(*packetId == 0x01) mPacketIds[0]++; + else if(*packetId == 0x02) mPacketIds[1]++; + else if(*packetId == 0x03) mPacketIds[2]++; + else if(*packetId == 0x81) mPacketIds[3]++; + else if(*packetId == 0x82) mPacketIds[4]++; + else if(*packetId == 0x83) mPacketIds[5]++; + else if(*packetId == 0x84) mPacketIds[6]++; + else mPacketIds[7]++; } } mSys->BufCtrl.popBack(); @@ -182,24 +175,9 @@ void app::loop(void) { } if(checkTicker(&mTicker, 1000)) { - if(++mSendTicker >= mSendInterval) { - mSendTicker = 0; - - if(!mSys->BufCtrl.empty()) - DPRINTLN("recbuf not empty! #" + String(mSys->BufCtrl.getFill())); - 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(); - } - } - } - if(mMqttActive) { mMqtt.loop(); - if(++mMqttTicker > mMqttInterval) { + if(++mMqttTicker >= mMqttInterval) { mMqttInterval = 0; mMqtt.isConnected(true); char topic[30], val[10]; @@ -220,7 +198,7 @@ void app::loop(void) { } if(mSerialValues) { - if(++mSerialTicker > mSerialInterval) { + if(++mSerialTicker >= mSerialInterval) { mSerialInterval = 0; char topic[30], val[10]; for(uint8_t id = 0; id < mSys->getNumInverters(); id++) { @@ -238,6 +216,22 @@ void app::loop(void) { } } } + + if(++mSendTicker >= mSendInterval) { + mSendTicker = 0; + + if(!mSys->BufCtrl.empty()) + DPRINTLN("recbuf not empty! #" + String(mSys->BufCtrl.getFill())); + Inverter<> *inv; + for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) { + inv = mSys->getInverterByPos(i); + if(NULL != inv) { + yield(); + mSys->Radio.sendTimePacket(inv->radioId.u64, mTimestamp); + mRxTicker = 0; + } + } + } } } @@ -402,20 +396,14 @@ void app::showErase() { //----------------------------------------------------------------------------- void app::showStatistics(void) { - String content = "CMDs:\n"; + String content = "Packets:\n"; for(uint8_t i = 0; i < DBG_CMD_LIST_LEN; i ++) { - content += String("0x") + String(dbgCmds[i], HEX) + String(": ") + String(mCmds[i]) + String("\n"); + content += String("0x") + String(dbgCmds[i], HEX) + String(": ") + String(mPacketIds[i]) + String("\n"); } - content += String("other: ") + String(mCmds[DBG_CMD_LIST_LEN]) + String("\n\n"); + content += String("other: ") + String(mPacketIds[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"); - content += String("61: ") + String(mChannelStat[2]) + String("\n"); - content += String("75: ") + String(mChannelStat[3]) + String("\n");*/ - if(!mSys->Radio.isChipConnected()) content += "WARNING! your NRF24 module can't be reached, check the wiring and pinout (setup)\n"; @@ -513,36 +501,6 @@ void app::showLiveData(void) { } -//----------------------------------------------------------------------------- -void app::showDebug() { - if(mWeb->args() > 0) { - /*String html; - - for(uint8_t i = 0; i < MAX_NUM_PAC_PER_PAYLOAD; i ++) { - for(uint8_t j = 0; j < (MAX_RF_PAYLOAD_SIZE- 11); j++) { - if(mPayload[i][j] < 0x10) - html += "0"; - html += String(mPayload[i][j], HEX) + " "; - } - html += "\n"; - } - html += "CMDS: "; - for(uint8_t i = 0; i < DBG_CMD_LIST_LEN; i ++) { - html += String(mCmds[i]) + String(" "); - } - html += "\n------------------";*/ - - mWeb->send(200, "text/plain", "na"); - } - else { - String html = FPSTR(debug_html); - html.replace("{DEVICE}", mDeviceName); - html.replace("{VERSION}", mVersion); - mWeb->send(200, "text/html", html); - } -} - - //----------------------------------------------------------------------------- void app::saveValues(bool webSend = true) { Main::saveValues(false); // general configuration diff --git a/tools/esp8266/app.h b/tools/esp8266/app.h index f179af32..26efc6e7 100644 --- a/tools/esp8266/app.h +++ b/tools/esp8266/app.h @@ -47,7 +47,6 @@ class app : public Main { void showStatistics(void); void showHoymiles(void); void showLiveData(void); - void showDebug(void); void saveValues(bool webSend); void updateCrc(void); @@ -74,8 +73,7 @@ class app : public Main { uint16_t mSendTicker; uint16_t mSendInterval; - uint32_t mCmds[DBG_CMD_LIST_LEN+1]; - //uint32_t mChannelStat[4]; + uint32_t mPacketIds[DBG_CMD_LIST_LEN+1]; uint32_t mRecCnt; // timer @@ -92,8 +90,6 @@ class app : public Main { bool mMqttActive; uint16_t mSerialTicker; uint16_t mSerialInterval; - - uint8_t mPayload[MAX_NUM_PAC_PER_PAYLOAD][MAX_RF_PAYLOAD_SIZE-11]; }; #endif /*__APP_H__*/ diff --git a/tools/esp8266/config.h b/tools/esp8266/config.h index 632817da..c37f979a 100644 --- a/tools/esp8266/config.h +++ b/tools/esp8266/config.h @@ -38,8 +38,6 @@ // maximum buffer length of packet received / sent to RF24 module #define MAX_RF_PAYLOAD_SIZE 32 -#define MAX_NUM_PAC_PER_PAYLOAD 4 - // changes the style of "/setup" page, visualized = nicer #define LIVEDATA_VISUALIZED diff --git a/tools/esp8266/defines.h b/tools/esp8266/defines.h index aa94bc77..9b4cb678 100644 --- a/tools/esp8266/defines.h +++ b/tools/esp8266/defines.h @@ -16,7 +16,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 3 -#define VERSION_PATCH 7 +#define VERSION_PATCH 8 //------------------------------------- diff --git a/tools/esp8266/hmRadio.h b/tools/esp8266/hmRadio.h index e7e67c8e..a251b7db 100644 --- a/tools/esp8266/hmRadio.h +++ b/tools/esp8266/hmRadio.h @@ -205,9 +205,11 @@ class HmRadio { mRxLoopCnt += addLoop; if(mRxLoopCnt != 0) { mRxLoopCnt--; + DISABLE_IRQ; mNrf24.stopListening(); mNrf24.setChannel(getRxNxtChannel()); mNrf24.startListening(); + RESTORE_IRQ; } return (0 == mRxLoopCnt); // receive finished } diff --git a/tools/esp8266/html/convert.py b/tools/esp8266/html/convert.py index 108a8d4b..8171b69e 100644 --- a/tools/esp8266/html/convert.py +++ b/tools/esp8266/html/convert.py @@ -27,4 +27,3 @@ convert2Header("index.html") convert2Header("setup.html") convert2Header("hoymiles.html") convert2Header("style.css") -convert2Header("debug.html") diff --git a/tools/esp8266/main.cpp b/tools/esp8266/main.cpp index 99147846..c2fac10e 100644 --- a/tools/esp8266/main.cpp +++ b/tools/esp8266/main.cpp @@ -57,13 +57,13 @@ void Main::setup(uint32_t timeout) { #endif if(!startAp) { + delay(5000); mTimestamp = getNtpTime(); DPRINTLN("[NTP]: " + getDateTimeStr(getNtpTime())); } mUpdater->setup(mWeb); mApActive = startAp; - } @@ -83,6 +83,11 @@ void Main::loop(void) { } else { if(millis() - mApLastTick > 10000) { + uint8_t cnt = WiFi.softAPgetStationNum(); + if(cnt > 0) { + DPRINTLN(String(cnt) + " clients connected, resetting AP timeout"); + mNextTryTs = (millis() + (WIFI_AP_ACTIVE_TIME * 1000)); + } mApLastTick = millis(); DPRINTLN("AP will be closed in " + String((mNextTryTs - mApLastTick) / 1000) + " seconds"); }