From 4f46106228ef38d7f436a3a480b4bbdad78ca698 Mon Sep 17 00:00:00 2001 From: DanielR92 Date: Sat, 19 Nov 2022 20:15:54 +0100 Subject: [PATCH 1/2] Add NRF to system site + api --- src/.vscode/settings.json | 51 ++++++++++++++++++++++++++++++++++++++- src/app.cpp | 22 ++++++++++++----- src/hm/hmRadio.h | 16 +++++++++--- src/web/html/system.html | 24 ++++++++++++++++++ src/web/webApi.cpp | 10 ++++++++ 5 files changed, 112 insertions(+), 11 deletions(-) diff --git a/src/.vscode/settings.json b/src/.vscode/settings.json index 6af36bae..3b7ffafd 100644 --- a/src/.vscode/settings.json +++ b/src/.vscode/settings.json @@ -24,6 +24,55 @@ "typeinfo": "cpp", "string": "cpp", "istream": "cpp", - "ostream": "cpp" + "ostream": "cpp", + "array": "cpp", + "atomic": "cpp", + "*.tcc": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "list": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "map": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "regex": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "limits": "cpp", + "new": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp" }, } \ No newline at end of file diff --git a/src/app.cpp b/src/app.cpp index fcfee586..06fb3088 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -23,6 +23,7 @@ void app::setup(uint32_t timeout) { addListener(EVERY_12H, std::bind(&app::ntpUpdateTick, this)); resetSystem(); + mSettings.setup(); mSettings.getPtr(mConfig); DPRINTLN(DBG_INFO, F("Settings valid: ") + String((mSettings.getValid()) ? F("true") : F("false"))); @@ -33,19 +34,28 @@ void app::setup(uint32_t timeout) { mSys = new HmSystemType(); mSys->enableDebug(); mSys->setup(mConfig->nrf.amplifierPower, mConfig->nrf.pinIrq, mConfig->nrf.pinCe, mConfig->nrf.pinCs); - mSys->addInverters(&mConfig->inst); - mPayload.setup(mSys); - mPayload.enableSerialDebug(mConfig->serial.debug); -#if !defined(AP_ONLY) - if (mConfig->mqtt.broker[0] > 0) { + if(mSys->Radio.isChipConnected()) + { + mSys->addInverters(&mConfig->inst); + + mPayload.setup(mSys); + mPayload.enableSerialDebug(mConfig->serial.debug); + } + else + { + DPRINTLN(DBG_WARN, F("WARNING! your NRF24 module can't be reached, check the wiring")); + } + + // when WiFi is in client mode, then enable mqtt broker + if (mConfig->mqtt.broker[0] > 0 && WiFi.getMode() == WIFI_STA) { mMqtt.setup(&mConfig->mqtt, mConfig->sys.deviceName, mVersion, mSys, &mUtcTimestamp, &mSunrise, &mSunset); mPayload.addListener(std::bind(&PubMqttType::payloadEventListener, &mMqtt, std::placeholders::_1)); addListener(EVERY_SEC, std::bind(&PubMqttType::tickerSecond, &mMqtt)); addListener(EVERY_MIN, std::bind(&PubMqttType::tickerMinute, &mMqtt)); addListener(EVERY_HR, std::bind(&PubMqttType::tickerHour, &mMqtt)); } -#endif + setupLed(); mWeb = new web(this, mConfig, &mStat, mVersion); diff --git a/src/hm/hmRadio.h b/src/hm/hmRadio.h index 4e1b749c..9061174a 100644 --- a/src/hm/hmRadio.h +++ b/src/hm/hmRadio.h @@ -99,7 +99,7 @@ class HmRadio { DPRINTLN(DBG_VERBOSE, F("hmRadio.h:setup")); pinMode(irq, INPUT_PULLUP); mBufCtrl = ctrl; - + uint32_t dtuSn = 0x87654321; uint32_t chipID = 0; // will be filled with last 3 bytes of MAC @@ -191,7 +191,7 @@ class HmRadio { uint8_t setDefaultChannels(void) { //DPRINTLN(DBG_VERBOSE, F("hmRadio.h:setDefaultChannels")); mTxChIdx = 2; // Start TX with 40 - mRxChIdx = 0; // Start RX with 03 + mRxChIdx = 0; // Start RX with 03 return mRfChLst[mTxChIdx]; } @@ -212,7 +212,7 @@ class HmRadio { uint16_t crc = ah::crc16(&mTxBuf[10], cnt); mTxBuf[10 + cnt++] = (crc >> 8) & 0xff; mTxBuf[10 + cnt++] = (crc ) & 0xff; - + // crc over all mTxBuf[10 + cnt] = ah::crc8(mTxBuf, 10 + cnt); @@ -295,6 +295,14 @@ class HmRadio { return mNrf24.isChipConnected(); } + rf24_datarate_e getDataRate(void) { + return mNrf24.getDataRate(); + } + + bool isPVariant(void) { + return mNrf24.isPVariant(); + } + uint32_t mSendCnt; @@ -360,7 +368,7 @@ class HmRadio { uint8_t mTxChIdx; uint8_t mRfChLst[RF_CHANNELS]; - + uint8_t mRxChIdx; uint16_t mRxLoopCnt; diff --git a/src/web/html/system.html b/src/web/html/system.html index d8a473a2..c95d581a 100644 --- a/src/web/html/system.html +++ b/src/web/html/system.html @@ -19,6 +19,7 @@
    +
      @@ -59,11 +60,34 @@ } } + function parseRadio(obj) { + const pa = ["MIN", "LOW", "HIGH", "MAX"]; + const datarate = ["1 MBps", "2 MBps", "250 kbps"]; + + var ul = document.getElementById("radio"); + let data; + + var li = document.createElement("li"); + li.appendChild(document.createTextNode("nrf24l01" + (obj["isPVariant"] ? "+ " : "") + (obj["isconnected"] ? "is connected " : "is not connected "))); + ul.appendChild(li); + + if(obj["isconnected"]) { + var li = document.createElement("li"); + li.appendChild(document.createTextNode("Datarate: " + datarate[obj["DataRate"]])); + ul.appendChild(li); + + var li = document.createElement("li"); + li.appendChild(document.createTextNode("Power Level: " + pa[obj["power_level"]])); + ul.appendChild(li); + } + } + function parse(obj) { if(null != obj) { parseMenu(obj["menu"]); parseSys(obj["system"]); parseSysInfo(obj["system"]); + parseRadio(obj["system"]["radio"]); var e = document.getElementById("system"); e.innerHTML = obj["html"]; diff --git a/src/web/webApi.cpp b/src/web/webApi.cpp index e71aa511..a6b3b1d1 100644 --- a/src/web/webApi.cpp +++ b/src/web/webApi.cpp @@ -162,6 +162,9 @@ void webApi::getSysInfo(JsonObject obj) { obj[F("sketch_total")] = ESP.getFreeSketchSpace(); obj[F("sketch_used")] = ESP.getSketchSize() / 1024; // in kb + + getRadio(obj.createNestedObject(F("radio"))); + #if defined(ESP32) obj[F("heap_total")] = ESP.getHeapSize(); obj[F("chip_revision")] = ESP.getChipRevision(); @@ -306,6 +309,9 @@ void webApi::getPinout(JsonObject obj) { //----------------------------------------------------------------------------- void webApi::getRadio(JsonObject obj) { obj[F("power_level")] = mConfig->nrf.amplifierPower; + obj[F("isconnected")] = mApp->mSys->Radio.isChipConnected(); + obj[F("DataRate")] = mApp->mSys->Radio.getDataRate(); + obj[F("isPVariant")] = mApp->mSys->Radio.isPVariant(); } @@ -358,6 +364,7 @@ void webApi::getMenu(JsonObject obj) { void webApi::getIndex(JsonObject obj) { getMenu(obj.createNestedObject(F("menu"))); getSysInfo(obj.createNestedObject(F("system"))); + getRadio(obj.createNestedObject(F("radio"))); getStatistics(obj.createNestedObject(F("statistics"))); obj["refresh_interval"] = mConfig->nrf.sendInterval; @@ -380,6 +387,9 @@ void webApi::getIndex(JsonObject obj) { JsonArray warn = obj.createNestedArray(F("warnings")); if(!mApp->mSys->Radio.isChipConnected()) warn.add(F("your NRF24 module can't be reached, check the wiring and pinout")); + else if(!mApp->mSys->Radio.isPVariant()) + warn.add(F("your NRF24 module have not a plus(+), please check!")); + if(!mApp->mqttIsConnected()) warn.add(F("MQTT is not connected")); From e148f89d0cbfe486b4bdc4cc9b5b6ebaec5c1c3a Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Tue, 29 Nov 2022 08:31:15 +0100 Subject: [PATCH 2/2] RPI: fix sleep calculation by using the correct (utc) time --- tools/rpi/hoymiles/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/rpi/hoymiles/__main__.py b/tools/rpi/hoymiles/__main__.py index 18e3d95e..69bf1479 100644 --- a/tools/rpi/hoymiles/__main__.py +++ b/tools/rpi/hoymiles/__main__.py @@ -62,7 +62,7 @@ class SunsetHandler: tomorrow = now + timedelta(days=1) nextSunrise = self.suntimes.riseutc(tomorrow) self.nextSunset = self.suntimes.setutc(tomorrow) - time_to_sleep = int((nextSunrise - datetime.now()).total_seconds()) + time_to_sleep = int((nextSunrise - datetime.utcnow()).total_seconds()) logging.info (f'Waiting for sunrise at {nextSunrise} UTC ({time_to_sleep} seconds)') if time_to_sleep > 0: time.sleep(time_to_sleep)