diff --git a/src/CHANGES.md b/src/CHANGES.md index fdde045d7..8225f1df7 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -1,5 +1,10 @@ # Development Changes +## 0.7.3 - 2023-06-09 +* fix hidden SSID scan #983 +* improved NRF24 missing message on home screen #981 +* fix MqTT publishing only updated values #982 + ## 0.7.2 - 2023-06-08 * fix HMS-800 and HMS-1000 assignments #981 * make nrf enabled all the time for ESP8266 diff --git a/src/app.cpp b/src/app.cpp index 5f6ef3ccc..f30ed4dbb 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -55,11 +55,11 @@ void app::setup() { if(mConfig->nrf.enabled) { mPayload.setup(this, &mSys, &mNrfRadio, &mStat, mConfig->nrf.maxRetransPerPyld, &mTimestamp); mPayload.enableSerialDebug(mConfig->serial.debug); - mPayload.addPayloadListener(std::bind(&app::payloadEventListener, this, std::placeholders::_1)); + mPayload.addPayloadListener(std::bind(&app::payloadEventListener, this, std::placeholders::_1, std::placeholders::_2)); mMiPayload.setup(this, &mSys, &mNrfRadio, &mStat, mConfig->nrf.maxRetransPerPyld, &mTimestamp); mMiPayload.enableSerialDebug(mConfig->serial.debug); - mMiPayload.addPayloadListener(std::bind(&app::payloadEventListener, this, std::placeholders::_1)); + mMiPayload.addPayloadListener(std::bind(&app::payloadEventListener, this, std::placeholders::_1, std::placeholders::_2)); } #if defined(ESP32) @@ -334,7 +334,7 @@ void app::tickZeroValues(void) { } if(changed) - payloadEventListener(RealTimeRunData_Debug); + payloadEventListener(RealTimeRunData_Debug, NULL); } //----------------------------------------------------------------------------- @@ -356,7 +356,7 @@ void app::tickMinute(void) { } if(changed) - payloadEventListener(RealTimeRunData_Debug); + payloadEventListener(RealTimeRunData_Debug, NULL); } //----------------------------------------------------------------------------- @@ -379,7 +379,7 @@ void app::tickMidnight(void) { } if(changed) - payloadEventListener(RealTimeRunData_Debug); + payloadEventListener(RealTimeRunData_Debug, NULL); if (mMqttEnabled) mMqtt.tickerMidnight(); diff --git a/src/app.h b/src/app.h index 4d5a90a82..e053cfd94 100644 --- a/src/app.h +++ b/src/app.h @@ -242,10 +242,10 @@ class app : public IApp, public ah::Scheduler { void resetSystem(void); - void payloadEventListener(uint8_t cmd) { + void payloadEventListener(uint8_t cmd, Inverter<> *iv) { #if !defined(AP_ONLY) if (mMqttEnabled) - mMqtt.payloadEventListener(cmd); + mMqtt.payloadEventListener(cmd, iv); #endif if(mConfig->plugin.display.type != 0) mDisplay.payloadEventListener(cmd); diff --git a/src/config/settings.h b/src/config/settings.h index 540d00df7..610b2fefc 100644 --- a/src/config/settings.h +++ b/src/config/settings.h @@ -68,6 +68,7 @@ typedef struct { // wifi char stationSsid[SSID_LEN]; char stationPwd[PWD_LEN]; + bool isHidden; cfgIp_t ip; } cfgSys_t; @@ -359,6 +360,7 @@ class settings { else { snprintf(mCfg.sys.stationSsid, SSID_LEN, FB_WIFI_SSID); snprintf(mCfg.sys.stationPwd, PWD_LEN, FB_WIFI_PWD); + mCfg.sys.isHidden = false; } snprintf(mCfg.sys.deviceName, DEVNAME_LEN, DEF_DEVICE_NAME); @@ -426,6 +428,7 @@ class settings { char buf[16]; obj[F("ssid")] = mCfg.sys.stationSsid; obj[F("pwd")] = mCfg.sys.stationPwd; + obj[F("hidd")] = (bool) mCfg.sys.isHidden; obj[F("dev")] = mCfg.sys.deviceName; obj[F("adm")] = mCfg.sys.adminPwd; obj[F("prot_mask")] = mCfg.sys.protectionMask; @@ -438,11 +441,12 @@ class settings { } else { getChar(obj, F("ssid"), mCfg.sys.stationSsid, SSID_LEN); getChar(obj, F("pwd"), mCfg.sys.stationPwd, PWD_LEN); + getVal(obj, F("hidd"), &mCfg.sys.isHidden); getChar(obj, F("dev"), mCfg.sys.deviceName, DEVNAME_LEN); getChar(obj, F("adm"), mCfg.sys.adminPwd, PWD_LEN); getVal(obj, F("prot_mask"), &mCfg.sys.protectionMask); getVal(obj, F("dark"), &mCfg.sys.darkMode); - if(obj.containsKey(F("ip"))) ah::ip2Arr(mCfg.sys.ip.ip, obj[F("ip")].as()); + if(obj.containsKey(F("ip"))) ah::ip2Arr(mCfg.sys.ip.ip, obj[F("ip")].as()); if(obj.containsKey(F("mask"))) ah::ip2Arr(mCfg.sys.ip.mask, obj[F("mask")].as()); if(obj.containsKey(F("dns1"))) ah::ip2Arr(mCfg.sys.ip.dns1, obj[F("dns1")].as()); if(obj.containsKey(F("dns2"))) ah::ip2Arr(mCfg.sys.ip.dns2, obj[F("dns2")].as()); diff --git a/src/defines.h b/src/defines.h index 3c315e990..90eefe873 100644 --- a/src/defines.h +++ b/src/defines.h @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 7 -#define VERSION_PATCH 2 +#define VERSION_PATCH 3 //------------------------------------- typedef struct { diff --git a/src/hm/hmPayload.h b/src/hm/hmPayload.h index 1b36e26ac..59f678d9b 100644 --- a/src/hm/hmPayload.h +++ b/src/hm/hmPayload.h @@ -28,7 +28,7 @@ typedef struct { } invPayload_t; -typedef std::function payloadListenerType; +typedef std::function *)> payloadListenerType; typedef std::function alarmListenerType; @@ -342,7 +342,7 @@ class HmPayload { yield(); } iv->doCalculations(); - notify(mPayload[iv->id].txCmd); + notify(mPayload[iv->id].txCmd, iv); if(AlarmData == mPayload[iv->id].txCmd) { uint8_t i = 0; @@ -372,9 +372,9 @@ class HmPayload { } private: - void notify(uint8_t val) { + void notify(uint8_t val, Inverter<> *iv) { if(NULL != mCbPayload) - (mCbPayload)(val); + (mCbPayload)(val, iv); } void notify(uint16_t code, uint32_t start, uint32_t endTime) { diff --git a/src/hm/miPayload.h b/src/hm/miPayload.h index b42d4ae2f..2205ecb9d 100644 --- a/src/hm/miPayload.h +++ b/src/hm/miPayload.h @@ -33,7 +33,7 @@ typedef struct { } miPayload_t; -typedef std::function miPayloadListenerType; +typedef std::function *)> miPayloadListenerType; template @@ -363,7 +363,7 @@ const byteAssign_t InfoAssignment[] = { yield(); } iv->doCalculations(); - notify(mPayload[iv->id].txCmd); + notify(mPayload[iv->id].txCmd, iv); if(AlarmData == mPayload[iv->id].txCmd) { uint8_t i = 0; @@ -556,9 +556,9 @@ const byteAssign_t InfoAssignment[] = { } private: - void notify(uint8_t val) { + void notify(uint8_t val, Inverter<> *iv) { if(NULL != mCbMiPayload) - (mCbMiPayload)(val); + (mCbMiPayload)(val, iv); } void miStsDecode(Inverter<> *iv, packet_t *p, uint8_t stschan = CH1) { @@ -752,7 +752,7 @@ const byteAssign_t InfoAssignment[] = { iv->setQueuedCmdFinished(); mStat->rxSuccess++; yield(); - notify(RealTimeRunData_Debug); //iv->type == INV_TYPE_4CH ? 0x36 : 0x09 ); + notify(RealTimeRunData_Debug, iv); //iv->type == INV_TYPE_4CH ? 0x36 : 0x09 ); } bool build(uint8_t id, bool *complete) { diff --git a/src/hms/hmsPayload.h b/src/hms/hmsPayload.h index a3463bd10..fdef3e456 100644 --- a/src/hms/hmsPayload.h +++ b/src/hms/hmsPayload.h @@ -29,7 +29,7 @@ typedef struct { } hmsPayload_t; -typedef std::function payloadListenerType; +typedef std::function *)> payloadListenerType; typedef std::function alarmListenerType; @@ -305,7 +305,7 @@ class HmsPayload { yield(); } iv->doCalculations(); - notify(mPayload[iv->id].txCmd); + notify(mPayload[iv->id].txCmd, iv); /*if(AlarmData == mPayload[iv->id].txCmd) { uint8_t i = 0; @@ -335,9 +335,9 @@ class HmsPayload { } private: - void notify(uint8_t val) { + void notify(uint8_t val, Inverter<> *iv) { if(NULL != mCbPayload) - (mCbPayload)(val); + (mCbPayload)(val, iv); } void notify(uint16_t code, uint32_t start, uint32_t endTime) { diff --git a/src/publisher/pubMqtt.h b/src/publisher/pubMqtt.h index 1f8519f56..5be82c0fa 100644 --- a/src/publisher/pubMqtt.h +++ b/src/publisher/pubMqtt.h @@ -119,7 +119,7 @@ class PubMqtt { else { // send mqtt data in a fixed interval if(mIntervalTimeout == 0) { mIntervalTimeout = mCfgMqtt->interval; - mSendList.push(RealTimeRunData_Debug); + mSendList.push(sendListCmdIv(RealTimeRunData_Debug, NULL)); sendIvData(); } } @@ -165,10 +165,10 @@ class PubMqtt { publish(mSubTopic, mVal, true); } - void payloadEventListener(uint8_t cmd) { + void payloadEventListener(uint8_t cmd, Inverter<> *iv) { if(mClient.connected()) { // prevent overflow if MQTT broker is not reachable but set if((0 == mCfgMqtt->interval) || (RealTimeRunData_Debug != cmd)) // no interval or no live data - mSendList.push(cmd); + mSendList.push(sendListCmdIv(cmd, iv)); } } @@ -564,7 +564,7 @@ class PubMqtt { void sendIvData() { bool anyAvail = processIvStatus(); if (mLastAnyAvail != anyAvail) - mSendList.push(RealTimeRunData_Debug); // makes sure that total values are calculated + mSendList.push(sendListCmdIv(RealTimeRunData_Debug, NULL)); // makes sure that total values are calculated if(mSendList.empty()) return; @@ -584,7 +584,7 @@ class PubMqtt { uint32_t *mUtcTimestamp; uint32_t mRxCnt, mTxCnt; - std::queue mSendList; + std::queue mSendList; std::queue mAlarmList; subscriptionCb mSubscriptionCb; bool mLastAnyAvail; diff --git a/src/publisher/pubMqttIvData.h b/src/publisher/pubMqttIvData.h index 5e72e522e..11742c29d 100644 --- a/src/publisher/pubMqttIvData.h +++ b/src/publisher/pubMqttIvData.h @@ -12,10 +12,16 @@ typedef std::function pubMqttPublisherType; +struct sendListCmdIv { + uint8_t cmd; + Inverter<> *iv; + sendListCmdIv(uint8_t a, Inverter<> *i) : cmd(a), iv(i) {} +}; + template class PubMqttIvData { public: - void setup(HMSYSTEM *sys, uint32_t *utcTs, std::queue *sendList) { + void setup(HMSYSTEM *sys, uint32_t *utcTs, std::queue *sendList) { mSys = sys; mUtcTimestamp = utcTs; mSendList = sendList; @@ -60,7 +66,8 @@ class PubMqttIvData { void stateStart() { mLastIvId = 0; if(!mSendList->empty()) { - mCmd = mSendList->front(); + mCmd = mSendList->front().cmd; + mIvSend = mSendList->front().iv; if((RealTimeRunData_Debug != mCmd) || !mRTRDataHasBeenSent) { mSendTotals = (RealTimeRunData_Debug == mCmd); @@ -141,9 +148,11 @@ class PubMqttIvData { } else mIvLastRTRpub[mIv->id] = lastTs; - snprintf(mSubTopic, 32 + MAX_NAME_LENGTH, "%s/ch%d/%s", mIv->config->name, rec->assign[mPos].ch, fields[rec->assign[mPos].fieldId]); - snprintf(mVal, 40, "%g", ah::round3(mIv->getValue(mPos, rec))); - mPublish(mSubTopic, mVal, retained); + if((mIvSend == mIv) || (NULL == mIvSend)) { // send only updated values, or all if the inverter is NULL + snprintf(mSubTopic, 32 + MAX_NAME_LENGTH, "%s/ch%d/%s", mIv->config->name, rec->assign[mPos].ch, fields[rec->assign[mPos].fieldId]); + snprintf(mVal, 40, "%g", ah::round3(mIv->getValue(mPos, rec))); + mPublish(mSubTopic, mVal, retained); + } mPos++; } else mState = FIND_NXT_IV; @@ -195,7 +204,7 @@ class PubMqttIvData { bool mSendTotals; float mTotal[4]; - Inverter<> *mIv; + Inverter<> *mIv, *mIvSend; uint8_t mPos; uint32_t mIvLastRTRpub[MAX_NUM_INVERTERS]; bool mRTRDataHasBeenSent; @@ -203,7 +212,7 @@ class PubMqttIvData { char mSubTopic[32 + MAX_NAME_LENGTH + 1]; char mVal[40]; - std::queue *mSendList; + std::queue *mSendList; }; #endif /*__PUB_MQTT_IV_DATA_H__*/ diff --git a/src/web/RestApi.h b/src/web/RestApi.h index ea08f8c09..35c22e448 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -206,6 +206,7 @@ class RestApi { void getSysInfo(AsyncWebServerRequest *request, JsonObject obj) { obj[F("ssid")] = mConfig->sys.stationSsid; + obj[F("hidd")] = mConfig->sys.isHidden; obj[F("device_name")] = mConfig->sys.deviceName; obj[F("dark_mode")] = (bool)mConfig->sys.darkMode; @@ -467,7 +468,7 @@ class RestApi { JsonArray warn = obj.createNestedArray(F("warnings")); if(!mRadio->isChipConnected()) - warn.add(F("your NRF24 module can't be reached, check the wiring and pinout")); + warn.add(F("your NRF24 module can't be reached, check the wiring, pinout and enable")); else if(!mRadio->isPVariant()) warn.add(F("your NRF24 module isn't a plus version(+), maybe incompatible")); if(!mApp->getSettingsValid()) diff --git a/src/web/html/setup.html b/src/web/html/setup.html index f717c2e31..01d481c22 100644 --- a/src/web/html/setup.html +++ b/src/web/html/setup.html @@ -72,7 +72,11 @@
SSID
-
+
+
+
+
hidden SSID
+
Password
@@ -617,6 +621,7 @@ function parseSys(obj) { for(var i of [["device", "device_name"], ["ssid", "ssid"]]) document.getElementsByName(i[0])[0].value = obj[i[1]]; + document.getElementsByName("hidd")[0].checked = obj["hidd"]; document.getElementsByName("darkMode")[0].checked = obj["dark_mode"]; e = document.getElementsByName("adminpwd")[0]; if(!obj["pwd_set"]) diff --git a/src/web/web.h b/src/web/web.h index d1a0a4a71..0b7ca7de6 100644 --- a/src/web/web.h +++ b/src/web/web.h @@ -448,6 +448,7 @@ class Web { request->arg("ssid").toCharArray(mConfig->sys.stationSsid, SSID_LEN); if (request->arg("pwd") != "{PWD}") request->arg("pwd").toCharArray(mConfig->sys.stationPwd, PWD_LEN); + mConfig->sys.isHidden = (request->arg("hidd") == "on"); if (request->arg("device") != "") request->arg("device").toCharArray(mConfig->sys.deviceName, DEVNAME_LEN); mConfig->sys.darkMode = (request->arg("darkMode") == "on"); diff --git a/src/wifi/ahoywifi.cpp b/src/wifi/ahoywifi.cpp index cd4a44d01..91c8b8d22 100644 --- a/src/wifi/ahoywifi.cpp +++ b/src/wifi/ahoywifi.cpp @@ -104,10 +104,15 @@ void ahoywifi::tickWifiLoop() { DBGPRINTLN(String(mConfig->sys.stationSsid)); mScanCnt = 0; mScanActive = true; + uint8_t *ssid = ([this] () { + if(mConfig->sys.isHidden) + return (uint8_t *)NULL; + return (uint8_t *)(mConfig->sys.stationSsid); + })(); #if defined(ESP8266) - WiFi.scanNetworks(true, false, 0U, (uint8_t *)mConfig->sys.stationSsid); + WiFi.scanNetworks(true, true, 0U, ssid); #else - WiFi.scanNetworks(true, false, false, 300U, 0U, mConfig->sys.stationSsid); + WiFi.scanNetworks(true, true, false, 300U, 0U, ssid); #endif return; }