Browse Source

0.7.3

* fix hidden SSID scan #983
* improved NRF24 missing message on home screen #981
* fix MqTT publishing only updated values #982
pull/985/head
lumapu 2 years ago
parent
commit
4e54bcf299
  1. 5
      src/CHANGES.md
  2. 10
      src/app.cpp
  3. 4
      src/app.h
  4. 4
      src/config/settings.h
  5. 2
      src/defines.h
  6. 8
      src/hm/hmPayload.h
  7. 10
      src/hm/miPayload.h
  8. 8
      src/hms/hmsPayload.h
  9. 10
      src/publisher/pubMqtt.h
  10. 17
      src/publisher/pubMqttIvData.h
  11. 3
      src/web/RestApi.h
  12. 7
      src/web/html/setup.html
  13. 1
      src/web/web.h
  14. 9
      src/wifi/ahoywifi.cpp

5
src/CHANGES.md

@ -1,5 +1,10 @@
# Development Changes # 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 ## 0.7.2 - 2023-06-08
* fix HMS-800 and HMS-1000 assignments #981 * fix HMS-800 and HMS-1000 assignments #981
* make nrf enabled all the time for ESP8266 * make nrf enabled all the time for ESP8266

10
src/app.cpp

@ -55,11 +55,11 @@ void app::setup() {
if(mConfig->nrf.enabled) { if(mConfig->nrf.enabled) {
mPayload.setup(this, &mSys, &mNrfRadio, &mStat, mConfig->nrf.maxRetransPerPyld, &mTimestamp); mPayload.setup(this, &mSys, &mNrfRadio, &mStat, mConfig->nrf.maxRetransPerPyld, &mTimestamp);
mPayload.enableSerialDebug(mConfig->serial.debug); 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.setup(this, &mSys, &mNrfRadio, &mStat, mConfig->nrf.maxRetransPerPyld, &mTimestamp);
mMiPayload.enableSerialDebug(mConfig->serial.debug); 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) #if defined(ESP32)
@ -334,7 +334,7 @@ void app::tickZeroValues(void) {
} }
if(changed) if(changed)
payloadEventListener(RealTimeRunData_Debug); payloadEventListener(RealTimeRunData_Debug, NULL);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -356,7 +356,7 @@ void app::tickMinute(void) {
} }
if(changed) if(changed)
payloadEventListener(RealTimeRunData_Debug); payloadEventListener(RealTimeRunData_Debug, NULL);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -379,7 +379,7 @@ void app::tickMidnight(void) {
} }
if(changed) if(changed)
payloadEventListener(RealTimeRunData_Debug); payloadEventListener(RealTimeRunData_Debug, NULL);
if (mMqttEnabled) if (mMqttEnabled)
mMqtt.tickerMidnight(); mMqtt.tickerMidnight();

4
src/app.h

