diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index 79c4b045..f8820700 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -1,3 +1,8 @@ +//----------------------------------------------------------------------------- +// 2022 Ahoy, https://www.mikrocontroller.net/topic/525778 +// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/ +//----------------------------------------------------------------------------- + #include "app.h" #include "html/h/index_html.h" @@ -29,6 +34,7 @@ app::app() : Main() { memset(mPayload, 0, (MAX_NUM_INVERTERS * sizeof(invPayload_t))); mRxFailed = 0; mRxSuccess = 0; + mFrameCnt = 0; mLastPacketId = 0x00; mSys = new HmSystemType(); @@ -212,6 +218,7 @@ void app::loop(void) { DPRINT("Received " + String(len) + " bytes channel " + String(p->rxCh) + ": "); mSys->Radio.dumpBuf(NULL, p->packet, len); } + mFrameCnt++; if(0 != len) { Inverter<> *iv = mSys->findInverter(&p->packet[1]); @@ -264,8 +271,6 @@ void app::loop(void) { } } } - snprintf(val, 10, "%d", ESP.getFreeHeap()); - mMqtt.sendMsg("free_heap", val); snprintf(val, 10, "%d", millis()/1000); mMqtt.sendMsg("uptime", val); } @@ -390,9 +395,9 @@ void app::processPayload(bool retransmit) { if(!mPayload[iv->id].complete) { if(!buildPayload(iv->id)) { if(mPayload[iv->id].requested) { - if(mPayload[iv->id].retransmits < mMaxRetransPerPyld) { - mPayload[iv->id].retransmits++; - if(retransmit) { + if(retransmit) { + if(mPayload[iv->id].retransmits < mMaxRetransPerPyld) { + mPayload[iv->id].retransmits++; if(mPayload[iv->id].maxPackId != 0) { for(uint8_t i = 0; i < (mPayload[iv->id].maxPackId-1); i ++) { if(mPayload[iv->id].len[i] == 0) { @@ -436,12 +441,13 @@ void app::processPayload(bool retransmit) { for(uint8_t i = 0; i < iv->listLen; i++) { iv->addValue(i, payload); + yield(); } iv->doCalculations(); } } + yield(); } - yield(); } } @@ -598,10 +604,9 @@ void app::showStatistics(void) { //DPRINTLN(F("app::showStatistics")); String content = F("Receive success: ") + String(mRxSuccess) + "\n"; content += F("Receive fail: ") + String(mRxFailed) + "\n"; + content += F("Frames received: ") + String(mFrameCnt) + "\n"; content += F("Send Cnt: ") + String(mSys->Radio.mSendCnt) + String("\n\n"); - content += F("Free Heap: 0x") + String(ESP.getFreeHeap(), HEX) + "\n\n"; - Inverter<> *iv; for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) { iv = mSys->getInverterByPos(i); diff --git a/tools/esp8266/app.h b/tools/esp8266/app.h index 3151e404..ccdfd000 100644 --- a/tools/esp8266/app.h +++ b/tools/esp8266/app.h @@ -1,3 +1,8 @@ +//----------------------------------------------------------------------------- +// 2022 Ahoy, https://www.mikrocontroller.net/topic/525778 +// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/ +//----------------------------------------------------------------------------- + #ifndef __APP_H__ #define __APP_H__ @@ -91,6 +96,7 @@ class app : public Main { invPayload_t mPayload[MAX_NUM_INVERTERS]; uint32_t mRxFailed; uint32_t mRxSuccess; + uint32_t mFrameCnt; uint8_t mLastPacketId; uint8_t mMaxRetransPerPyld; diff --git a/tools/esp8266/config.h b/tools/esp8266/config.h index 2c98449c..ff96b301 100644 --- a/tools/esp8266/config.h +++ b/tools/esp8266/config.h @@ -1,3 +1,8 @@ +//----------------------------------------------------------------------------- +// 2022 Ahoy, https://www.mikrocontroller.net/topic/525778 +// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/ +//----------------------------------------------------------------------------- + #ifndef __CONFIG_H__ #define __CONFIG_H__ diff --git a/tools/esp8266/crc.cpp b/tools/esp8266/crc.cpp index 7694dadd..7c64d642 100644 --- a/tools/esp8266/crc.cpp +++ b/tools/esp8266/crc.cpp @@ -1,3 +1,8 @@ +//----------------------------------------------------------------------------- +// 2022 Ahoy, https://www.mikrocontroller.net/topic/525778 +// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/ +//----------------------------------------------------------------------------- + #include "crc.h" uint8_t crc8(uint8_t buf[], uint8_t len) { @@ -7,6 +12,7 @@ uint8_t crc8(uint8_t buf[], uint8_t len) { for(uint8_t b = 0; b < 8; b ++) { crc = (crc << 1) ^ ((crc & 0x80) ? CRC8_POLY : 0x00); } + yield(); } return crc; } @@ -21,23 +27,9 @@ uint16_t crc16(uint8_t buf[], uint8_t len, uint16_t start) { shift = (crc & 0x0001); crc = crc >> 1; if(shift != 0) - crc = crc ^ 0xA001; + crc = crc ^ CRC16_MODBUS_POLYNOM; } + yield(); } return crc; } - -uint16_t crc16nrf24(uint8_t buf[], uint16_t lenBits, uint16_t startBit, uint16_t crcIn) { - uint16_t crc = crcIn; - uint8_t idx, val = buf[(startBit >> 3)]; - - for(uint16_t bit = startBit; bit < lenBits; bit ++) { - idx = bit & 0x07; - if(0 == idx) - val = buf[(bit >> 3)]; - crc ^= 0x8000 & (val << (8 + idx)); - crc = (crc & 0x8000) ? ((crc << 1) ^ CRC16_NRF24_POLYNOM) : (crc << 1); - } - - return crc; -} diff --git a/tools/esp8266/crc.h b/tools/esp8266/crc.h index 349146b3..c0323ebb 100644 --- a/tools/esp8266/crc.h +++ b/tools/esp8266/crc.h @@ -1,16 +1,20 @@ +//----------------------------------------------------------------------------- +// 2022 Ahoy, https://www.mikrocontroller.net/topic/525778 +// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/ +//----------------------------------------------------------------------------- + #ifndef __CRC_H__ #define __CRC_H__ #include +#include "Arduino.h" #define CRC8_INIT 0x00 #define CRC8_POLY 0x01 #define CRC16_MODBUS_POLYNOM 0xA001 -#define CRC16_NRF24_POLYNOM 0x1021 uint8_t crc8(uint8_t buf[], uint8_t len); uint16_t crc16(uint8_t buf[], uint8_t len, uint16_t start = 0xffff); -uint16_t crc16nrf24(uint8_t buf[], uint16_t lenBits, uint16_t startBit = 0, uint16_t crcIn = 0xffff); #endif /*__CRC_H__*/ diff --git a/tools/esp8266/debug.h b/tools/esp8266/debug.h index 2699b943..d080c018 100644 --- a/tools/esp8266/debug.h +++ b/tools/esp8266/debug.h @@ -1,3 +1,8 @@ +//----------------------------------------------------------------------------- +// 2022 Ahoy, https://www.mikrocontroller.net/topic/525778 +// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/ +//----------------------------------------------------------------------------- + #ifndef __DEBUG_H__ #define __DEBUG_H__ diff --git a/tools/esp8266/defines.h b/tools/esp8266/defines.h index df9a055c..6d14eea9 100644 --- a/tools/esp8266/defines.h +++ b/tools/esp8266/defines.h @@ -1,3 +1,8 @@ +//----------------------------------------------------------------------------- +// 2022 Ahoy, https://www.mikrocontroller.net/topic/525778 +// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/ +//----------------------------------------------------------------------------- + #ifndef __DEFINES_H__ #define __DEFINES_H__ @@ -16,7 +21,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 4 -#define VERSION_PATCH 17 +#define VERSION_PATCH 18 //------------------------------------- diff --git a/tools/esp8266/eep.h b/tools/esp8266/eep.h index 21d380d1..52907d5b 100644 --- a/tools/esp8266/eep.h +++ b/tools/esp8266/eep.h @@ -1,3 +1,8 @@ +//----------------------------------------------------------------------------- +// 2022 Ahoy, https://www.mikrocontroller.net/topic/525778 +// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/ +//----------------------------------------------------------------------------- + #ifndef __EEP_H__ #define __EEP_H__ @@ -7,7 +12,7 @@ class eep { public: eep() { - EEPROM.begin(1000); + EEPROM.begin(4096); } ~eep() { EEPROM.end(); diff --git a/tools/esp8266/esp8266.ino b/tools/esp8266/esp8266.ino index 4d5ca3b0..4ddd706a 100644 --- a/tools/esp8266/esp8266.ino +++ b/tools/esp8266/esp8266.ino @@ -1,3 +1,7 @@ +//----------------------------------------------------------------------------- +// 2022 Ahoy, https://www.mikrocontroller.net/topic/525778 +// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/ +//----------------------------------------------------------------------------- #include "Arduino.h" diff --git a/tools/esp8266/hmDefines.h b/tools/esp8266/hmDefines.h index 37106460..38a2fc4e 100644 --- a/tools/esp8266/hmDefines.h +++ b/tools/esp8266/hmDefines.h @@ -1,3 +1,8 @@ +//----------------------------------------------------------------------------- +// 2022 Ahoy, https://www.mikrocontroller.net/topic/525778 +// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/ +//----------------------------------------------------------------------------- + #ifndef __HM_DEFINES_H__ #define __HM_DEFINES_H__ diff --git a/tools/esp8266/hmInverter.h b/tools/esp8266/hmInverter.h index 65576dbe..6bd61be4 100644 --- a/tools/esp8266/hmInverter.h +++ b/tools/esp8266/hmInverter.h @@ -1,3 +1,8 @@ +//----------------------------------------------------------------------------- +// 2022 Ahoy, https://www.mikrocontroller.net/topic/525778 +// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/ +//----------------------------------------------------------------------------- + #ifndef __HM_INVERTER_H__ #define __HM_INVERTER_H__ @@ -8,7 +13,6 @@ * calculated automatically. * A list of functions can be linked to the assignment and will be executed * automatically. Their result does not differ from original read values. - * The special command 0xff (CMDFF) must be used. */ // forward declaration of class @@ -144,6 +148,7 @@ class Inverter { if(CMD_CALC == assign[i].div) { record[i] = calcFunctions[assign[i].start].func(this, assign[i].num); } + yield(); } } diff --git a/tools/esp8266/hmRadio.h b/tools/esp8266/hmRadio.h index 8e9a2bea..937b7ec2 100644 --- a/tools/esp8266/hmRadio.h +++ b/tools/esp8266/hmRadio.h @@ -1,3 +1,8 @@ +//----------------------------------------------------------------------------- +// 2022 Ahoy, https://www.mikrocontroller.net/topic/525778 +// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/ +//----------------------------------------------------------------------------- + #ifndef __RADIO_H__ #define __RADIO_H__ @@ -86,11 +91,12 @@ class HmRadio { mNrf24.setChannel(DEFAULT_RECV_CHANNEL); mNrf24.setDataRate(RF24_250KBPS); - mNrf24.disableCRC(); + mNrf24.setCRCLength(RF24_CRC_16); mNrf24.setAutoAck(false); mNrf24.setPayloadSize(MAX_RF_PAYLOAD_SIZE); mNrf24.setAddressWidth(5); mNrf24.openReadingPipe(1, DTU_RADIO_ID); + mNrf24.enableDynamicPayloads(); // enable only receiving interrupts mNrf24.maskIRQ(true, true, false); @@ -257,31 +263,26 @@ class HmRadio { DISABLE_IRQ; mNrf24.stopListening(); - if(clear) { + if(clear) mRxLoopCnt = RX_LOOP_CNT; - } mTxCh = getDefaultChannel(); mNrf24.setChannel(mTxCh); - mNrf24.openWritingPipe(invId); // TODO: deprecated mNrf24.setCRCLength(RF24_CRC_16); mNrf24.enableDynamicPayloads(); mNrf24.setAutoAck(true); mNrf24.setRetries(3, 15); // 3*250us and 15 loops -> 11.25ms - mNrf24.write(buf, len); // Try to avoid zero payload acks (has no effect) mNrf24.openWritingPipe(DUMMY_RADIO_ID); // TODO: why dummy radio id?, deprecated - + mRxChIdx = 0; + mNrf24.setChannel(mRxChLst[mRxChIdx]); mNrf24.setAutoAck(false); mNrf24.setRetries(0, 0); mNrf24.disableDynamicPayloads(); mNrf24.setCRCLength(RF24_CRC_DISABLED); - - mRxChIdx = 0; - mNrf24.setChannel(mRxChLst[mRxChIdx]); mNrf24.startListening(); RESTORE_IRQ; diff --git a/tools/esp8266/hmSystem.h b/tools/esp8266/hmSystem.h index 20d756bb..2e992469 100644 --- a/tools/esp8266/hmSystem.h +++ b/tools/esp8266/hmSystem.h @@ -1,3 +1,8 @@ +//----------------------------------------------------------------------------- +// 2022 Ahoy, https://www.mikrocontroller.net/topic/525778 +// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/ +//----------------------------------------------------------------------------- + #ifndef __HM_SYSTEM_H__ #define __HM_SYSTEM_H__ diff --git a/tools/esp8266/html/h/index_html.h b/tools/esp8266/html/h/index_html.h index 0a410fae..de5839da 100644 --- a/tools/esp8266/html/h/index_html.h +++ b/tools/esp8266/html/h/index_html.h @@ -1,4 +1,4 @@ #ifndef __INDEX_HTML_H__ #define __INDEX_HTML_H__ -const char index_html[] PROGMEM = "Index - {DEVICE}

