From 20c145013eaa3b5924ba9ec17c24e1f332887307 Mon Sep 17 00:00:00 2001 From: stefan123t Date: Thu, 16 Jun 2022 11:28:49 +0200 Subject: [PATCH 1/5] added DEBUG_FLAGs to config.h --- tools/esp8266/app.cpp | 32 +++++++++++++++++++++++++++++ tools/esp8266/config.h | 7 +++++++ tools/esp8266/hmInverter.h | 36 ++++++++++++++++++++++++++++++++ tools/esp8266/hmRadio.h | 22 ++++++++++++++++++++ tools/esp8266/hmSystem.h | 10 +++++++++ tools/esp8266/main.cpp | 42 ++++++++++++++++++++++++++++++++++++++ tools/esp8266/main.h | 12 +++++++++++ 7 files changed, 161 insertions(+) diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index 79c4b045..a2a64210 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -7,7 +7,9 @@ //----------------------------------------------------------------------------- app::app() : Main() { +#ifdef DEBUG_APP DPRINTLN(F("app::app():Main")); +#endif mSendTicker = 0xffff; mSendInterval = 0; mMqttTicker = 0xffff; @@ -43,7 +45,9 @@ app::~app(void) { //----------------------------------------------------------------------------- void app::setup(uint32_t timeout) { +#ifdef DEBUG_APP DPRINTLN(F("app::setup")); +#endif Main::setup(timeout); mWeb->on("/", std::bind(&app::showIndex, this)); @@ -187,9 +191,11 @@ void app::setup(uint32_t timeout) { //----------------------------------------------------------------------------- void app::loop(void) { +#ifdef DEBUG_APP //DPRINT(F("a")); //DPRINTLN(F("a")); //app_loops++; +#ifdef DEBUG_APP Main::loop(); mSys->Radio.loop(); @@ -197,9 +203,11 @@ void app::loop(void) { yield(); if(checkTicker(&mRxTicker, 5)) { +#ifdef DEBUG_APP //DPRINTLN(F("app_loops =") + String(app_loops)); //app_loops=0; //DPRINT(F("a")); +#endif bool rxRdy = mSys->Radio.switchRxCh(); if(!mSys->BufCtrl.empty()) { @@ -350,14 +358,18 @@ void app::loop(void) { //----------------------------------------------------------------------------- void app::handleIntr(void) { +#ifdef DEBUG_APP //DPRINTLN(F("app::handleIntr")); +#endif mSys->Radio.handleIntr(); } //----------------------------------------------------------------------------- bool app::buildPayload(uint8_t id) { +#ifdef DEBUG_APP //DPRINTLN(F("app::buildPayload")); +#endif uint16_t crc = 0xffff, crcRcv; if(mPayload[id].maxPackId > MAX_PAYLOAD_ENTRIES) mPayload[id].maxPackId = MAX_PAYLOAD_ENTRIES; @@ -382,8 +394,10 @@ bool app::buildPayload(uint8_t id) { //----------------------------------------------------------------------------- void app::processPayload(bool retransmit) { +#ifdef DEBUG_APP //DPRINTLN(F("app::processPayload")); //DPRINT(F("p")); +#endif for(uint8_t id = 0; id < mSys->getNumInverters(); id++) { Inverter<> *iv = mSys->getInverterByPos(id); if(NULL != iv) { @@ -448,7 +462,9 @@ void app::processPayload(bool retransmit) { //----------------------------------------------------------------------------- void app::showIndex(void) { +#ifdef DEBUG_APP DPRINTLN(F("app::showIndex")); +#endif String html = FPSTR(index_html); html.replace(F("{DEVICE}"), mDeviceName); html.replace(F("{VERSION}"), mVersion); @@ -460,7 +476,9 @@ void app::showIndex(void) { //----------------------------------------------------------------------------- void app::showSetup(void) { +#ifdef DEBUG_APP DPRINTLN(F("app::showSetup")); +#endif // overrides same method in main.cpp uint16_t interval; @@ -580,14 +598,18 @@ void app::showSetup(void) { //----------------------------------------------------------------------------- void app::showSave(void) { +#ifdef DEBUG_APP DPRINTLN(F("app::showSave")); +#endif saveValues(true); } //----------------------------------------------------------------------------- void app::showErase() { +#ifdef DEBUG_APP DPRINTLN(F("app::showErase")); +#endif eraseSettings(); showReboot(); } @@ -595,7 +617,9 @@ void app::showErase() { //----------------------------------------------------------------------------- void app::showStatistics(void) { +#ifdef DEBUG_APP //DPRINTLN(F("app::showStatistics")); +#endif String content = F("Receive success: ") + String(mRxSuccess) + "\n"; content += F("Receive fail: ") + String(mRxFailed) + "\n"; content += F("Send Cnt: ") + String(mSys->Radio.mSendCnt) + String("\n\n"); @@ -644,7 +668,9 @@ void app::showStatistics(void) { //----------------------------------------------------------------------------- void app::showHoymiles(void) { +#ifdef DEBUG_APP DPRINTLN(F("app::showHoymiles")); +#endif String html = FPSTR(hoymiles_html); html.replace(F("{DEVICE}"), mDeviceName); html.replace(F("{VERSION}"), mVersion); @@ -656,7 +682,9 @@ void app::showHoymiles(void) { //----------------------------------------------------------------------------- void app::showLiveData(void) { +#ifdef DEBUG_APP //DPRINTLN(F("app::showLiveData")); +#endif String modHtml; for(uint8_t id = 0; id < mSys->getNumInverters(); id++) { Inverter<> *iv = mSys->getInverterByPos(id); @@ -734,7 +762,9 @@ void app::showLiveData(void) { //----------------------------------------------------------------------------- void app::saveValues(bool webSend = true) { +#ifdef DEBUG_APP DPRINTLN(F("app::saveValues")); +#endif Main::saveValues(false); // general configuration if(mWeb->args() > 0) { @@ -843,7 +873,9 @@ void app::saveValues(bool webSend = true) { //----------------------------------------------------------------------------- void app::updateCrc(void) { +#ifdef DEBUG_APP DPRINTLN(F("app::updateCrc")); +#endif Main::updateCrc(); uint16_t crc; diff --git a/tools/esp8266/config.h b/tools/esp8266/config.h index 2c98449c..2ae56ff9 100644 --- a/tools/esp8266/config.h +++ b/tools/esp8266/config.h @@ -53,4 +53,11 @@ // changes the style of "/setup" page, visualized = nicer #define LIVEDATA_VISUALIZED +// comment out to disable any of the debug options here +#define DEBUG_APP +#define DEBUG_HMINVERTER +#define DEBUG_HMRADIO +#define DEBUG_HMSYSTEM +#define DEBUG_HMMAIN + #endif /*__CONFIG_H__*/ diff --git a/tools/esp8266/hmInverter.h b/tools/esp8266/hmInverter.h index 65576dbe..51a2a7dd 100644 --- a/tools/esp8266/hmInverter.h +++ b/tools/esp8266/hmInverter.h @@ -82,7 +82,9 @@ class Inverter { } void init(void) { +#ifdef DEBUG_HMINVERTER DPRINTLN(F("hmInverter.h:init")); +#endif getAssignment(); toRadioId(); record = new RECORDTYPE[listLen]; @@ -92,7 +94,9 @@ class Inverter { } uint8_t getPosByChFld(uint8_t channel, uint8_t fieldId) { +#ifdef DEBUG_HMINVERTER //DPRINTLN(F("hmInverter.h:getPosByChFld")); +#endif uint8_t pos = 0; for(; pos < listLen; pos++) { if((assign[pos].ch == channel) && (assign[pos].fieldId == fieldId)) @@ -102,22 +106,30 @@ class Inverter { } const char *getFieldName(uint8_t pos) { +#ifdef DEBUG_HMINVERTER //DPRINTLN(F("hmInverter.h:getFieldName")); +#endif return fields[assign[pos].fieldId]; } const char *getUnit(uint8_t pos) { +#ifdef DEBUG_HMINVERTER //DPRINTLN(F("hmInverter.h:getUnit")); +#endif return units[assign[pos].unitId]; } uint8_t getChannel(uint8_t pos) { +#ifdef DEBUG_HMINVERTER //DPRINTLN(F("hmInverter.h:getChannel")); +#endif return assign[pos].ch; } void addValue(uint8_t pos, uint8_t buf[]) { +#ifdef DEBUG_HMINVERTER //DPRINTLN(F("hmInverter.h:addValue")); +#endif uint8_t ptr = assign[pos].start; uint8_t end = ptr + assign[pos].num; uint16_t div = assign[pos].div; @@ -134,12 +146,16 @@ class Inverter { } RECORDTYPE getValue(uint8_t pos) { +#ifdef DEBUG_HMINVERTER //DPRINTLN(F("hmInverter.h:getValue")); +#endif return record[pos]; } void doCalculations(void) { +#ifdef DEBUG_HMINVERTER //DPRINTLN(F("hmInverter.h:doCalculations")); +#endif for(uint8_t i = 0; i < listLen; i++) { if(CMD_CALC == assign[i].div) { record[i] = calcFunctions[assign[i].start].func(this, assign[i].num); @@ -148,7 +164,9 @@ class Inverter { } bool isAvailable(uint32_t timestamp) { +#ifdef DEBUG_HMINVERTER //DPRINTLN(F("hmInverter.h:isAvailable")); +#endif return ((timestamp - ts) < INACT_THRES_SEC); } @@ -162,13 +180,17 @@ class Inverter { } uint32_t getLastTs(void) { +#ifdef DEBUG_HMINVERTER //DPRINTLN(F("hmInverter.h:getLastTs")); +#endif return ts; } private: void toRadioId(void) { +#ifdef DEBUG_HMINVERTER //DPRINTLN(F("hmInverter.h:toRadioId")); +#endif radioId.u64 = 0ULL; radioId.b[4] = serial.b[0]; radioId.b[3] = serial.b[1]; @@ -178,7 +200,9 @@ class Inverter { } void getAssignment(void) { +#ifdef DEBUG_HMINVERTER //DPRINTLN(F("hmInverter.h:getAssignment")); +#endif if(INV_TYPE_1CH == type) { listLen = (uint8_t)(HM1CH_LIST_LEN); assign = (byteAssign_t*)hm1chAssignment; @@ -211,7 +235,9 @@ class Inverter { template static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) { +#ifdef DEBUG_HMINVERTER //DPRINTLN(F("hmInverter.h:calcYieldTotalCh0")); +#endif if(NULL != iv) { T yield = 0; for(uint8_t i = 1; i <= iv->channels; i++) { @@ -225,7 +251,9 @@ static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) { template static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) { +#ifdef DEBUG_HMINVERTER //DPRINTLN(F("hmInverter.h:calcYieldDayCh0")); +#endif if(NULL != iv) { T yield = 0; for(uint8_t i = 1; i <= iv->channels; i++) { @@ -239,7 +267,9 @@ static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) { template static T calcUdcCh(Inverter<> *iv, uint8_t arg0) { +#ifdef DEBUG_HMINVERTER //DPRINTLN(F("hmInverter.h:calcUdcCh")); +#endif // arg0 = channel of source for(uint8_t i = 0; i < iv->listLen; i++) { if((FLD_UDC == iv->assign[i].fieldId) && (arg0 == iv->assign[i].ch)) { @@ -252,7 +282,9 @@ static T calcUdcCh(Inverter<> *iv, uint8_t arg0) { template static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) { +#ifdef DEBUG_HMINVERTER //DPRINTLN(F("hmInverter.h:calcPowerDcCh0")); +#endif if(NULL != iv) { T dcPower = 0; for(uint8_t i = 1; i <= iv->channels; i++) { @@ -266,7 +298,9 @@ static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) { template static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) { +#ifdef DEBUG_HMINVERTER //DPRINTLN(F("hmInverter.h:calcEfficiencyCh0")); +#endif if(NULL != iv) { uint8_t pos = iv->getPosByChFld(CH0, FLD_PAC); T acPower = iv->getValue(pos); @@ -283,7 +317,9 @@ static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) { template static T calcIrradiation(Inverter<> *iv, uint8_t arg0) { +#ifdef DEBUG_HMINVERTER //DPRINTLN(F("hmInverter.h:calcIrradiation")); +#endif // arg0 = channel if(NULL != iv) { uint8_t pos = iv->getPosByChFld(arg0, FLD_PDC); diff --git a/tools/esp8266/hmRadio.h b/tools/esp8266/hmRadio.h index 8e9a2bea..1dc71394 100644 --- a/tools/esp8266/hmRadio.h +++ b/tools/esp8266/hmRadio.h @@ -49,7 +49,9 @@ template > 8)); @@ -189,7 +201,9 @@ class HmRadio { } bool checkPaketCrc(uint8_t buf[], uint8_t *len, uint8_t rxCh) { +#ifdef DEBUG_HMRADIO //DPRINTLN(F("hmRadio.h:checkPaketCrc")); +#endif *len = (buf[0] >> 2); if(*len > (MAX_RF_PAYLOAD_SIZE - 2)) *len = MAX_RF_PAYLOAD_SIZE - 2; @@ -204,8 +218,10 @@ class HmRadio { } bool switchRxCh(uint16_t addLoop = 0) { +#ifdef DEBUG_HMRADIO //DPRINTLN(F("hmRadio.h:switchRxCh")); //DPRINT(F("R")); +#endif mRxLoopCnt += addLoop; if(mRxLoopCnt != 0) { @@ -220,7 +236,9 @@ class HmRadio { } void dumpBuf(const char *info, uint8_t buf[], uint8_t len) { +#ifdef DEBUG_HMRADIO //DPRINTLN(F("hmRadio.h:dumpBuf")); +#endif if(NULL != info) DPRINT(String(info)); for(uint8_t i = 0; i < len; i++) { @@ -231,7 +249,9 @@ class HmRadio { } bool isChipConnected(void) { +#ifdef DEBUG_HMRADIO //DPRINTLN(F("hmRadio.h:isChipConnected")); +#endif return mNrf24.isChipConnected(); } @@ -246,9 +266,11 @@ class HmRadio { private: void sendPacket(uint64_t invId, uint8_t buf[], uint8_t len, bool clear=false) { +#ifdef DEBUG_HMRADIO //DPRINTLN(F("hmRadio.h:sendPacket")); //DPRINTLN("sent packet: #" + String(mSendCnt)); //dumpBuf("SEN ", buf, len); +#endif if(mSerialDebug) { DPRINT("Transmit " + String(len) + " | "); dumpBuf(NULL, buf, len); diff --git a/tools/esp8266/hmSystem.h b/tools/esp8266/hmSystem.h index 20d756bb..301d1b40 100644 --- a/tools/esp8266/hmSystem.h +++ b/tools/esp8266/hmSystem.h @@ -24,12 +24,16 @@ class HmSystem { } void setup() { +#ifdef DEBUG_HMSYSTEM DPRINTLN(F("hmSystem.h:setup")); +#endif Radio.setup(&BufCtrl); } INVERTERTYPE *addInverter(const char *name, uint64_t serial, uint16_t chMaxPwr[]) { +#ifdef DEBUG_HMSYSTEM DPRINTLN(F("hmSystem.h:addInverter")); +#endif if(MAX_INVERTER <= mNumInv) { DPRINT(F("max number of inverters reached!")); return NULL; @@ -66,7 +70,9 @@ class HmSystem { } INVERTERTYPE *findInverter(uint8_t buf[]) { +#ifdef DEBUG_HMSYSTEM //DPRINTLN(F("hmSystem.h:findInverter")); +#endif INVERTERTYPE *p; for(uint8_t i = 0; i < mNumInv; i++) { p = &mInverter[i]; @@ -80,7 +86,9 @@ class HmSystem { } INVERTERTYPE *getInverterByPos(uint8_t pos) { +#ifdef DEBUG_HMSYSTEM //DPRINTLN(F("hmSystem.h:getInverterByPos")); +#endif if(mInverter[pos].serial.u64 != 0ULL) return &mInverter[pos]; else @@ -88,7 +96,9 @@ class HmSystem { } uint8_t getNumInverters(void) { +#ifdef DEBUG_HMSYSTEM //DPRINTLN(F("hmSystem.h:getNumInverters")); +#endif return mNumInv; } diff --git a/tools/esp8266/main.cpp b/tools/esp8266/main.cpp index 041932fa..8c9ce420 100644 --- a/tools/esp8266/main.cpp +++ b/tools/esp8266/main.cpp @@ -26,7 +26,9 @@ Main::Main(void) { mEep = new eep(); Serial.begin(115200); +#ifdef DEBUG_HMMAIN DPRINTLN(F("Main::Main")); +#endif mUptimeSecs = 0; mUptimeTicker = 0xffffffff; @@ -40,7 +42,9 @@ Main::Main(void) { //----------------------------------------------------------------------------- void Main::setup(uint32_t timeout) { +#ifdef DEBUG_HMMAIN DPRINTLN(F("Main::setup")); +#endif bool startAp = mApActive; mLimit = timeout; @@ -69,7 +73,9 @@ void Main::setup(uint32_t timeout) { //----------------------------------------------------------------------------- void Main::loop(void) { +#ifdef DEBUG_HMMAIN //DPRINT(F("M")); +#endif if(mApActive) { mDns->processNextRequest(); #ifndef AP_ONLY @@ -118,7 +124,9 @@ void Main::loop(void) { //----------------------------------------------------------------------------- bool Main::getConfig(void) { +#ifdef DEBUG_HMMAIN DPRINTLN(F("Main::getConfig")); +#endif bool mApActive = false; mWifiSettingsValid = checkEEpCrc(ADDR_START, ADDR_WIFI_CRC, ADDR_WIFI_CRC); @@ -141,7 +149,9 @@ bool Main::getConfig(void) { //----------------------------------------------------------------------------- void Main::setupAp(const char *ssid, const char *pwd) { +#ifdef DEBUG_HMMAIN DPRINTLN(F("Main::setupAp")); +#endif IPAddress apIp(192, 168, 1, 1); DPRINTLN(F("\n---------\nAP MODE\nSSDI: ") @@ -149,7 +159,9 @@ void Main::setupAp(const char *ssid, const char *pwd) { + String(pwd) + F("\nActive for: ") + String(WIFI_AP_ACTIVE_TIME) + F(" seconds") + F("\n---------\n")); +#ifdef DEBUG_HMMAIN DPRINTLN("DBG: " + String(mNextTryTs)); +#endif WiFi.mode(WIFI_AP); WiFi.softAPConfig(apIp, apIp, IPAddress(255, 255, 255, 0)); @@ -168,7 +180,9 @@ void Main::setupAp(const char *ssid, const char *pwd) { //----------------------------------------------------------------------------- bool Main::setupStation(uint32_t timeout) { +#ifdef DEBUG_HMMAIN DPRINTLN(F("Main::setupStation")); +#endif int32_t cnt; bool startAp = false; @@ -218,7 +232,9 @@ bool Main::setupStation(uint32_t timeout) { //----------------------------------------------------------------------------- void Main::showSetup(void) { +#ifdef DEBUG_HMMAIN DPRINTLN(F("Main::showSetup")); +#endif String html = FPSTR(setup_html); html.replace(F("{SSID}"), mStationSsid); // PWD will be left at the default value (for protection) @@ -236,21 +252,27 @@ void Main::showSetup(void) { //----------------------------------------------------------------------------- void Main::showCss(void) { +#ifdef DEBUG_HMMAIN DPRINTLN(F("Main::showCss")); +#endif mWeb->send(200, "text/css", FPSTR(style_css)); } //----------------------------------------------------------------------------- void Main::showSave(void) { +#ifdef DEBUG_HMMAIN DPRINTLN(F("Main::showSave")); +#endif saveValues(true); } //----------------------------------------------------------------------------- void Main::saveValues(bool webSend = true) { +#ifdef DEBUG_HMMAIN DPRINTLN(F("Main::saveValues")); +#endif if(mWeb->args() > 0) { if(mWeb->arg("ssid") != "") { memset(mStationSsid, 0, SSID_LEN); @@ -284,7 +306,9 @@ void Main::saveValues(bool webSend = true) { //----------------------------------------------------------------------------- void Main::updateCrc(void) { +#ifdef DEBUG_HMMAIN DPRINTLN(F("Main::updateCrc")); +#endif uint16_t crc; crc = buildEEpCrc(ADDR_START, ADDR_WIFI_CRC); //Serial.println("new CRC: " + String(crc, HEX)); @@ -295,7 +319,9 @@ void Main::updateCrc(void) { //----------------------------------------------------------------------------- void Main::showUptime(void) { +#ifdef DEBUG_HMMAIN //DPRINTLN(F("Main::showUptime")); +#endif char time[20] = {0}; int upTimeSc = uint32_t((mUptimeSecs) % 60); @@ -311,14 +337,18 @@ void Main::showUptime(void) { //----------------------------------------------------------------------------- void Main::showTime(void) { +#ifdef DEBUG_HMMAIN //DPRINTLN(F("Main::showTime")); +#endif mWeb->send(200, "text/plain", getDateTimeStr(mTimestamp)); } //----------------------------------------------------------------------------- void Main::showNotFound(void) { +#ifdef DEBUG_HMMAIN DPRINTLN(F("Main::showNotFound - ") + mWeb->uri()); +#endif String msg = F("File Not Found\n\nURI: "); msg += mWeb->uri(); msg += F("\nMethod: "); @@ -337,7 +367,9 @@ void Main::showNotFound(void) { //----------------------------------------------------------------------------- void Main::showReboot(void) { +#ifdef DEBUG_HMMAIN DPRINTLN(F("Main::showReboot")); +#endif mWeb->send(200, F("text/html"), F("Rebooting ...rebooting ... auto reload after 10s")); delay(1000); ESP.restart(); @@ -347,7 +379,9 @@ void Main::showReboot(void) { //----------------------------------------------------------------------------- void Main::showFactoryRst(void) { +#ifdef DEBUG_HMMAIN DPRINTLN(F("Main::showFactoryRst")); +#endif String content = ""; int refresh = 3; if(mWeb->args() > 0) { @@ -376,7 +410,9 @@ void Main::showFactoryRst(void) { //----------------------------------------------------------------------------- time_t Main::getNtpTime(void) { +#ifdef DEBUG_HMMAIN //DPRINTLN(F("Main::getNtpTime")); +#endif time_t date = 0; IPAddress timeServer; uint8_t buf[NTP_PACKET_SIZE]; @@ -414,7 +450,9 @@ time_t Main::getNtpTime(void) { //----------------------------------------------------------------------------- void Main::sendNTPpacket(IPAddress& address) { +#ifdef DEBUG_HMMAIN //DPRINTLN(F("Main::sendNTPpacket")); +#endif uint8_t buf[NTP_PACKET_SIZE] = {0}; buf[0] = B11100011; // LI, Version, Mode @@ -435,7 +473,9 @@ void Main::sendNTPpacket(IPAddress& address) { //----------------------------------------------------------------------------- String Main::getDateTimeStr(time_t t) { +#ifdef DEBUG_HMMAIN //DPRINTLN(F("Main::getDateTimeStr")); +#endif char str[20] = {0}; if(0 == t) sprintf(str, "n/a"); @@ -449,7 +489,9 @@ String Main::getDateTimeStr(time_t t) { // calculates the daylight saving time for middle Europe. Input: Unixtime in UTC // from: https://forum.arduino.cc/index.php?topic=172044.msg1278536#msg1278536 time_t Main::offsetDayLightSaving (uint32_t local_t) { +#ifdef DEBUG_HMMAIN //DPRINTLN(F("Main::offsetDayLightSaving")); +#endif int m = month (local_t); if(m < 3 || m > 10) return 0; // no DSL in Jan, Feb, Nov, Dez if(m > 3 && m < 10) return 1; // DSL in Apr, May, Jun, Jul, Aug, Sep diff --git a/tools/esp8266/main.h b/tools/esp8266/main.h index 6a066bed..d642c7ca 100644 --- a/tools/esp8266/main.h +++ b/tools/esp8266/main.h @@ -41,7 +41,9 @@ class Main { virtual void updateCrc(void); inline uint16_t buildEEpCrc(uint32_t start, uint32_t length) { +#ifdef DEBUG_HMMAIN DPRINTLN(F("main.h:buildEEpCrc")); +#endif uint8_t buf[32]; uint16_t crc = 0xffff; uint8_t len; @@ -57,16 +59,22 @@ class Main { } bool checkEEpCrc(uint32_t start, uint32_t length, uint32_t crcPos) { +#ifdef DEBUG_HMMAIN //DPRINTLN(F("main.h:checkEEpCrc")); +#endif uint16_t crcRd, crcCheck; crcCheck = buildEEpCrc(start, length); mEep->read(crcPos, &crcRd); +#ifdef DEBUG_HMMAIN //DPRINTLN("CRC RD: " + String(crcRd, HEX) + " CRC CALC: " + String(crcCheck, HEX)); +#endif return (crcCheck == crcRd); } void eraseSettings(bool all = false) { +#ifdef DEBUG_HMMAIN //DPRINTLN(F("main.h:eraseSettings")); +#endif uint8_t buf[64] = {0}; uint16_t addr = (all) ? ADDR_START : ADDR_START_SETTINGS; uint16_t end; @@ -82,7 +90,9 @@ class Main { } inline bool checkTicker(uint32_t *ticker, uint32_t interval) { +#ifdef DEBUG_HMMAIN //DPRINT(F("c")); +#endif uint32_t mil = millis(); if(mil >= *ticker) { *ticker = mil + interval; @@ -97,7 +107,9 @@ class Main { } void stats(void) { +#ifdef DEBUG_HMMAIN DPRINTLN(F("main.h:stats")); +#endif uint32_t free; uint16_t max; uint8_t frag; From d876fe841e723c6b4147945463363e25a341b0a6 Mon Sep 17 00:00:00 2001 From: stefan123t Date: Thu, 16 Jun 2022 11:30:33 +0200 Subject: [PATCH 2/5] added pyRF24 build instructions from mslookup --- tools/rpi/README.md | 56 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/tools/rpi/README.md b/tools/rpi/README.md index 3e5001ea..f779b8b8 100644 --- a/tools/rpi/README.md +++ b/tools/rpi/README.md @@ -16,7 +16,6 @@ Thanks go to all who contributed, and are continuing to contribute, by providing their time, equipment, and ingenuity! - Required Hardware Setup ----------------------- @@ -26,11 +25,61 @@ Required Hardware Setup - NRF24L01+ Radio Module connected as described, e.g., in [2] (Instructions at [3] should work identically, but [2] has more pretty pictures.) -- TMRh20's 'Optimized High Speed nRF24L01+ Driver' [3], installed +- TMRh20's 'Optimized High Speed nRF24L01+ Driver' [3], installed as per the instructions given in [4] - Python Library Wrapper, as per [5] +Building the NRF24 Python Wrapper +--------------------------------- + +You have to install the NRF24 Python Library, as a Dependency for the Raspberry Pi Version of Ahoy. + +To do that correctly, I have contacted the developer of NRF24 via github +[Python 3 Wrapper not installing properly #845](https://github.com/nRF24/RF24/issues/845) +as I could not get the Python Wrapper for NRF24 to be built. + +- Install Raspberry Pi OS lite x86 with raspberry pi imager +- Connect nrf24 module to raspberry pi (as described in github) +- Login with user pi +- Execute `sudo apt update && sudo apt -y upgrade` +- Execute `sudo raspi-config` and + - Select "Expand filesystem" in "Advanced Options" + - Activate "SPI" in "Interface Options" + - "Finish" to exit `raspi-config` Tool, reboot YES! +- Login as pi user again + +```code +sudo apt install cmake git python3-dev libboost-python-dev python3-pip python3-rpi.gpio + +sudo ln -s $(ls /usr/lib/$(ls /usr/lib/gcc | \ + tail -1)/libboost_python3*.so | \ + tail -1) /usr/lib/$(ls /usr/lib/gcc | \ + tail -1)/libboost_python3.so + +git clone https://github.com/nRF24/RF24.git +cd RF24 + +export RF24_DRIVER=SPIDEV +rm Makefile.inc #just to make sure there is no old stuff +mkdir build && cd build +cmake .. +make +sudo make install + +cd ../pyRF24 +rm -r ./build/ ./dist/ ./RF24.egg-info/ ./__pycache__/ #just to make sure there is no old stuff +python3 -m pip install --upgrade pip +python3 -m pip install . +python3 -m pip list #watch for RF24 module - if its there its installed + +cd .. +cd examples_linux/ +python3 getting_started.py # to test and see whether RF24 class can be loaded as module in python correctly +``` + +If there are no error messages on the last step, then the NRF24 Wrapper has been installed successfully. + Example Run ----------- @@ -81,7 +130,7 @@ This can be used to inject debug payloads The message must be in hexlified format Use of variables: - * tttttttt expands to current time like we know from our `80 0b` command + * `tttttttt` expands to current time like we know from our `80 0b` command Example injects exactly the same as we normally use to poll data @@ -139,4 +188,3 @@ References - [3] https://nrf24.github.io/RF24/index.html - [4] https://nrf24.github.io/RF24/md_docs_linux_install.html - [5] https://nrf24.github.io/RF24/md_docs_python_wrapper.html - From 1e4afddafc471055b94a8072ca62b09078538dc7 Mon Sep 17 00:00:00 2001 From: stefan123t Date: Thu, 16 Jun 2022 11:31:08 +0200 Subject: [PATCH 3/5] added links to some documentation --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6c781bbf..9d166a62 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,13 @@ Various tools, examples, and documentation for communicating with Hoymiles micro In particular: -* `doc/hoymiles-format-description.txt` is a detailed description of the communications format and the history of this project -* `doc/getting-started-ESP8266.md` shows the hardware setup for an ESP8266-based system +* `doc/hoymiles-format-description.txt` is a [detailed description of the communications format](doc/hoymiles-format-description.md) and the history of this project +* `doc/getting-started-ESP8266.md` shows the [hardware setup for an ESP8266-based system](doc/getting-started-ESP8266.md) * The `tools` folder contains various software tools for RaspberryPi, Arduino and ESP8266/ESP32: - * A [version for ESP8266](tools/esp8266) that includes a web interface - * A [version for Arduino Nano](tools/nano/NRF24_SendRcv) - * An [alternative Version of the above](tools/NRF24_SendRcv) - * A [different implementation](tools/HoyDtuSim) - * An [implementation for Raspberry Pi](tools/rpi) that polls an inverter and archives results as log files/stdout as well as posting them to an MQTT broker. + * A [version for ESP8266](tools/esp8266/) that includes an web interface + * A [version for Arduino Nano](tools/nano/NRF24_SendRcv/) + * An [alternative Version of the above](tools/NRF24_SendRcv/) + * A [different implementation](tools/HoyDtuSim/) + * An [implementation for Raspberry Pi](tools/rpi/) that polls an inverter and archives results as log files/stdout as well as posting them to an MQTT broker. Contributors are always welcome! From 14c46e86bd3f4337a5ac2f3725608b71a358ae80 Mon Sep 17 00:00:00 2001 From: stefan123t Date: Thu, 16 Jun 2022 22:27:16 +0200 Subject: [PATCH 4/5] added variable error messages using #pragma error --- tools/esp8266/defines.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/esp8266/defines.h b/tools/esp8266/defines.h index df9a055c..a75b34e0 100644 --- a/tools/esp8266/defines.h +++ b/tools/esp8266/defines.h @@ -87,10 +87,16 @@ typedef struct { #define ADDR_SER_INTERVAL ADDR_SER_DEBUG + SER_DEBUG_LEN #define ADDR_NEXT ADDR_SER_INTERVAL + SER_INTERVAL_LEN -#define ADDR_SETTINGS_CRC 950 +// #define ADDR_SETTINGS_CRC 950 +#define ADDR_SETTINGS_CRC ADDR_NEXT + CRC_LEN #if(ADDR_SETTINGS_CRC <= ADDR_NEXT) -#error address overlap! +#pragma error "address overlap! (ADDR_SETTINGS_CRC="+ ADDR_SETTINGS_CRC +", ADDR_NEXT="+ ADDR_NEXT +")" +#endif + +#if(ADDR_SETTINGS_CRC >= 4096 - CRC_LEN) +#pragma error "EEPROM size exceeded! (ADDR_SETTINGS_CRC="+ ADDR_SETTINGS_CRC +", CRC_LEN="+ CRC_LEN +")" +#pragma error "Configure less inverters? (MAX_NUM_INVERTERS=" + MAX_NUM_INVERTERS +")" #endif #endif /*__DEFINES_H__*/ From 17b186ee04e72abfd1653ae1b767a138f4835b61 Mon Sep 17 00:00:00 2001 From: stefan123t Date: Fri, 17 Jun 2022 00:18:45 +0200 Subject: [PATCH 5/5] added DBGXXX definitions to all header files --- tools/esp8266/app.h | 6 +++ tools/esp8266/hmInverter.h | 80 ++++++++++++-------------------------- tools/esp8266/hmRadio.h | 54 +++++++++---------------- tools/esp8266/hmSystem.h | 26 +++++-------- tools/esp8266/main.cpp | 80 ++++++++++---------------------------- tools/esp8266/main.h | 29 ++++++-------- 6 files changed, 91 insertions(+), 184 deletions(-) diff --git a/tools/esp8266/app.h b/tools/esp8266/app.h index 3151e404..b4ed6e7c 100644 --- a/tools/esp8266/app.h +++ b/tools/esp8266/app.h @@ -11,6 +11,12 @@ #include "hmSystem.h" #include "mqtt.h" +#ifdef DEBUG_APP +#define DBGAPP(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0) +#else +#define DBGAPP(x...) do { (void)0; } while (0) +#endif + typedef CircularBuffer BufferType; typedef HmRadio RadioType; typedef Inverter InverterType; diff --git a/tools/esp8266/hmInverter.h b/tools/esp8266/hmInverter.h index 51a2a7dd..59f5d53c 100644 --- a/tools/esp8266/hmInverter.h +++ b/tools/esp8266/hmInverter.h @@ -3,6 +3,12 @@ #include "hmDefines.h" +#ifdef DEBUG_HMINVERTER +#define DBGINV(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0) +#else +#define DBGINV(x...) do { (void)0; } while (0) +#endif + /** * For values which are of interest and not transmitted by the inverter can be * calculated automatically. @@ -82,9 +88,7 @@ class Inverter { } void init(void) { -#ifdef DEBUG_HMINVERTER - DPRINTLN(F("hmInverter.h:init")); -#endif + DBGINV(F("hmInverter.h:init")); getAssignment(); toRadioId(); record = new RECORDTYPE[listLen]; @@ -94,9 +98,7 @@ class Inverter { } uint8_t getPosByChFld(uint8_t channel, uint8_t fieldId) { -#ifdef DEBUG_HMINVERTER - //DPRINTLN(F("hmInverter.h:getPosByChFld")); -#endif + //DBGINV(F("hmInverter.h:getPosByChFld")); uint8_t pos = 0; for(; pos < listLen; pos++) { if((assign[pos].ch == channel) && (assign[pos].fieldId == fieldId)) @@ -106,30 +108,22 @@ class Inverter { } const char *getFieldName(uint8_t pos) { -#ifdef DEBUG_HMINVERTER - //DPRINTLN(F("hmInverter.h:getFieldName")); -#endif + //DBGINV(F("hmInverter.h:getFieldName")); return fields[assign[pos].fieldId]; } const char *getUnit(uint8_t pos) { -#ifdef DEBUG_HMINVERTER - //DPRINTLN(F("hmInverter.h:getUnit")); -#endif + //DBGINV(F("hmInverter.h:getUnit")); return units[assign[pos].unitId]; } uint8_t getChannel(uint8_t pos) { -#ifdef DEBUG_HMINVERTER - //DPRINTLN(F("hmInverter.h:getChannel")); -#endif + //DBGINV(F("hmInverter.h:getChannel")); return assign[pos].ch; } void addValue(uint8_t pos, uint8_t buf[]) { -#ifdef DEBUG_HMINVERTER - //DPRINTLN(F("hmInverter.h:addValue")); -#endif + //DBGINV(F("hmInverter.h:addValue")); uint8_t ptr = assign[pos].start; uint8_t end = ptr + assign[pos].num; uint16_t div = assign[pos].div; @@ -146,16 +140,12 @@ class Inverter { } RECORDTYPE getValue(uint8_t pos) { -#ifdef DEBUG_HMINVERTER - //DPRINTLN(F("hmInverter.h:getValue")); -#endif + //DBGINV(F("hmInverter.h:getValue")); return record[pos]; } void doCalculations(void) { -#ifdef DEBUG_HMINVERTER - //DPRINTLN(F("hmInverter.h:doCalculations")); -#endif + //DBGINV(F("hmInverter.h:doCalculations")); for(uint8_t i = 0; i < listLen; i++) { if(CMD_CALC == assign[i].div) { record[i] = calcFunctions[assign[i].start].func(this, assign[i].num); @@ -164,14 +154,12 @@ class Inverter { } bool isAvailable(uint32_t timestamp) { -#ifdef DEBUG_HMINVERTER - //DPRINTLN(F("hmInverter.h:isAvailable")); -#endif + //DBGINV(F("hmInverter.h:isAvailable")); return ((timestamp - ts) < INACT_THRES_SEC); } bool isProducing(uint32_t timestamp) { - //DPRINTLN(F("hmInverter.h:isProducing")); + //DBGINV(F("hmInverter.h:isProducing")); if(isAvailable(timestamp)) { uint8_t pos = getPosByChFld(CH0, FLD_PAC); return (getValue(pos) > INACT_PWR_THRESH); @@ -180,17 +168,13 @@ class Inverter { } uint32_t getLastTs(void) { -#ifdef DEBUG_HMINVERTER - //DPRINTLN(F("hmInverter.h:getLastTs")); -#endif + //DBGINV(F("hmInverter.h:getLastTs")); return ts; } private: void toRadioId(void) { -#ifdef DEBUG_HMINVERTER - //DPRINTLN(F("hmInverter.h:toRadioId")); -#endif + //DBGINV(F("hmInverter.h:toRadioId")); radioId.u64 = 0ULL; radioId.b[4] = serial.b[0]; radioId.b[3] = serial.b[1]; @@ -200,9 +184,7 @@ class Inverter { } void getAssignment(void) { -#ifdef DEBUG_HMINVERTER - //DPRINTLN(F("hmInverter.h:getAssignment")); -#endif + //DBGINV(F("hmInverter.h:getAssignment")); if(INV_TYPE_1CH == type) { listLen = (uint8_t)(HM1CH_LIST_LEN); assign = (byteAssign_t*)hm1chAssignment; @@ -235,9 +217,7 @@ class Inverter { template static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) { -#ifdef DEBUG_HMINVERTER - //DPRINTLN(F("hmInverter.h:calcYieldTotalCh0")); -#endif + //DBGINV(F("hmInverter.h:calcYieldTotalCh0")); if(NULL != iv) { T yield = 0; for(uint8_t i = 1; i <= iv->channels; i++) { @@ -251,9 +231,7 @@ static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) { template static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) { -#ifdef DEBUG_HMINVERTER - //DPRINTLN(F("hmInverter.h:calcYieldDayCh0")); -#endif + //DBGINV(F("hmInverter.h:calcYieldDayCh0")); if(NULL != iv) { T yield = 0; for(uint8_t i = 1; i <= iv->channels; i++) { @@ -267,9 +245,7 @@ static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) { template static T calcUdcCh(Inverter<> *iv, uint8_t arg0) { -#ifdef DEBUG_HMINVERTER - //DPRINTLN(F("hmInverter.h:calcUdcCh")); -#endif + //DBGINV(F("hmInverter.h:calcUdcCh")); // arg0 = channel of source for(uint8_t i = 0; i < iv->listLen; i++) { if((FLD_UDC == iv->assign[i].fieldId) && (arg0 == iv->assign[i].ch)) { @@ -282,9 +258,7 @@ static T calcUdcCh(Inverter<> *iv, uint8_t arg0) { template static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) { -#ifdef DEBUG_HMINVERTER - //DPRINTLN(F("hmInverter.h:calcPowerDcCh0")); -#endif + //DBGINV(F("hmInverter.h:calcPowerDcCh0")); if(NULL != iv) { T dcPower = 0; for(uint8_t i = 1; i <= iv->channels; i++) { @@ -298,9 +272,7 @@ static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) { template static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) { -#ifdef DEBUG_HMINVERTER - //DPRINTLN(F("hmInverter.h:calcEfficiencyCh0")); -#endif + //DBGINV(F("hmInverter.h:calcEfficiencyCh0")); if(NULL != iv) { uint8_t pos = iv->getPosByChFld(CH0, FLD_PAC); T acPower = iv->getValue(pos); @@ -317,9 +289,7 @@ static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) { template static T calcIrradiation(Inverter<> *iv, uint8_t arg0) { -#ifdef DEBUG_HMINVERTER - //DPRINTLN(F("hmInverter.h:calcIrradiation")); -#endif + //DBGINV(F("hmInverter.h:calcIrradiation")); // arg0 = channel if(NULL != iv) { uint8_t pos = iv->getPosByChFld(arg0, FLD_PDC); diff --git a/tools/esp8266/hmRadio.h b/tools/esp8266/hmRadio.h index 1dc71394..f317df7f 100644 --- a/tools/esp8266/hmRadio.h +++ b/tools/esp8266/hmRadio.h @@ -17,6 +17,12 @@ #define RX_LOOP_CNT 300 +#ifdef DEBUG_HMRADIO +#define DBGHMR(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0) +#else +#define DBGHMR(x...) do { (void)0; } while (0) +#endif + const char* const rf24AmpPower[] = {"MIN", "LOW", "HIGH", "MAX"}; @@ -49,9 +55,7 @@ template > 8)); @@ -201,9 +195,7 @@ class HmRadio { } bool checkPaketCrc(uint8_t buf[], uint8_t *len, uint8_t rxCh) { -#ifdef DEBUG_HMRADIO - //DPRINTLN(F("hmRadio.h:checkPaketCrc")); -#endif + //DBGHMR(F("hmRadio.h:checkPaketCrc")); *len = (buf[0] >> 2); if(*len > (MAX_RF_PAYLOAD_SIZE - 2)) *len = MAX_RF_PAYLOAD_SIZE - 2; @@ -218,10 +210,8 @@ class HmRadio { } bool switchRxCh(uint16_t addLoop = 0) { -#ifdef DEBUG_HMRADIO - //DPRINTLN(F("hmRadio.h:switchRxCh")); - //DPRINT(F("R")); -#endif + //DBGHMR(F("hmRadio.h:switchRxCh")); + //DBGHMR(F("R")); mRxLoopCnt += addLoop; if(mRxLoopCnt != 0) { @@ -236,9 +226,7 @@ class HmRadio { } void dumpBuf(const char *info, uint8_t buf[], uint8_t len) { -#ifdef DEBUG_HMRADIO - //DPRINTLN(F("hmRadio.h:dumpBuf")); -#endif + //DBGHMR(F("hmRadio.h:dumpBuf")); if(NULL != info) DPRINT(String(info)); for(uint8_t i = 0; i < len; i++) { @@ -249,9 +237,7 @@ class HmRadio { } bool isChipConnected(void) { -#ifdef DEBUG_HMRADIO - //DPRINTLN(F("hmRadio.h:isChipConnected")); -#endif + //DBGHMR(F("hmRadio.h:isChipConnected")); return mNrf24.isChipConnected(); } @@ -266,11 +252,9 @@ class HmRadio { private: void sendPacket(uint64_t invId, uint8_t buf[], uint8_t len, bool clear=false) { -#ifdef DEBUG_HMRADIO - //DPRINTLN(F("hmRadio.h:sendPacket")); - //DPRINTLN("sent packet: #" + String(mSendCnt)); + //DBGHMR(F("hmRadio.h:sendPacket")); + //DBGHMR("sent packet: #" + String(mSendCnt)); //dumpBuf("SEN ", buf, len); -#endif if(mSerialDebug) { DPRINT("Transmit " + String(len) + " | "); dumpBuf(NULL, buf, len); diff --git a/tools/esp8266/hmSystem.h b/tools/esp8266/hmSystem.h index 301d1b40..417e815f 100644 --- a/tools/esp8266/hmSystem.h +++ b/tools/esp8266/hmSystem.h @@ -6,7 +6,11 @@ #include "hmRadio.h" #endif - +#ifdef DEBUG_HMSYSTEM +#define DBGHMS(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0) +#else +#define DBGHMS(x...) do { (void)0; } while (0) +#endif template > class HmSystem { @@ -24,16 +28,12 @@ class HmSystem { } void setup() { -#ifdef DEBUG_HMSYSTEM - DPRINTLN(F("hmSystem.h:setup")); -#endif + DBGHMS(F("hmSystem.h:setup")); Radio.setup(&BufCtrl); } INVERTERTYPE *addInverter(const char *name, uint64_t serial, uint16_t chMaxPwr[]) { -#ifdef DEBUG_HMSYSTEM - DPRINTLN(F("hmSystem.h:addInverter")); -#endif + DBGHMS(F("hmSystem.h:addInverter")); if(MAX_INVERTER <= mNumInv) { DPRINT(F("max number of inverters reached!")); return NULL; @@ -70,9 +70,7 @@ class HmSystem { } INVERTERTYPE *findInverter(uint8_t buf[]) { -#ifdef DEBUG_HMSYSTEM - //DPRINTLN(F("hmSystem.h:findInverter")); -#endif + //DBGHMS(F("hmSystem.h:findInverter")); INVERTERTYPE *p; for(uint8_t i = 0; i < mNumInv; i++) { p = &mInverter[i]; @@ -86,9 +84,7 @@ class HmSystem { } INVERTERTYPE *getInverterByPos(uint8_t pos) { -#ifdef DEBUG_HMSYSTEM - //DPRINTLN(F("hmSystem.h:getInverterByPos")); -#endif + //DBGHMS(F("hmSystem.h:getInverterByPos")); if(mInverter[pos].serial.u64 != 0ULL) return &mInverter[pos]; else @@ -96,9 +92,7 @@ class HmSystem { } uint8_t getNumInverters(void) { -#ifdef DEBUG_HMSYSTEM - //DPRINTLN(F("hmSystem.h:getNumInverters")); -#endif + //DBGHMS(F("hmSystem.h:getNumInverters")); return mNumInv; } diff --git a/tools/esp8266/main.cpp b/tools/esp8266/main.cpp index 8c9ce420..bda1ef50 100644 --- a/tools/esp8266/main.cpp +++ b/tools/esp8266/main.cpp @@ -26,9 +26,7 @@ Main::Main(void) { mEep = new eep(); Serial.begin(115200); -#ifdef DEBUG_HMMAIN - DPRINTLN(F("Main::Main")); -#endif + DBGMAIN(F("Main::Main")); mUptimeSecs = 0; mUptimeTicker = 0xffffffff; @@ -42,9 +40,7 @@ Main::Main(void) { //----------------------------------------------------------------------------- void Main::setup(uint32_t timeout) { -#ifdef DEBUG_HMMAIN - DPRINTLN(F("Main::setup")); -#endif + DBGMAIN(F("Main::setup")); bool startAp = mApActive; mLimit = timeout; @@ -73,9 +69,7 @@ void Main::setup(uint32_t timeout) { //----------------------------------------------------------------------------- void Main::loop(void) { -#ifdef DEBUG_HMMAIN - //DPRINT(F("M")); -#endif + //DBGMAIN(F("M")); if(mApActive) { mDns->processNextRequest(); #ifndef AP_ONLY @@ -124,9 +118,7 @@ void Main::loop(void) { //----------------------------------------------------------------------------- bool Main::getConfig(void) { -#ifdef DEBUG_HMMAIN - DPRINTLN(F("Main::getConfig")); -#endif + DBGMAIN(F("Main::getConfig")); bool mApActive = false; mWifiSettingsValid = checkEEpCrc(ADDR_START, ADDR_WIFI_CRC, ADDR_WIFI_CRC); @@ -149,9 +141,7 @@ bool Main::getConfig(void) { //----------------------------------------------------------------------------- void Main::setupAp(const char *ssid, const char *pwd) { -#ifdef DEBUG_HMMAIN - DPRINTLN(F("Main::setupAp")); -#endif + DBGMAIN(F("Main::setupAp")); IPAddress apIp(192, 168, 1, 1); DPRINTLN(F("\n---------\nAP MODE\nSSDI: ") @@ -159,9 +149,7 @@ void Main::setupAp(const char *ssid, const char *pwd) { + String(pwd) + F("\nActive for: ") + String(WIFI_AP_ACTIVE_TIME) + F(" seconds") + F("\n---------\n")); -#ifdef DEBUG_HMMAIN - DPRINTLN("DBG: " + String(mNextTryTs)); -#endif + DBGMAIN("DBG: " + String(mNextTryTs)); WiFi.mode(WIFI_AP); WiFi.softAPConfig(apIp, apIp, IPAddress(255, 255, 255, 0)); @@ -180,9 +168,7 @@ void Main::setupAp(const char *ssid, const char *pwd) { //----------------------------------------------------------------------------- bool Main::setupStation(uint32_t timeout) { -#ifdef DEBUG_HMMAIN - DPRINTLN(F("Main::setupStation")); -#endif + DBGMAIN(F("Main::setupStation")); int32_t cnt; bool startAp = false; @@ -232,9 +218,7 @@ bool Main::setupStation(uint32_t timeout) { //----------------------------------------------------------------------------- void Main::showSetup(void) { -#ifdef DEBUG_HMMAIN - DPRINTLN(F("Main::showSetup")); -#endif + DBGMAIN(F("Main::showSetup")); String html = FPSTR(setup_html); html.replace(F("{SSID}"), mStationSsid); // PWD will be left at the default value (for protection) @@ -252,9 +236,7 @@ void Main::showSetup(void) { //----------------------------------------------------------------------------- void Main::showCss(void) { -#ifdef DEBUG_HMMAIN - DPRINTLN(F("Main::showCss")); -#endif + DBGMAIN(F("Main::showCss")); mWeb->send(200, "text/css", FPSTR(style_css)); } @@ -270,9 +252,7 @@ void Main::showSave(void) { //----------------------------------------------------------------------------- void Main::saveValues(bool webSend = true) { -#ifdef DEBUG_HMMAIN - DPRINTLN(F("Main::saveValues")); -#endif + DBGMAIN(F("Main::saveValues")); if(mWeb->args() > 0) { if(mWeb->arg("ssid") != "") { memset(mStationSsid, 0, SSID_LEN); @@ -306,9 +286,7 @@ void Main::saveValues(bool webSend = true) { //----------------------------------------------------------------------------- void Main::updateCrc(void) { -#ifdef DEBUG_HMMAIN - DPRINTLN(F("Main::updateCrc")); -#endif + DBGMAIN(F("Main::updateCrc")); uint16_t crc; crc = buildEEpCrc(ADDR_START, ADDR_WIFI_CRC); //Serial.println("new CRC: " + String(crc, HEX)); @@ -319,9 +297,7 @@ void Main::updateCrc(void) { //----------------------------------------------------------------------------- void Main::showUptime(void) { -#ifdef DEBUG_HMMAIN - //DPRINTLN(F("Main::showUptime")); -#endif + //DBGMAIN(F("Main::showUptime")); char time[20] = {0}; int upTimeSc = uint32_t((mUptimeSecs) % 60); @@ -337,18 +313,14 @@ void Main::showUptime(void) { //----------------------------------------------------------------------------- void Main::showTime(void) { -#ifdef DEBUG_HMMAIN - //DPRINTLN(F("Main::showTime")); -#endif + //DBGMAIN(F("Main::showTime")); mWeb->send(200, "text/plain", getDateTimeStr(mTimestamp)); } //----------------------------------------------------------------------------- void Main::showNotFound(void) { -#ifdef DEBUG_HMMAIN - DPRINTLN(F("Main::showNotFound - ") + mWeb->uri()); -#endif + DBGMAIN(F("Main::showNotFound - ") + mWeb->uri()); String msg = F("File Not Found\n\nURI: "); msg += mWeb->uri(); msg += F("\nMethod: "); @@ -367,9 +339,7 @@ void Main::showNotFound(void) { //----------------------------------------------------------------------------- void Main::showReboot(void) { -#ifdef DEBUG_HMMAIN - DPRINTLN(F("Main::showReboot")); -#endif + DBGMAIN(F("Main::showReboot")); mWeb->send(200, F("text/html"), F("Rebooting ...rebooting ... auto reload after 10s")); delay(1000); ESP.restart(); @@ -379,9 +349,7 @@ void Main::showReboot(void) { //----------------------------------------------------------------------------- void Main::showFactoryRst(void) { -#ifdef DEBUG_HMMAIN - DPRINTLN(F("Main::showFactoryRst")); -#endif + DBGMAIN(F("Main::showFactoryRst")); String content = ""; int refresh = 3; if(mWeb->args() > 0) { @@ -410,9 +378,7 @@ void Main::showFactoryRst(void) { //----------------------------------------------------------------------------- time_t Main::getNtpTime(void) { -#ifdef DEBUG_HMMAIN - //DPRINTLN(F("Main::getNtpTime")); -#endif + //DBGMAIN(F("Main::getNtpTime")); time_t date = 0; IPAddress timeServer; uint8_t buf[NTP_PACKET_SIZE]; @@ -450,9 +416,7 @@ time_t Main::getNtpTime(void) { //----------------------------------------------------------------------------- void Main::sendNTPpacket(IPAddress& address) { -#ifdef DEBUG_HMMAIN - //DPRINTLN(F("Main::sendNTPpacket")); -#endif + //DBGMAIN(F("Main::sendNTPpacket")); uint8_t buf[NTP_PACKET_SIZE] = {0}; buf[0] = B11100011; // LI, Version, Mode @@ -473,9 +437,7 @@ void Main::sendNTPpacket(IPAddress& address) { //----------------------------------------------------------------------------- String Main::getDateTimeStr(time_t t) { -#ifdef DEBUG_HMMAIN - //DPRINTLN(F("Main::getDateTimeStr")); -#endif + //DBGMAIN(F("Main::getDateTimeStr")); char str[20] = {0}; if(0 == t) sprintf(str, "n/a"); @@ -489,9 +451,7 @@ String Main::getDateTimeStr(time_t t) { // calculates the daylight saving time for middle Europe. Input: Unixtime in UTC // from: https://forum.arduino.cc/index.php?topic=172044.msg1278536#msg1278536 time_t Main::offsetDayLightSaving (uint32_t local_t) { -#ifdef DEBUG_HMMAIN - //DPRINTLN(F("Main::offsetDayLightSaving")); -#endif + //DBGMAIN(F("Main::offsetDayLightSaving")); int m = month (local_t); if(m < 3 || m > 10) return 0; // no DSL in Jan, Feb, Nov, Dez if(m > 3 && m < 10) return 1; // DSL in Apr, May, Jun, Jul, Aug, Sep diff --git a/tools/esp8266/main.h b/tools/esp8266/main.h index d642c7ca..341496de 100644 --- a/tools/esp8266/main.h +++ b/tools/esp8266/main.h @@ -18,6 +18,11 @@ #include "crc.h" #include "debug.h" +#ifdef DEBUG_HMMAIN +#define DBGMAIN(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0) +#else +#define DBGMAIN(x...) do { (void)0; } while (0) +#endif const byte mDnsPort = 53; @@ -41,9 +46,7 @@ class Main { virtual void updateCrc(void); inline uint16_t buildEEpCrc(uint32_t start, uint32_t length) { -#ifdef DEBUG_HMMAIN - DPRINTLN(F("main.h:buildEEpCrc")); -#endif + DBGMAIN(F("main.h:buildEEpCrc")); uint8_t buf[32]; uint16_t crc = 0xffff; uint8_t len; @@ -59,22 +62,16 @@ class Main { } bool checkEEpCrc(uint32_t start, uint32_t length, uint32_t crcPos) { -#ifdef DEBUG_HMMAIN - //DPRINTLN(F("main.h:checkEEpCrc")); -#endif + //DBGMAIN(F("main.h:checkEEpCrc")); uint16_t crcRd, crcCheck; crcCheck = buildEEpCrc(start, length); mEep->read(crcPos, &crcRd); -#ifdef DEBUG_HMMAIN - //DPRINTLN("CRC RD: " + String(crcRd, HEX) + " CRC CALC: " + String(crcCheck, HEX)); -#endif + //DBGMAIN("CRC RD: " + String(crcRd, HEX) + " CRC CALC: " + String(crcCheck, HEX)); return (crcCheck == crcRd); } void eraseSettings(bool all = false) { -#ifdef DEBUG_HMMAIN - //DPRINTLN(F("main.h:eraseSettings")); -#endif + //DBGMAIN(F("main.h:eraseSettings")); uint8_t buf[64] = {0}; uint16_t addr = (all) ? ADDR_START : ADDR_START_SETTINGS; uint16_t end; @@ -90,9 +87,7 @@ class Main { } inline bool checkTicker(uint32_t *ticker, uint32_t interval) { -#ifdef DEBUG_HMMAIN - //DPRINT(F("c")); -#endif + //DBGMAIN(F("c")); uint32_t mil = millis(); if(mil >= *ticker) { *ticker = mil + interval; @@ -107,9 +102,7 @@ class Main { } void stats(void) { -#ifdef DEBUG_HMMAIN - DPRINTLN(F("main.h:stats")); -#endif + DBGMAIN(F("main.h:stats")); uint32_t free; uint16_t max; uint8_t frag;