mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
restart on MQTT err fix, Float storage & RAW fix
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
-DNO_HOMIE
|
||||
-DCSSHDC_DISABLE
|
||||
-DSPILED_DISABLE
|
||||
-DAC_DISABLE
|
||||
#-DAC_DISABLE
|
||||
-DSYSLOG_ENABLE
|
||||
-DPID_DISABLE
|
||||
-DOTA
|
||||
|
||||
@@ -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<<F(" Store ")<<F(" Val=")<<par<<endl;
|
||||
itemVal->valuefloat = par;
|
||||
itemVal->type = aJson_Float;
|
||||
}
|
||||
|
||||
void Item::setSubtype(uint8_t 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;
|
||||
|
||||
@@ -131,6 +131,7 @@ class Item
|
||||
void setFlag (short flag);
|
||||
void clearFlag (short flag);
|
||||
void setVal(long int par);
|
||||
void setFloatVal(float par);
|
||||
void setSubtype(uint8_t par);
|
||||
int Poll(int cause);
|
||||
int SendStatus(int sendFlags);
|
||||
|
||||
@@ -362,12 +362,18 @@ itemCmd itemCmd::assignFrom(itemCmd from, short chanType)
|
||||
break;
|
||||
case ST_VOID:
|
||||
break;
|
||||
case ST_STRING:
|
||||
cmd.itemArgType=from.cmd.itemArgType;
|
||||
param.asString=from.param.asString;
|
||||
break;
|
||||
default:
|
||||
debugSerial<<F("Wrong Assignment ")<<from.cmd.itemArgType<<F("->")<<cmd.itemArgType<<endl;
|
||||
}
|
||||
break;
|
||||
case ST_VOID:
|
||||
cmd.itemArgType=from.cmd.itemArgType;
|
||||
param=from.param;
|
||||
break;
|
||||
|
||||
case ST_INT32:
|
||||
case ST_UINT32:
|
||||
@@ -379,12 +385,17 @@ itemCmd itemCmd::assignFrom(itemCmd from, short chanType)
|
||||
param.h=from.param.h;
|
||||
param.s=from.param.s;
|
||||
cmd.itemArgType=ST_HSV255;
|
||||
break;
|
||||
case ST_STRING:
|
||||
cmd.itemArgType=from.cmd.itemArgType;
|
||||
param.asString=from.param.asString;
|
||||
break;
|
||||
default:
|
||||
param.asInt32=from.param.asInt32;
|
||||
cmd.itemArgType=from.cmd.itemArgType;
|
||||
}
|
||||
break;
|
||||
case ST_HS:
|
||||
case ST_HS: //ToDo - string ?
|
||||
param.v=from.getPercents255();
|
||||
cmd.itemArgType=ST_HSV255;
|
||||
break;
|
||||
@@ -394,6 +405,11 @@ itemCmd itemCmd::assignFrom(itemCmd from, short chanType)
|
||||
case ST_FLOAT_CELSIUS:
|
||||
switch (from.cmd.itemArgType)
|
||||
{
|
||||
case ST_STRING:
|
||||
cmd.itemArgType=from.cmd.itemArgType;
|
||||
param.asString=from.param.asString;
|
||||
break;
|
||||
|
||||
case ST_TENS:
|
||||
param.asfloat=from.param.asInt32/10.;
|
||||
break;
|
||||
@@ -441,6 +457,10 @@ itemCmd itemCmd::assignFrom(itemCmd from, short chanType)
|
||||
case ST_RGB:
|
||||
switch (from.cmd.itemArgType)
|
||||
{
|
||||
case ST_STRING:
|
||||
cmd.itemArgType=from.cmd.itemArgType;
|
||||
param.asString=from.param.asString;
|
||||
break;
|
||||
case ST_RGBW:
|
||||
// RGBW_flag=true;
|
||||
case ST_RGB:
|
||||
@@ -950,13 +970,13 @@ bool itemCmd::loadItem(Item * item, uint16_t optionsFlag)
|
||||
|
||||
Int((int32_t)item->itemVal->valueint);
|
||||
//debugSerial<<F("Loaded Int:");
|
||||
debugOut();
|
||||
//debugOut();
|
||||
return true;
|
||||
|
||||
case aJson_Float:
|
||||
Float(item->itemVal->valueint);
|
||||
//debugSerial<<F("Loaded Float:");
|
||||
debugOut();
|
||||
//debugOut();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -988,7 +1008,19 @@ bool itemCmd::saveItem(Item * item, uint16_t optionsFlag)
|
||||
{
|
||||
if (optionsFlag & SEND_COMMAND) item->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);
|
||||
}
|
||||
|
||||
@@ -1468,15 +1468,14 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||
} else {
|
||||
errorSerial<<F("ERROR: Server returned ");
|
||||
errorSerial<<responseStatusCode<<endl;
|
||||
// timerLanCheckTime = millis();// + 5000;
|
||||
return READ_RE_CONFIG;//-11;
|
||||
if (configLoaded) return IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER;
|
||||
else return READ_RE_CONFIG; //Load from NVRAM
|
||||
}
|
||||
|
||||
} else {
|
||||
debugSerial<<F("failed to connect\n");
|
||||
// debugSerial<<F(" try again in 5 seconds\n");
|
||||
// timerLanCheckTime = millis();// + 5000;
|
||||
return READ_RE_CONFIG;//-11;
|
||||
if (configLoaded) return IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER;
|
||||
else return READ_RE_CONFIG; //Load from NVRAM
|
||||
}
|
||||
#endif
|
||||
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32) || defined (NRF5) //|| defined(ARDUINO_ARCH_ESP32) //|| defined(ARDUINO_ARCH_ESP8266)
|
||||
@@ -1524,11 +1523,13 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||
}
|
||||
} else {
|
||||
errorSerial<<F("Config retrieving failed\n");
|
||||
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
||||
if (configLoaded) return IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER;
|
||||
else return READ_RE_CONFIG; //Load from NVRAM
|
||||
}
|
||||
} else {
|
||||
errorSerial<<F("Connect failed\n");
|
||||
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
||||
if (configLoaded) return IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER;
|
||||
else return READ_RE_CONFIG; //Load from NVRAM
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1568,12 +1569,14 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||
}
|
||||
} else {
|
||||
errorSerial<<F("Config retrieving failed\n");
|
||||
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
||||
if (configLoaded) return IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER;
|
||||
else return READ_RE_CONFIG; //Load from NVRAM
|
||||
}
|
||||
} else {
|
||||
errorSerial.printf("[HTTP] GET... failed, error: %s\n", httpClient.errorToString(httpResponseCode).c_str());
|
||||
httpClient.end();
|
||||
return READ_RE_CONFIG;
|
||||
if (configLoaded) return IP_READY_CONFIG_LOADED_CONNECTING_TO_BROKER;
|
||||
else return READ_RE_CONFIG; //Load from NVRAM
|
||||
}
|
||||
httpClient.end();
|
||||
#endif
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#define S_LOCK S_ADDITIONAL+1
|
||||
#define S_QUIET S_ADDITIONAL+2
|
||||
#define S_SWING S_ADDITIONAL+3
|
||||
#define S_RAW S_ADDITIONAL+4
|
||||
//#define S_RAW S_ADDITIONAL+4
|
||||
|
||||
extern void modbusIdle(void) ;
|
||||
class out_AC : public abstractOut {
|
||||
|
||||
Reference in New Issue
Block a user