From a9bcba3d7cc869de3020348a5e3242afe1d613e0 Mon Sep 17 00:00:00 2001 From: Andrey Klimov Date: Wed, 22 Sep 2021 01:03:57 +0300 Subject: [PATCH 1/2] restart on MQTT err fix, Float storage & RAW fix --- build-flags/build_flags_mega2560slim2 | 2 +- lighthub/item.cpp | 8 +++++ lighthub/item.h | 1 + lighthub/itemCmd.cpp | 42 +++++++++++++++++++++++---- lighthub/main.cpp | 27 +++++++++-------- lighthub/modules/out_ac.h | 2 +- 6 files changed, 63 insertions(+), 19 deletions(-) diff --git a/build-flags/build_flags_mega2560slim2 b/build-flags/build_flags_mega2560slim2 index a9d219e..ef80113 100644 --- a/build-flags/build_flags_mega2560slim2 +++ b/build-flags/build_flags_mega2560slim2 @@ -10,7 +10,7 @@ -DNO_HOMIE -DCSSHDC_DISABLE -DSPILED_DISABLE --DAC_DISABLE +#-DAC_DISABLE -DSYSLOG_ENABLE -DPID_DISABLE -DOTA diff --git a/lighthub/item.cpp b/lighthub/item.cpp index 775a0f5..8e2e9f5 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -388,6 +388,14 @@ void Item::setVal(long int par) // Only store if VAL is int (autogenerated or c itemVal->type = aJson_Int; } +void Item::setFloatVal(float par) // Only store if VAL is int (autogenerated or config-defined) +{ + if (!itemVal || (itemVal->type != aJson_Int && itemVal->type != aJson_Float && itemVal->type != aJson_NULL)) return; + //debugSerial<")<itemVal->valueint); //debugSerial<itemVal->valueint); //debugSerial<setCmd(cmd.cmdCode); if (optionsFlag & SEND_PARAMETERS) + switch (cmd.itemArgType) { + case ST_FLOAT: + item->setFloatVal(param.asfloat); + //case ST_FLOAT_CELSIUS: + break; + + case ST_INT32: + case ST_UINT32: + item->setVal(param.asInt32); + break; + + default: item->setSubtype(cmd.itemArgType); item->setVal(param.asInt32); } diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 1296bb3..4cdbd08 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -1468,16 +1468,15 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args) } else { errorSerial< Date: Mon, 4 Oct 2021 18:53:32 +0300 Subject: [PATCH 2/2] NoMQTT mode, float config val, small fixes --- lighthub/abstractch.cpp | 2 +- lighthub/item.cpp | 4 ++-- lighthub/itemCmd.cpp | 5 +++-- lighthub/main.cpp | 15 ++++++++++++--- lighthub/main.h | 2 +- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lighthub/abstractch.cpp b/lighthub/abstractch.cpp index 57e1ade..fdccd18 100644 --- a/lighthub/abstractch.cpp +++ b/lighthub/abstractch.cpp @@ -31,7 +31,7 @@ int abstractCh::publishTopic(const char* topic, const char * value, const char* { strncpy(addrstr,topic,sizeof(addrstr)); if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,topic); - strncat(addrstr,subtopic,sizeof(addrstr)); + strncat(addrstr,subtopic,sizeof(addrstr)-1); if (mqttClient.connected() && lanStatus == OPERATION && !ethernetIdleCount) { mqttClient.publish(addrstr, value, true); diff --git a/lighthub/item.cpp b/lighthub/item.cpp index 8e2e9f5..291e4bb 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -1074,9 +1074,9 @@ switch (itemType) { pinMode(iaddr, OUTPUT); if (inverse) - digitalWrite(iaddr, k = ((icmd == CMD_ON) ? LOW : HIGH)); + digitalWrite(iaddr, k = ((icmd == CMD_ON || icmd == CMD_AUTO) ? LOW : HIGH)); else - digitalWrite(iaddr, k = ((icmd == CMD_ON) ? HIGH : LOW)); + digitalWrite(iaddr, k = ((icmd == CMD_ON || icmd == CMD_AUTO) ? HIGH : LOW)); debugSerial<itemVal->valueint); + Float(item->itemVal->valuefloat); //debugSerial<setFloatVal(param.asfloat); - //case ST_FLOAT_CELSIUS: + // break; case ST_INT32: diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 4cdbd08..9ad197e 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -257,6 +257,8 @@ int httpHandler(Client& client, String request, long contentLength, bool authori itemCmd ic; ic.loadItem(&item,SEND_COMMAND|SEND_PARAMETERS); + if (item.itemType == CH_GROUP) + {if (item.isActive()) item.setCmd(CMD_ON); else item.setCmd(CMD_OFF);} char buf[32]; response=ic.toString(buf, sizeof(buf)); @@ -270,7 +272,7 @@ int httpHandler(Client& client, String request, long contentLength, bool authori request+=body; debugSerial<