Skip to content

Commit

Permalink
0.7.3
Browse files Browse the repository at this point in the history
* fix hidden SSID scan #983
* improved NRF24 missing message on home screen #981
* fix MqTT publishing only updated values #982
  • Loading branch information
lumapu committed Jun 9, 2023
1 parent 53853f8 commit 4e54bcf
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 38 deletions.
5 changes: 5 additions & 0 deletions src/CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -334,7 +334,7 @@ void app::tickZeroValues(void) {
}

if(changed)
payloadEventListener(RealTimeRunData_Debug);
payloadEventListener(RealTimeRunData_Debug, NULL);
}

//-----------------------------------------------------------------------------
Expand All @@ -356,7 +356,7 @@ void app::tickMinute(void) {
}

if(changed)
payloadEventListener(RealTimeRunData_Debug);
payloadEventListener(RealTimeRunData_Debug, NULL);
}

//-----------------------------------------------------------------------------
Expand All @@ -379,7 +379,7 @@ void app::tickMidnight(void) {
}

if(changed)
payloadEventListener(RealTimeRunData_Debug);
payloadEventListener(RealTimeRunData_Debug, NULL);

if (mMqttEnabled)
mMqtt.tickerMidnight();
Expand Down
4 changes: 2 additions & 2 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/config/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ typedef struct {
// wifi
char stationSsid[SSID_LEN];
char stationPwd[PWD_LEN];
bool isHidden;

cfgIp_t ip;
} cfgSys_t;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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<bool>(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<uint16_t>(obj, F("prot_mask"), &mCfg.sys.protectionMask);
getVal<bool>(obj, F("dark"), &mCfg.sys.darkMode);
if(obj.containsKey(F("ip"))) ah::ip2Arr(mCfg.sys.ip.ip, obj[F("ip")].as<const char*>());
if(obj.containsKey(F("ip"))) ah::ip2Arr(mCfg.sys.ip.ip, obj[F("ip")].as<const char*>());
if(obj.containsKey(F("mask"))) ah::ip2Arr(mCfg.sys.ip.mask, obj[F("mask")].as<const char*>());
if(obj.containsKey(F("dns1"))) ah::ip2Arr(mCfg.sys.ip.dns1, obj[F("dns1")].as<const char*>());
if(obj.containsKey(F("dns2"))) ah::ip2Arr(mCfg.sys.ip.dns2, obj[F("dns2")].as<const char*>());
Expand Down
2 changes: 1 addition & 1 deletion src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 7
#define VERSION_PATCH 2
#define VERSION_PATCH 3

//-------------------------------------
typedef struct {
Expand Down
8 changes: 4 additions & 4 deletions src/hm/hmPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typedef struct {
} 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;


Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions src/hm/miPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ typedef struct {
} miPayload_t;


typedef std::function<void(uint8_t)> miPayloadListenerType;
typedef std::function<void(uint8_t, Inverter<> *)> miPayloadListenerType;


template<class HMSYSTEM, class HMRADIO>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/hms/hmsPayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ typedef struct {
} 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;


Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions src/publisher/pubMqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -584,7 +584,7 @@ class PubMqtt {

uint32_t *mUtcTimestamp;
uint32_t mRxCnt, mTxCnt;
std::queue<uint8_t> mSendList;
std::queue<sendListCmdIv> mSendList;
std::queue<alarm_t> mAlarmList;
subscriptionCb mSubscriptionCb;
bool mLastAnyAvail;
Expand Down
23 changes: 16 additions & 7 deletions src/publisher/pubMqttIvData.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@

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>
class PubMqttIvData {
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;
mUtcTimestamp = utcTs;
mSendList = sendList;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -195,15 +204,15 @@ class PubMqttIvData {
bool mSendTotals;
float mTotal[4];

Inverter<> *mIv;
Inverter<> *mIv, *mIvSend;
uint8_t mPos;
uint32_t mIvLastRTRpub[MAX_NUM_INVERTERS];
bool mRTRDataHasBeenSent;

char mSubTopic[32 + MAX_NAME_LENGTH + 1];
char mVal[40];

std::queue<uint8_t> *mSendList;
std::queue<sendListCmdIv> *mSendList;
};

#endif /*__PUB_MQTT_IV_DATA_H__*/
3 changes: 2 additions & 1 deletion src/web/RestApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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())
Expand Down
7 changes: 6 additions & 1 deletion src/web/html/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@
</div>
<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-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 class="row mb-2 mb-sm-3">
<div class="col-12 col-sm-3 my-2">Password</div>
Expand Down Expand Up @@ -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"])
Expand Down
1 change: 1 addition & 0 deletions src/web/web.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
9 changes: 7 additions & 2 deletions src/wifi/ahoywifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 4e54bcf

Please sign in to comment.