From 643635bee1ce1b621ca5258f5ccf59ea5e9e38bc Mon Sep 17 00:00:00 2001 From: geronet1 Date: Mon, 22 Jan 2024 11:06:48 +0100 Subject: [PATCH 1/5] ETH NTP update bugfix --- src/app.cpp | 29 ++++++++++++++++++----------- src/app.h | 1 + 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index feeffc57..53b004c0 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -172,7 +172,6 @@ void app::onNetwork(bool gotIp) { mMqttReconnect = true; mSunrise = 0; // needs to be set to 0, to reinstall sunrise and ivComm tickers! once(std::bind(&app::tickNtpUpdate, this), 2, "ntp2"); - //tickNtpUpdate(); #if !defined(ETHERNET) if (WIFI_AP == WiFi.getMode()) { mMqttEnabled = false; @@ -206,12 +205,7 @@ void app::regularTickers(void) { #if defined(ETHERNET) void app::onNtpUpdate(bool gotTime) { - uint32_t nxtTrig = 5; // default: check again in 5 sec - if (gotTime || mTimestamp != 0) { - this->updateNtp(); - nxtTrig = gotTime ? 43200 : 60; // depending on NTP update success check again in 12 h or in 1 min - } - once(std::bind(&app::tickNtpUpdate, this), nxtTrig, "ntp"); + mNtpReceived = true; } #endif /* defined(ETHERNET) */ @@ -255,13 +249,22 @@ void app::updateNtp(void) { //----------------------------------------------------------------------------- void app::tickNtpUpdate(void) { uint32_t nxtTrig = 5; // default: check again in 5 sec + bool isOK = false; + #if defined(ETHERNET) - bool isOK = (mTimestamp != 0); - mEth.updateNtpTime(); + if (!mNtpReceived) + { + mEth.updateNtpTime(); + } + else + { + mNtpReceived = false; + isOK = true; + } #else - bool isOK = mWifi.getNtpTime(); + isOK = mWifi.getNtpTime(); #endif - if (isOK || mTimestamp != 0) { + if (isOK) { this->updateNtp(); nxtTrig = isOK ? (mConfig->ntp.interval * 60) : 60; // depending on NTP update success check again in 12h (depends on setting) or in 1 min @@ -565,6 +568,10 @@ void app::resetSystem(void) { mSaveReboot = false; mNetworkConnected = false; + +#if defined(ETHERNET) + mNtpReceived = false; +#endif } //----------------------------------------------------------------------------- diff --git a/src/app.h b/src/app.h index 7922edfb..94140eff 100644 --- a/src/app.h +++ b/src/app.h @@ -351,6 +351,7 @@ class app : public IApp, public ah::Scheduler { void tickNtpUpdate(void); #if defined(ETHERNET) void onNtpUpdate(bool gotTime); + bool mNtpReceived; #endif /* defined(ETHERNET) */ void updateNtp(void); From 66117e545bc4a1428ac218d9f9eeda03ec02272f Mon Sep 17 00:00:00 2001 From: lumapu Date: Mon, 22 Jan 2024 22:52:42 +0100 Subject: [PATCH 2/5] 0.8.64 * add `ARC` to log (NRF24 Debug) --- src/CHANGES.md | 3 +++ src/defines.h | 3 ++- src/hm/Communication.h | 4 ++++ src/hm/hmRadio.h | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/CHANGES.md b/src/CHANGES.md index a20c20be..ca376d8d 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -1,5 +1,8 @@ # Development Changes +## 0.8.64 - 2024-01-22 +* add `ARC` to log (NRF24 Debug) + ## 0.8.63 - 2024-01-22 * made code review * fixed endless loop #1387 diff --git a/src/defines.h b/src/defines.h index 77ea6726..81319b29 100644 --- a/src/defines.h +++ b/src/defines.h @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 8 -#define VERSION_PATCH 63 +#define VERSION_PATCH 64 //------------------------------------- typedef struct { @@ -22,6 +22,7 @@ typedef struct { int8_t rssi; uint8_t packet[MAX_RF_PAYLOAD_SIZE]; uint16_t millis; + uint8_t arc; } packet_t; typedef enum { diff --git a/src/hm/Communication.h b/src/hm/Communication.h index 80b43ab3..e55d60f6 100644 --- a/src/hm/Communication.h +++ b/src/hm/Communication.h @@ -284,6 +284,9 @@ class Communication : public CommQueue<> { DBGPRINT(String(p->millis)); DBGPRINT(F("ms | ")); DBGPRINT(String(p->len)); + DBGPRINT(F(", ARC ")); + DBGPRINT(String(p->arc)); + DBGPRINT(F(" |")); if(INV_RADIO_TYPE_NRF == q->iv->ivRadioType) { DBGPRINT(F(" CH")); if(3 == p->ch) @@ -500,6 +503,7 @@ class Communication : public CommQueue<> { int8_t rssi = -127; uint8_t len = 0; + DPRINT_IVID(DBG_INFO, q->iv->id); for(uint8_t i = 0; i < mMaxFrameId; i++) { if(mLocalBuf[i].len + len > MAX_BUFFER) { DPRINTLN(DBG_ERROR, F("payload buffer to small!")); diff --git a/src/hm/hmRadio.h b/src/hm/hmRadio.h index 67b1abcd..d5e208b8 100644 --- a/src/hm/hmRadio.h +++ b/src/hm/hmRadio.h @@ -307,6 +307,7 @@ class HmRadio : public Radio { p.len = (len > MAX_RF_PAYLOAD_SIZE) ? MAX_RF_PAYLOAD_SIZE : len; p.rssi = mNrf24->testRPD() ? -64 : -75; p.millis = millis() - mMillis; + p.arc = mNrf24->getARC(); mNrf24->read(p.packet, p.len); if (p.packet[0] != 0x00) { From 8c2b37ed9e720e4cd922d4defd8abefba968ddcd Mon Sep 17 00:00:00 2001 From: lumapu Date: Mon, 22 Jan 2024 23:04:18 +0100 Subject: [PATCH 3/5] 0.8.64 add ARC to timeout --- src/hm/Communication.h | 9 +++++++-- src/hm/hmRadio.h | 4 ++++ src/hm/radio.h | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/hm/Communication.h b/src/hm/Communication.h index e55d60f6..ca76cc04 100644 --- a/src/hm/Communication.h +++ b/src/hm/Communication.h @@ -134,10 +134,15 @@ class Communication : public CommQueue<> { DPRINT_IVID(DBG_INFO, q->iv->id); DBGPRINT(F("request timeout: ")); DBGPRINT(String(q->iv->radio->mRadioWaitTime.getRunTime())); - DBGPRINTLN(F("ms")); + DBGPRINT(F("ms")); + if(INV_RADIO_TYPE_NRF == q->iv->ivRadioType) { + DBGPRINT(F(", ARC ")); + DBGPRINTLN(String(q->iv->radio->getARC())); + } else + DBGPRINTLN(""); } if(!q->iv->mGotFragment) { - if(q->iv->ivRadioType == INV_RADIO_TYPE_CMT) { + if(INV_RADIO_TYPE_CMT == q->iv->ivRadioType) { q->iv->radio->switchFrequency(q->iv, HOY_BOOT_FREQ_KHZ, (q->iv->config->frequency*FREQ_STEP_KHZ + HOY_BASE_FREQ_KHZ)); mWaitTime.startTimeMonitor(1000); } else { diff --git a/src/hm/hmRadio.h b/src/hm/hmRadio.h index d5e208b8..774a99a1 100644 --- a/src/hm/hmRadio.h +++ b/src/hm/hmRadio.h @@ -293,6 +293,10 @@ class HmRadio : public Radio { return mNrf24->isPVariant(); } + uint8_t getARC(void) { + return mNrf24->getARC(); + } + private: inline bool getReceived(void) { bool isLastPackage = false; diff --git a/src/hm/radio.h b/src/hm/radio.h index 09bd9134..9cb14000 100644 --- a/src/hm/radio.h +++ b/src/hm/radio.h @@ -29,6 +29,7 @@ class Radio { virtual bool switchFrequencyCh(Inverter<> *iv, uint8_t fromCh, uint8_t toCh) { return true; } virtual bool isChipConnected(void) { return false; } virtual bool loop(void) = 0; + virtual uint8_t getARC(void) { return 0xff; } void handleIntr(void) { mIrqRcvd = true; From 92a9e161b2d914f939f59f56e7e7707565c5441c Mon Sep 17 00:00:00 2001 From: lumapu Date: Mon, 22 Jan 2024 23:08:47 +0100 Subject: [PATCH 4/5] 0.8.64 * merge PR: ETH NTP update bugfix #1385 --- src/CHANGES.md | 1 + src/app.cpp | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/CHANGES.md b/src/CHANGES.md index ca376d8d..a4942d55 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -2,6 +2,7 @@ ## 0.8.64 - 2024-01-22 * add `ARC` to log (NRF24 Debug) +* merge PR: ETH NTP update bugfix #1385 ## 0.8.63 - 2024-01-22 * made code review diff --git a/src/app.cpp b/src/app.cpp index 1225ca90..9f569259 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -251,11 +251,8 @@ void app::tickNtpUpdate(void) { #if defined(ETHERNET) if (!mNtpReceived) - { mEth.updateNtpTime(); - } - else - { + else { mNtpReceived = false; isOK = true; } From 7f386f07df602e71d0d66ed7e0ddc51c4630aa05 Mon Sep 17 00:00:00 2001 From: lumapu Date: Mon, 22 Jan 2024 23:47:22 +0100 Subject: [PATCH 5/5] 0.8.64 add `getPLOS` (NRF24 Debug) --- patches/RF24.patch | 35 +++++++++++++++++++++++++++++++++++ patches/RF24_Hal.patch | 28 ++++++++++++++++++++++++---- scripts/applyPatches.py | 2 ++ src/defines.h | 1 + src/hm/Communication.h | 6 +++++- src/hm/hmRadio.h | 5 +++++ src/hm/radio.h | 1 + src/platformio.ini | 9 ++++++--- 8 files changed, 79 insertions(+), 8 deletions(-) create mode 100644 patches/RF24.patch diff --git a/patches/RF24.patch b/patches/RF24.patch new file mode 100644 index 00000000..63db8823 --- /dev/null +++ b/patches/RF24.patch @@ -0,0 +1,35 @@ +diff --git a/RF24.cpp b/RF24.cpp +index 9e5b4a8..a4de63c 100644 +--- a/RF24.cpp ++++ b/RF24.cpp +@@ -1871,6 +1871,11 @@ uint8_t RF24::getARC(void) + return read_register(OBSERVE_TX) & 0x0F; + } + ++uint8_t RF24::getPLOS(void) ++{ ++ return read_register(OBSERVE_TX) & 0x0F; ++} ++ + /****************************************************************************/ + + bool RF24::setDataRate(rf24_datarate_e speed) +diff --git a/RF24.h b/RF24.h +index dbd32ae..a3d6b52 100644 +--- a/RF24.h ++++ b/RF24.h +@@ -1644,6 +1644,7 @@ public: + * @return Returns values from 0 to 15. + */ + uint8_t getARC(void); ++ uint8_t getPLOS(void); + + /** + * Set the transmission @ref Datarate +@@ -2415,4 +2416,4 @@ private: + * Use `ctrl+c` to quit at any time. + */ + +-#endif // __RF24_H__ +\ No newline at end of file ++#endif // __RF24_H__ diff --git a/patches/RF24_Hal.patch b/patches/RF24_Hal.patch index 1a4f159e..88a53bf9 100644 --- a/patches/RF24_Hal.patch +++ b/patches/RF24_Hal.patch @@ -1,5 +1,5 @@ diff --git a/RF24.cpp b/RF24.cpp -index c0cc732..b6708d9 100644 +index 9e5b4a8..af00758 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -12,228 +12,24 @@ @@ -727,7 +727,7 @@ index c0cc732..b6708d9 100644 } /****************************************************************************/ -@@ -1676,15 +1136,8 @@ void RF24::closeReadingPipe(uint8_t pipe) +@@ -1675,15 +1135,8 @@ void RF24::closeReadingPipe(uint8_t pipe) void RF24::toggle_features(void) { @@ -745,8 +745,20 @@ index c0cc732..b6708d9 100644 } /****************************************************************************/ +@@ -1871,6 +1324,11 @@ uint8_t RF24::getARC(void) + return read_register(OBSERVE_TX) & 0x0F; + } + ++uint8_t RF24::getPLOS(void) ++{ ++ return (read_register(OBSERVE_TX) >> 4) & 0x0F; ++} ++ + /****************************************************************************/ + + bool RF24::setDataRate(rf24_datarate_e speed) diff --git a/RF24.h b/RF24.h -index dbd32ae..f774bba 100644 +index dbd32ae..74ae35d 100644 --- a/RF24.h +++ b/RF24.h @@ -16,12 +16,7 @@ @@ -932,7 +944,15 @@ index dbd32ae..f774bba 100644 */ void encodeRadioDetails(uint8_t* encoded_status); -@@ -1896,18 +1800,6 @@ private: +@@ -1644,6 +1548,7 @@ public: + * @return Returns values from 0 to 15. + */ + uint8_t getARC(void); ++ uint8_t getPLOS(void); + + /** + * Set the transmission @ref Datarate +@@ -1896,18 +1801,6 @@ private: */ bool _init_pins(); diff --git a/scripts/applyPatches.py b/scripts/applyPatches.py index 3ba30a5f..3289badb 100644 --- a/scripts/applyPatches.py +++ b/scripts/applyPatches.py @@ -32,3 +32,5 @@ if env['PIOENV'][:22] != "opendtufusion-ethernet": if env['PIOENV'][:13] == "opendtufusion": applyPatch("GxEPD2", "../patches/GxEPD2_SW_SPI.patch") applyPatch("RF24", "../patches/RF24_Hal.patch") +else: + applyPatch("RF24", "../patches/RF24.patch") diff --git a/src/defines.h b/src/defines.h index 81319b29..b8ddace9 100644 --- a/src/defines.h +++ b/src/defines.h @@ -23,6 +23,7 @@ typedef struct { uint8_t packet[MAX_RF_PAYLOAD_SIZE]; uint16_t millis; uint8_t arc; + uint8_t plos; } packet_t; typedef enum { diff --git a/src/hm/Communication.h b/src/hm/Communication.h index ca76cc04..98dd06e1 100644 --- a/src/hm/Communication.h +++ b/src/hm/Communication.h @@ -137,7 +137,9 @@ class Communication : public CommQueue<> { DBGPRINT(F("ms")); if(INV_RADIO_TYPE_NRF == q->iv->ivRadioType) { DBGPRINT(F(", ARC ")); - DBGPRINTLN(String(q->iv->radio->getARC())); + DBGPRINT(String(q->iv->radio->getARC())); + DBGPRINT(F(", PLOS ")); + DBGPRINTLN(String(q->iv->radio->getPLOS())); } else DBGPRINTLN(""); } @@ -291,6 +293,8 @@ class Communication : public CommQueue<> { DBGPRINT(String(p->len)); DBGPRINT(F(", ARC ")); DBGPRINT(String(p->arc)); + DBGPRINT(F(", PLOS ")); + DBGPRINT(String(p->plos)); DBGPRINT(F(" |")); if(INV_RADIO_TYPE_NRF == q->iv->ivRadioType) { DBGPRINT(F(" CH")); diff --git a/src/hm/hmRadio.h b/src/hm/hmRadio.h index 774a99a1..ef37e266 100644 --- a/src/hm/hmRadio.h +++ b/src/hm/hmRadio.h @@ -297,6 +297,10 @@ class HmRadio : public Radio { return mNrf24->getARC(); } + uint8_t getPLOS(void) { + return mNrf24->getPLOS(); + } + private: inline bool getReceived(void) { bool isLastPackage = false; @@ -312,6 +316,7 @@ class HmRadio : public Radio { p.rssi = mNrf24->testRPD() ? -64 : -75; p.millis = millis() - mMillis; p.arc = mNrf24->getARC(); + p.plos = mNrf24->getPLOS(); mNrf24->read(p.packet, p.len); if (p.packet[0] != 0x00) { diff --git a/src/hm/radio.h b/src/hm/radio.h index 9cb14000..a71e24c7 100644 --- a/src/hm/radio.h +++ b/src/hm/radio.h @@ -30,6 +30,7 @@ class Radio { virtual bool isChipConnected(void) { return false; } virtual bool loop(void) = 0; virtual uint8_t getARC(void) { return 0xff; } + virtual uint8_t getPLOS(void) { return 0xff; } void handleIntr(void) { mIrqRcvd = true; diff --git a/src/platformio.ini b/src/platformio.ini index e8a1a68a..9b97e018 100644 --- a/src/platformio.ini +++ b/src/platformio.ini @@ -26,7 +26,7 @@ extra_scripts = lib_deps = https://github.com/yubox-node-org/ESPAsyncWebServer - nrf24/RF24 @ 1.4.8 + https://github.com/nRF24/RF24 @ 1.4.8 paulstoffregen/Time @ ^1.6.1 https://github.com/bertmelis/espMqttClient#v1.5.0 bblanchon/ArduinoJson @ ^6.21.3 @@ -195,7 +195,7 @@ board = esp32dev lib_deps = khoih-prog/AsyncWebServer_ESP32_W5500 khoih-prog/AsyncUDP_ESP32_W5500 - nrf24/RF24 @ ^1.4.8 + https://github.com/nRF24/RF24 @ ^1.4.8 paulstoffregen/Time @ ^1.6.1 https://github.com/bertmelis/espMqttClient#v1.5.0 bblanchon/ArduinoJson @ ^6.21.3 @@ -218,7 +218,7 @@ board = esp32dev lib_deps = khoih-prog/AsyncWebServer_ESP32_W5500 khoih-prog/AsyncUDP_ESP32_W5500 - nrf24/RF24 @ ^1.4.8 + https://github.com/nRF24/RF24 @ ^1.4.8 paulstoffregen/Time @ ^1.6.1 https://github.com/bertmelis/espMqttClient#v1.5.0 bblanchon/ArduinoJson @ ^6.21.3 @@ -334,6 +334,7 @@ build_flags = ${env.build_flags} -DENABLE_MQTT -DPLUGIN_DISPLAY -DENABLE_HISTORY + -DSPI_HAL -DDEF_NRF_CS_PIN=37 -DDEF_NRF_CE_PIN=38 -DDEF_NRF_IRQ_PIN=47 @@ -362,6 +363,7 @@ build_flags = ${env.build_flags} -DENABLE_MQTT -DPLUGIN_DISPLAY -DENABLE_HISTORY + -DSPI_HAL -DDEF_NRF_CS_PIN=37 -DDEF_NRF_CE_PIN=38 -DDEF_NRF_IRQ_PIN=47 @@ -385,6 +387,7 @@ platform = espressif32@6.5.0 board = esp32-s3-devkitc-1 upload_protocol = esp-builtin build_flags = ${env.build_flags} + -DSPI_HAL -DDEF_NRF_CS_PIN=37 -DDEF_NRF_CE_PIN=38 -DDEF_NRF_IRQ_PIN=47