AHOY - {DEVICE}

Visualization

Setup

Uptime:

Time:

Statistics:

Every {TS}seconds the values are updated

This project was started from this discussion. (Mikrocontroller.net)
New updates can be found on Github: https://github.com/grindylow/ahoy

Please report issues using the feature provided by Github.

© 2022

Update Firmware

AHOY :: {VERSION}

Reboot

"; +const char index_html[] PROGMEM = "Index - {DEVICE}

AHOY - {DEVICE}

Visualization

Setup

Uptime:

Time:

Statistics:

Every {TS}seconds the values are updated

This project was started from this discussion. (Mikrocontroller.net)
New updates can be found on Github: https://github.com/grindylow/ahoy

Please report issues using the feature provided by Github.

Creative Commons - Creative Commons - https://creativecommons.org/licenses/by-nc-sa/3.0/de/
Check the licenses which are published on https://github.com/grindylow/ahoyas well

© 2022

Update Firmware

AHOY :: {VERSION}

Reboot

"; #endif /*__INDEX_HTML_H__*/ diff --git a/tools/esp8266/html/h/style_css.h b/tools/esp8266/html/h/style_css.h index 848b8607..5f972cf8 100644 --- a/tools/esp8266/html/h/style_css.h +++ b/tools/esp8266/html/h/style_css.h @@ -1,4 +1,4 @@ #ifndef __STYLE_CSS_H__ #define __STYLE_CSS_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:13pt;color:#006ec0;}.subdes {font-size:12pt;color:#006ec0;margin-left:7px;}.subsubdes {font-size:12pt;color:#006ec0;margin:0 0 7px 12px;}.hide {display:none;}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%;border-top:5px solid #fff;}#footer p, #footer a {color:#fff;padding:0 7px 0 7px;font-size:10pt !important;}div.content {background-color:#fff;padding-bottom:65px;overflow:auto;}input, select {padding:7px;font-size:13pt;}input.text, select {width:70%;box-sizing:border-box;margin-bottom:10px;border:1px solid #ccc;}input.sh {max-width:150px !important;margin-right:10px;}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:15px;}.left {float:left;}.right {float:right;}div.ch-iv {width:100%;background-color:#32b004;display:inline-block;margin-bottom:15px;padding-bottom:20px;overflow:auto;}div.ch {width:220px;min-height:350px;background-color:#006ec0;display:inline-block;margin:0 10px 15px 10px;overflow:auto;padding-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:220px;}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:24px;}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:960px;margin-bottom:40px;}div.ts {font-size:13px;background-color:#ddd;border-top:7px solid #999;padding:7px;}#note {margin:50px 10px 10px 10px;padding-top:10px;width:100%;border-top:1px solid #bbb;}@media(max-width:500px) {div.ch .unit, div.ch-iv .unit {font-size:18px;}div.ch {width:170px;min-height:100px;}.subgrp {width:180px;}}"; +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;}p.lic, p.lic a {font-size:8pt;color:#999;}.des {margin-top:35px;font-size:13pt;color:#006ec0;}.subdes {font-size:12pt;color:#006ec0;margin-left:7px;}.subsubdes {font-size:12pt;color:#006ec0;margin:0 0 7px 12px;}.hide {display:none;}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%;border-top:5px solid #fff;}#footer p, #footer a {color:#fff;padding:0 7px 0 7px;font-size:10pt !important;}div.content {background-color:#fff;padding-bottom:65px;overflow:auto;}input, select {padding:7px;font-size:13pt;}input.text, select {width:70%;box-sizing:border-box;margin-bottom:10px;border:1px solid #ccc;}input.sh {max-width:150px !important;margin-right:10px;}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:15px;}.left {float:left;}.right {float:right;}div.ch-iv {width:100%;background-color:#32b004;display:inline-block;margin-bottom:15px;padding-bottom:20px;overflow:auto;}div.ch {width:220px;min-height:350px;background-color:#006ec0;display:inline-block;margin:0 10px 15px 10px;overflow:auto;padding-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:220px;}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:24px;}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:960px;margin-bottom:40px;}div.ts {font-size:13px;background-color:#ddd;border-top:7px solid #999;padding:7px;}#note {margin:50px 10px 10px 10px;padding-top:10px;width:100%;border-top:1px solid #bbb;}@media(max-width:500px) {div.ch .unit, div.ch-iv .unit {font-size:18px;}div.ch {width:170px;min-height:100px;}.subgrp {width:180px;}}"; #endif /*__STYLE_CSS_H__*/ diff --git a/tools/esp8266/html/index.html b/tools/esp8266/html/index.html index 71cee71f..f07d032a 100644 --- a/tools/esp8266/html/index.html +++ b/tools/esp8266/html/index.html @@ -46,7 +46,10 @@ This project was started from this discussion. (Mikrocontroller.net)
New updates can be found on Github: https://github.com/grindylow/ahoy

- Please report issues using the feature provided by Github. + Please report issues using the feature provided by Github.
+
+

Creative Commons - Creative Commons - https://creativecommons.org/licenses/by-nc-sa/3.0/de/
+ Check the licenses which are published on https://github.com/grindylow/ahoy as well