@ -242,10 +242,10 @@ class app : public IApp, public ah::Scheduler {
void resetSystem(void); void resetSystem(void);
void payloadEventListener(uint8_t cmd) { void payloadEventListener(uint8_t cmd, Inverter<> *iv) {
#if !defined(AP_ONLY) #if !defined(AP_ONLY)
if (mMqttEnabled) if (mMqttEnabled)
mMqtt.payloadEventListener(cmd); mMqtt.payloadEventListener(cmd, iv);
#endif #endif
if(mConfig->plugin.display.type != 0) if(mConfig->plugin.display.type != 0)
mDisplay.payloadEventListener(cmd); mDisplay.payloadEventListener(cmd);

4
src/config/settings.h

@ -68,6 +68,7 @@ typedef struct {
// wifi // wifi
char stationSsid[SSID_LEN]; char stationSsid[SSID_LEN];
char stationPwd[PWD_LEN]; char stationPwd[PWD_LEN];
bool isHidden;
cfgIp_t ip; cfgIp_t ip;
} cfgSys_t; } cfgSys_t;
@ -359,6 +360,7 @@ class settings {
else { else {
snprintf(mCfg.sys.stationSsid, SSID_LEN, FB_WIFI_SSID); snprintf(mCfg.sys.stationSsid, SSID_LEN, FB_WIFI_SSID);
snprintf(mCfg.sys.stationPwd, PWD_LEN, FB_WIFI_PWD); snprintf(mCfg.sys.stationPwd, PWD_LEN, FB_WIFI_PWD);
mCfg.sys.isHidden = false;
} }
snprintf(mCfg.sys.deviceName, DEVNAME_LEN, DEF_DEVICE_NAME); snprintf(mCfg.sys.deviceName, DEVNAME_LEN, DEF_DEVICE_NAME);
@ -426,6 +428,7 @@ class settings {
char buf[16]; char buf[16];
obj[F("ssid")] = mCfg.sys.stationSsid; obj[F("ssid")] = mCfg.sys.stationSsid;
obj[F("pwd")] = mCfg.sys.stationPwd; obj[F("pwd")] = mCfg.sys.stationPwd;
obj[F("hidd")] = (bool) mCfg.sys.isHidden;
obj[F("dev")] = mCfg.sys.deviceName; obj[F("dev")] = mCfg.sys.deviceName;
obj[F("adm")] = mCfg.sys.adminPwd; obj[F("adm")] = mCfg.sys.adminPwd;
obj[F("prot_mask")] = mCfg.sys.protectionMask; obj[F("prot_mask")] = mCfg.sys.protectionMask;
@ -438,6 +441,7 @@ class settings {
} else { } else {
getChar(obj, F("ssid"), mCfg.sys.stationSsid, SSID_LEN); getChar(obj, F("ssid"), mCfg.sys.stationSsid, SSID_LEN);
getChar(obj, F("pwd"), mCfg.sys.stationPwd, PWD_LEN); getChar(obj, F("pwd"), mCfg.sys.stationPwd, PWD_LEN);
getVal<bool>(obj, F("hidd"), &mCfg.sys.isHidden);
getChar(obj, F("dev"), mCfg.sys.deviceName, DEVNAME_LEN); getChar(obj, F("dev"), mCfg.sys.deviceName, DEVNAME_LEN);
getChar(obj, F("adm"), mCfg.sys.adminPwd, PWD_LEN); getChar(obj, F("adm"), mCfg.sys.adminPwd, PWD_LEN);
getVal<uint16_t>(obj, F("prot_mask"), &mCfg.sys.protectionMask); getVal<uint16_t>(obj, F("prot_mask"), &mCfg.sys.protectionMask);

2
src/defines.h

@ -13,7 +13,7 @@
//------------------------------------- //-------------------------------------
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 7 #define VERSION_MINOR 7
#define VERSION_PATCH 2 #define VERSION_PATCH 3
//------------------------------------- //-------------------------------------
typedef struct { typedef struct {

8
src/hm/hmPayload.h

@ -28,7 +28,7 @@ typedef struct {
} invPayload_t; } invPayload_t;
typedef std::function<void(uint8_t)> payloadListenerType; typedef std::function<void(uint8_t, Inverter<> *)> payloadListenerType;
typedef std::function<void(uint16_t alarmCode, uint32_t start, uint32_t end)> alarmListenerType; typedef std::function<void(uint16_t alarmCode, uint32_t start, uint32_t end)> alarmListenerType;
@ -342,7 +342,7 @@ class HmPayload {
yield(); yield();
} }
iv->doCalculations(); iv->doCalculations();
notify(mPayload[iv->id].txCmd); notify(mPayload[iv->id].txCmd, iv);
if(AlarmData == mPayload[iv->id].txCmd) { if(AlarmData == mPayload[iv->id].txCmd) {
uint8_t i = 0; uint8_t i = 0;
@ -372,9 +372,9 @@ class HmPayload {
} }
private: private:
void notify(uint8_t val) { void notify(uint8_t val, Inverter<> *iv) {
if(NULL != mCbPayload) if(NULL != mCbPayload)
(mCbPayload)(val); (mCbPayload)(val, iv);
} }
void notify(uint16_t code, uint32_t start, uint32_t endTime) { void notify(uint16_t code, uint32_t start, uint32_t endTime) {

10
src/hm/miPayload.h

@ -33,7 +33,7 @@ typedef struct {
} miPayload_t; } miPayload_t;
typedef std::function<void(uint8_t)> miPayloadListenerType; typedef std::function<void(uint8_t, Inverter<> *)> miPayloadListenerType;
template<class HMSYSTEM, class HMRADIO> template<class HMSYSTEM, class HMRADIO>
@ -363,7 +363,7 @@ const byteAssign_t InfoAssignment[] = {
yield(); yield();
} }
iv->doCalculations(); iv->doCalculations();
notify(mPayload[iv->id].txCmd); notify(mPayload[iv->id].txCmd, iv);
if(AlarmData == mPayload[iv->id].txCmd) { if(AlarmData == mPayload[iv->id].txCmd) {
uint8_t i = 0; uint8_t i = 0;
@ -556,9 +556,9 @@ const byteAssign_t InfoAssignment[] = {
} }
private: private:
void notify(uint8_t val) { void notify(uint8_t val, Inverter<> *iv) {
if(NULL != mCbMiPayload) if(NULL != mCbMiPayload)
(mCbMiPayload)(val); (mCbMiPayload)(val, iv);
} }
void miStsDecode(Inverter<> *iv, packet_t *p, uint8_t stschan = CH1) { void miStsDecode(Inverter<> *iv, packet_t *p, uint8_t stschan = CH1) {
@ -752,7 +752,7 @@ const byteAssign_t InfoAssignment[] = {
iv->setQueuedCmdFinished(); iv->setQueuedCmdFinished();
mStat->rxSuccess++; mStat->rxSuccess++;
yield(); 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) { bool build(uint8_t id, bool *complete) {

8
src/hms/hmsPayload.h

@ -29,7 +29,7 @@ typedef struct {
} hmsPayload_t; } hmsPayload_t;
typedef std::function<void(uint8_t)> payloadListenerType; typedef std::function<void(uint8_t, Inverter<> *)> payloadListenerType;
typedef std::function<void(uint16_t alarmCode, uint32_t start, uint32_t end)> alarmListenerType; typedef std::function<void(uint16_t alarmCode, uint32_t start, uint32_t end)> alarmListenerType;
@ -305,7 +305,7 @@ class HmsPayload {
yield(); yield();
} }
iv->doCalculations(); iv->doCalculations();
notify(mPayload[iv->id].txCmd); notify(mPayload[iv->id].txCmd, iv);
/*if(AlarmData == mPayload[iv->id].txCmd) { /*if(AlarmData == mPayload[iv->id].txCmd) {
uint8_t i = 0; uint8_t i = 0;
@ -335,9 +335,9 @@ class HmsPayload {
} }
private: private:
void notify(uint8_t val) { void notify(uint8_t val, Inverter<> *iv) {
if(NULL != mCbPayload) if(NULL != mCbPayload)
(mCbPayload)(val); (mCbPayload)(val, iv);
} }
void notify(uint16_t code, uint32_t start, uint32_t endTime) { void notify(uint16_t code, uint32_t start, uint32_t endTime) {

10
src/publisher/pubMqtt.h

@ -119,7 +119,7 @@ class PubMqtt {
else { // send mqtt data in a fixed interval else { // send mqtt data in a fixed interval
if(mIntervalTimeout == 0) { if(mIntervalTimeout == 0) {
mIntervalTimeout = mCfgMqtt->interval; mIntervalTimeout = mCfgMqtt->interval;
mSendList.push(RealTimeRunData_Debug); mSendList.push(sendListCmdIv(RealTimeRunData_Debug, NULL));
sendIvData(); sendIvData();
} }
} }
@ -165,10 +165,10 @@ class PubMqtt {
publish(mSubTopic, mVal, true); 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(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 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() { void sendIvData() {
bool anyAvail = processIvStatus(); bool anyAvail = processIvStatus();
if (mLastAnyAvail != anyAvail) 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()) if(mSendList.empty())
return; return;
@ -584,7 +584,7 @@ class PubMqtt {
uint32_t *mUtcTimestamp; uint32_t *mUtcTimestamp;
uint32_t mRxCnt, mTxCnt; uint32_t mRxCnt, mTxCnt;
std::queue<uint8_t> mSendList; std::queue<sendListCmdIv> mSendList;
std::queue<alarm_t> mAlarmList; std::queue<alarm_t> mAlarmList;
subscriptionCb mSubscriptionCb; subscriptionCb mSubscriptionCb;
bool mLastAnyAvail; bool mLastAnyAvail;

17
src/publisher/pubMqttIvData.h

@ -12,10 +12,16 @@
typedef std::function<void(const char *subTopic, const char *payload, bool retained)> pubMqttPublisherType; typedef std::function<void(const char *subTopic, const char *payload, bool retained)> pubMqttPublisherType;
struct sendListCmdIv {
uint8_t cmd;
Inverter<> *iv;
sendListCmdIv(uint8_t a, Inverter<> *i) : cmd(a), iv(i) {}
};
template<class HMSYSTEM> template<class HMSYSTEM>
class PubMqttIvData { class PubMqttIvData {
public: public:
void setup(HMSYSTEM *sys, uint32_t *utcTs, std::queue<uint8_t> *sendList) { void setup(HMSYSTEM *sys, uint32_t *utcTs, std::queue<sendListCmdIv> *sendList) {
mSys = sys; mSys = sys;
mUtcTimestamp = utcTs; mUtcTimestamp = utcTs;
mSendList = sendList; mSendList = sendList;
@ -60,7 +66,8 @@ class PubMqttIvData {
void stateStart() { void stateStart() {
mLastIvId = 0; mLastIvId = 0;
if(!mSendList->empty()) { if(!mSendList->empty()) {
mCmd = mSendList->front(); mCmd = mSendList->front().cmd;
mIvSend = mSendList->front().iv;
if((RealTimeRunData_Debug != mCmd) || !mRTRDataHasBeenSent) { if((RealTimeRunData_Debug != mCmd) || !mRTRDataHasBeenSent) {
mSendTotals = (RealTimeRunData_Debug == mCmd); mSendTotals = (RealTimeRunData_Debug == mCmd);
@ -141,9 +148,11 @@ class PubMqttIvData {
} else } else
mIvLastRTRpub[mIv->id] = lastTs; mIvLastRTRpub[mIv->id] = lastTs;
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(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))); snprintf(mVal, 40, "%g", ah::round3(mIv->getValue(mPos, rec)));
mPublish(mSubTopic, mVal, retained); mPublish(mSubTopic, mVal, retained);
}
mPos++; mPos++;
} else } else
mState = FIND_NXT_IV; mState = FIND_NXT_IV;
@ -195,7 +204,7 @@ class PubMqttIvData {
bool mSendTotals; bool mSendTotals;
float mTotal[4]; float mTotal[4];
Inverter<> *mIv; Inverter<> *mIv, *mIvSend;
uint8_t mPos; uint8_t mPos;
uint32_t mIvLastRTRpub[MAX_NUM_INVERTERS]; uint32_t mIvLastRTRpub[MAX_NUM_INVERTERS];
bool mRTRDataHasBeenSent; bool mRTRDataHasBeenSent;
@ -203,7 +212,7 @@ class PubMqttIvData {
char mSubTopic[32 + MAX_NAME_LENGTH + 1]; char mSubTopic[32 + MAX_NAME_LENGTH + 1];
char mVal[40]; char mVal[40];
std::queue<uint8_t> *mSendList; std::queue<sendListCmdIv> *mSendList;
}; };
#endif /*__PUB_MQTT_IV_DATA_H__*/ #endif /*__PUB_MQTT_IV_DATA_H__*/

3
src/web/RestApi.h

@ -206,6 +206,7 @@ class RestApi {
void getSysInfo(AsyncWebServerRequest *request, JsonObject obj) { void getSysInfo(AsyncWebServerRequest *request, JsonObject obj) {
obj[F("ssid")] = mConfig->sys.stationSsid; obj[F("ssid")] = mConfig->sys.stationSsid;
obj[F("hidd")] = mConfig->sys.isHidden;
obj[F("device_name")] = mConfig->sys.deviceName; obj[F("device_name")] = mConfig->sys.deviceName;
obj[F("dark_mode")] = (bool)mConfig->sys.darkMode; obj[F("dark_mode")] = (bool)mConfig->sys.darkMode;
@ -467,7 +468,7 @@ class RestApi {
JsonArray warn = obj.createNestedArray(F("warnings")); JsonArray warn = obj.createNestedArray(F("warnings"));
if(!mRadio->isChipConnected()) 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()) else if(!mRadio->isPVariant())
warn.add(F("your NRF24 module isn't a plus version(+), maybe incompatible")); warn.add(F("your NRF24 module isn't a plus version(+), maybe incompatible"));
if(!mApp->getSettingsValid()) if(!mApp->getSettingsValid())

7
src/web/html/setup.html

@ -72,7 +72,11 @@
</div> </div>
<div class="row mb-2 mb-sm-3"> <div class="row mb-2 mb-sm-3">
<div class="col-12 col-sm-3 my-2">SSID</div> <div class="col-12 col-sm-3 my-2">SSID</div>
<div class="col-12 col-sm-9"><input type="text" name="ssid"/></div> <div class="col-12 col-sm-9"><input type="text" name="ssid"/><div>
</div>
<div class="row mb-2 mb-sm-3">
<div class="col-12 col-sm-3 my-2">hidden SSID</div>
<div class="col-12 col-sm-9"><input type="checkbox" name="hidd"/><div>
</div> </div>
<div class="row mb-2 mb-sm-3"> <div class="row mb-2 mb-sm-3">
<div class="col-12 col-sm-3 my-2">Password</div> <div class="col-12 col-sm-3 my-2">Password</div>
@ -617,6 +621,7 @@
function parseSys(obj) { function parseSys(obj) {
for(var i of [["device", "device_name"], ["ssid", "ssid"]]) for(var i of [["device", "device_name"], ["ssid", "ssid"]])
document.getElementsByName(i[0])[0].value = obj[i[1]]; document.getElementsByName(i[0])[0].value = obj[i[1]];
document.getElementsByName("hidd")[0].checked = obj["hidd"];
document.getElementsByName("darkMode")[0].checked = obj["dark_mode"]; document.getElementsByName("darkMode")[0].checked = obj["dark_mode"];
e = document.getElementsByName("adminpwd")[0]; e = document.getElementsByName("adminpwd")[0];
if(!obj["pwd_set"]) if(!obj["pwd_set"])

1
src/web/web.h

@ -448,6 +448,7 @@ class Web {
request->arg("ssid").toCharArray(mConfig->sys.stationSsid, SSID_LEN); request->arg("ssid").toCharArray(mConfig->sys.stationSsid, SSID_LEN);
if (request->arg("pwd") != "{PWD}") if (request->arg("pwd") != "{PWD}")
request->arg("pwd").toCharArray(mConfig->sys.stationPwd, PWD_LEN); request->arg("pwd").toCharArray(mConfig->sys.stationPwd, PWD_LEN);
mConfig->sys.isHidden = (request->arg("hidd") == "on");
if (request->arg("device") != "") if (request->arg("device") != "")
request->arg("device").toCharArray(mConfig->sys.deviceName, DEVNAME_LEN); request->arg("device").toCharArray(mConfig->sys.deviceName, DEVNAME_LEN);
mConfig->sys.darkMode = (request->arg("darkMode") == "on"); mConfig->sys.darkMode = (request->arg("darkMode") == "on");

9
src/wifi/ahoywifi.cpp

@ -104,10 +104,15 @@ void ahoywifi::tickWifiLoop() {
DBGPRINTLN(String(mConfig->sys.stationSsid)); DBGPRINTLN(String(mConfig->sys.stationSsid));
mScanCnt = 0; mScanCnt = 0;
mScanActive = true; mScanActive = true;
uint8_t *ssid = ([this] () {
if(mConfig->sys.isHidden)
return (uint8_t *)NULL;
return (uint8_t *)(mConfig->sys.stationSsid);
})();
#if defined(ESP8266) #if defined(ESP8266)
WiFi.scanNetworks(true, false, 0U, (uint8_t *)mConfig->sys.stationSsid); WiFi.scanNetworks(true, true, 0U, ssid);
#else #else
WiFi.scanNetworks(true, false, false, 300U, 0U, mConfig->sys.stationSsid); WiFi.scanNetworks(true, true, false, 300U, 0U, ssid);
#endif #endif
return; return;
} }

Loading…
Cancel
Save