mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
JSON string type control. Relability fix
This commit is contained in:
@@ -30,7 +30,7 @@ int abstractIn::publish(char * value, const char* subtopic)
|
|||||||
if (in)
|
if (in)
|
||||||
{
|
{
|
||||||
aJsonObject *emit = aJson.getObjectItem(in->inputObj, "emit");
|
aJsonObject *emit = aJson.getObjectItem(in->inputObj, "emit");
|
||||||
if (emit)
|
if (emit && emit->type == aJson_String)
|
||||||
{
|
{
|
||||||
return publishTopic(emit->valuestring,value,subtopic);
|
return publishTopic(emit->valuestring,value,subtopic);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ int itemCtrl2(char* name,int r,int g, int b, int w)
|
|||||||
{ aJsonObject *i =groupArr->child;
|
{ aJsonObject *i =groupArr->child;
|
||||||
while (i)
|
while (i)
|
||||||
{ //Serial.println(i->valuestring);
|
{ //Serial.println(i->valuestring);
|
||||||
itemCtrl2(i->valuestring,r,g,b,w);
|
if (i->type == aJson_String) itemCtrl2(i->valuestring,r,g,b,w);
|
||||||
i=i->next;}
|
i=i->next;}
|
||||||
}
|
}
|
||||||
} //itemtype
|
} //itemtype
|
||||||
@@ -100,7 +100,9 @@ void DMXImmediateUpdate(short tch,short r, short g, short b, short w) {
|
|||||||
if (dmxArr && (dmxArr->type==aJson_Array))
|
if (dmxArr && (dmxArr->type==aJson_Array))
|
||||||
|
|
||||||
{
|
{
|
||||||
char* itemname = aJson.getArrayItem(dmxArr,tch)->valuestring;
|
aJsonObject *DMXch = aJson.getArrayItem(dmxArr,tch);
|
||||||
|
char* itemname = NULL;
|
||||||
|
if (DMXch->type == aJson_String) itemname=DMXch->valuestring;
|
||||||
if (itemname) itemCtrl2(itemname,r,g,b,w);
|
if (itemname) itemCtrl2(itemname,r,g,b,w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ void Input::counterPoll() {
|
|||||||
debugSerial<<F("IN:")<<(pin)<<F(" Counter type. val=")<<counterValue;
|
debugSerial<<F("IN:")<<(pin)<<F(" Counter type. val=")<<counterValue;
|
||||||
|
|
||||||
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
||||||
if (emit) {
|
if (emit && emit->type == aJson_String) {
|
||||||
char valstr[10];
|
char valstr[10];
|
||||||
char addrstr[MQTT_TOPIC_LENGTH];
|
char addrstr[MQTT_TOPIC_LENGTH];
|
||||||
strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
||||||
@@ -327,7 +327,7 @@ void Input::uptimePoll() {
|
|||||||
if (nextPollTime() > millis())
|
if (nextPollTime() > millis())
|
||||||
return;
|
return;
|
||||||
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
||||||
if (emit) {
|
if (emit && emit->type == aJson_String) {
|
||||||
#ifdef WITH_DOMOTICZ
|
#ifdef WITH_DOMOTICZ
|
||||||
if(getIdxField()){
|
if(getIdxField()){
|
||||||
publishDataToDomoticz(DHT_POLL_DELAY_DEFAULT, emit, "{\"idx\":%s,\"svalue\":\"%d\"}", getIdxField(), millis());
|
publishDataToDomoticz(DHT_POLL_DELAY_DEFAULT, emit, "{\"idx\":%s,\"svalue\":\"%d\"}", getIdxField(), millis());
|
||||||
@@ -422,9 +422,9 @@ void Input::dht22Poll() {
|
|||||||
#endif
|
#endif
|
||||||
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
||||||
aJsonObject *item = aJson.getObjectItem(inputObj, "item");
|
aJsonObject *item = aJson.getObjectItem(inputObj, "item");
|
||||||
if (item) thermoSetCurTemp(item->valuestring, temp);
|
if (item && item->type == aJson_String) thermoSetCurTemp(item->valuestring, temp);
|
||||||
debugSerial << F("IN:") << pin << F(" DHT22 type. T=") << temp << F("°C H=") << humidity << F("%")<<endl;
|
debugSerial << F("IN:") << pin << F(" DHT22 type. T=") << temp << F("°C H=") << humidity << F("%")<<endl;
|
||||||
if (emit && temp && humidity && temp == temp && humidity == humidity) {
|
if (emit && emit->type == aJson_String && temp && humidity && temp == temp && humidity == humidity) {
|
||||||
char addrstr[MQTT_TOPIC_LENGTH] = "";
|
char addrstr[MQTT_TOPIC_LENGTH] = "";
|
||||||
#ifdef WITH_DOMOTICZ
|
#ifdef WITH_DOMOTICZ
|
||||||
if(getIdxField()){
|
if(getIdxField()){
|
||||||
@@ -480,13 +480,13 @@ bool Input::executeCommand(aJsonObject* cmd, int8_t toggle, char* defCmd)
|
|||||||
aJsonObject *emit = aJson.getObjectItem(cmd, "emit");
|
aJsonObject *emit = aJson.getObjectItem(cmd, "emit");
|
||||||
|
|
||||||
char * itemCommand;
|
char * itemCommand;
|
||||||
if (irev && toggle) itemCommand = irev->valuestring;
|
if (irev && toggle && irev->type == aJson_String) itemCommand = irev->valuestring;
|
||||||
else if(icmd) itemCommand = icmd->valuestring;
|
else if(icmd && icmd->type == aJson_String) itemCommand = icmd->valuestring;
|
||||||
else itemCommand = defCmd;
|
else itemCommand = defCmd;
|
||||||
|
|
||||||
char * emitCommand;
|
char * emitCommand;
|
||||||
if (erev && toggle) itemCommand = erev->valuestring;
|
if (erev && toggle && erev->type == aJson_String) itemCommand = erev->valuestring;
|
||||||
else if(ecmd) emitCommand = ecmd->valuestring;
|
else if(ecmd && ecmd->type == aJson_String) emitCommand = ecmd->valuestring;
|
||||||
else emitCommand = defCmd;
|
else emitCommand = defCmd;
|
||||||
|
|
||||||
debugSerial << F("IN:") << (pin) << F(" : ") <<endl;
|
debugSerial << F("IN:") << (pin) << F(" : ") <<endl;
|
||||||
@@ -496,7 +496,7 @@ if (emit) debugSerial << emit->valuestring<< F(" -> ")<<emitCommand<<endl;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (emit && emitCommand) {
|
if (emit && emitCommand && emit->type == aJson_String) {
|
||||||
/*
|
/*
|
||||||
TODO implement
|
TODO implement
|
||||||
#ifdef WITH_DOMOTICZ
|
#ifdef WITH_DOMOTICZ
|
||||||
@@ -520,7 +520,7 @@ if (mqttClient.connected() && !ethernetIdleCount)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // emit
|
} // emit
|
||||||
if (item && itemCommand) {
|
if (item && itemCommand && item->type == aJson_String) {
|
||||||
//debugSerial <<F("Controlled item:")<< item->valuestring <<endl;
|
//debugSerial <<F("Controlled item:")<< item->valuestring <<endl;
|
||||||
Item it(item->valuestring);
|
Item it(item->valuestring);
|
||||||
if (it.isValid()) it.Ctrl(itemCommand, true);
|
if (it.isValid()) it.Ctrl(itemCommand, true);
|
||||||
@@ -895,7 +895,7 @@ void Input::onContactChanged(int newValue) {
|
|||||||
aJsonObject *scmd = aJson.getObjectItem(inputObj, "scmd");
|
aJsonObject *scmd = aJson.getObjectItem(inputObj, "scmd");
|
||||||
aJsonObject *rcmd = aJson.getObjectItem(inputObj, "rcmd");
|
aJsonObject *rcmd = aJson.getObjectItem(inputObj, "rcmd");
|
||||||
debugSerial << F("LEGACY IN:") << (pin) << F("=") << newValue << endl;
|
debugSerial << F("LEGACY IN:") << (pin) << F("=") << newValue << endl;
|
||||||
if (emit) {
|
if (emit && emit->type == aJson_String) {
|
||||||
#ifdef WITH_DOMOTICZ
|
#ifdef WITH_DOMOTICZ
|
||||||
if (getIdxField())
|
if (getIdxField())
|
||||||
{ (newValue) ? publishDataToDomoticz(0, emit, "{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"On\"}",
|
{ (newValue) ? publishDataToDomoticz(0, emit, "{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"On\"}",
|
||||||
@@ -912,26 +912,26 @@ if (mqttClient.connected() && !ethernetIdleCount)
|
|||||||
{
|
{
|
||||||
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
||||||
if (newValue) { //send set command
|
if (newValue) { //send set command
|
||||||
if (!scmd) mqttClient.publish(addrstr, "ON", true);
|
if (!scmd || scmd->type != aJson_String) mqttClient.publish(addrstr, "ON", true);
|
||||||
else if (strlen(scmd->valuestring))
|
else if (strlen(scmd->valuestring))
|
||||||
mqttClient.publish(addrstr, scmd->valuestring, true);
|
mqttClient.publish(addrstr, scmd->valuestring, true);
|
||||||
} else { //send reset command
|
} else { //send reset command
|
||||||
if (!rcmd) mqttClient.publish(addrstr, "OFF", true);
|
if (!rcmd || rcmd->type == aJson_String) mqttClient.publish(addrstr, "OFF", true);
|
||||||
else if (strlen(rcmd->valuestring))mqttClient.publish(addrstr, rcmd->valuestring, true);
|
else if (strlen(rcmd->valuestring))mqttClient.publish(addrstr, rcmd->valuestring, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // emit
|
} // emit
|
||||||
if (item) {
|
if (item && item->type == aJson_String) {
|
||||||
//debugSerial <<F("Controlled item:")<< item->valuestring <<endl;
|
//debugSerial <<F("Controlled item:")<< item->valuestring <<endl;
|
||||||
Item it(item->valuestring);
|
Item it(item->valuestring);
|
||||||
if (it.isValid()) {
|
if (it.isValid()) {
|
||||||
if (newValue) { //send set command
|
if (newValue) { //send set command
|
||||||
if (!scmd) it.Ctrl(CMD_ON, 0, NULL, true);
|
if (!scmd || scmd->type != aJson_String) it.Ctrl(CMD_ON, 0, NULL, true);
|
||||||
else if (strlen(scmd->valuestring))
|
else if (strlen(scmd->valuestring))
|
||||||
it.Ctrl(scmd->valuestring, true);
|
it.Ctrl(scmd->valuestring, true);
|
||||||
} else { //send reset command
|
} else { //send reset command
|
||||||
if (!rcmd) it.Ctrl(CMD_OFF, 0, NULL, true);
|
if (!rcmd || rcmd->type == aJson_String) it.Ctrl(CMD_OFF, 0, NULL, true);
|
||||||
else if (strlen(rcmd->valuestring))
|
else if (strlen(rcmd->valuestring))
|
||||||
it.Ctrl(rcmd->valuestring, true);
|
it.Ctrl(rcmd->valuestring, true);
|
||||||
}
|
}
|
||||||
@@ -945,7 +945,7 @@ void Input::onAnalogChanged(float newValue) {
|
|||||||
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
||||||
|
|
||||||
|
|
||||||
if (emit) {
|
if (emit && emit->type == aJson_String) {
|
||||||
|
|
||||||
//#ifdef WITH_DOMOTICZ
|
//#ifdef WITH_DOMOTICZ
|
||||||
// if (getIdxField()) {
|
// if (getIdxField()) {
|
||||||
@@ -963,7 +963,7 @@ void Input::onAnalogChanged(float newValue) {
|
|||||||
mqttClient.publish(addrstr, strVal, true);
|
mqttClient.publish(addrstr, strVal, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item) {
|
if (item && item->type == aJson_String) {
|
||||||
int intNewValue = round(newValue);
|
int intNewValue = round(newValue);
|
||||||
Item it(item->valuestring);
|
Item it(item->valuestring);
|
||||||
if (it.isValid()) {
|
if (it.isValid()) {
|
||||||
@@ -976,6 +976,8 @@ void Input::onAnalogChanged(float newValue) {
|
|||||||
bool Input::publishDataToDomoticz(int pollTimeIncrement, aJsonObject *emit, const char *format, ...)
|
bool Input::publishDataToDomoticz(int pollTimeIncrement, aJsonObject *emit, const char *format, ...)
|
||||||
{
|
{
|
||||||
#ifdef WITH_DOMOTICZ
|
#ifdef WITH_DOMOTICZ
|
||||||
|
if (emit && emit->type == aJson_String)
|
||||||
|
{
|
||||||
debugSerial << F("\nDomoticz valstr:");
|
debugSerial << F("\nDomoticz valstr:");
|
||||||
char valstr[50];
|
char valstr[50];
|
||||||
va_list args;
|
va_list args;
|
||||||
@@ -988,6 +990,7 @@ bool Input::publishDataToDomoticz(int pollTimeIncrement, aJsonObject *emit, cons
|
|||||||
if (pollTimeIncrement)
|
if (pollTimeIncrement)
|
||||||
setNextPollTime(millis() + pollTimeIncrement);
|
setNextPollTime(millis() + pollTimeIncrement);
|
||||||
// debugSerial << F(" NextPollMillis=") << nextPollTime() << endl;
|
// debugSerial << F(" NextPollMillis=") << nextPollTime() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
@@ -995,7 +998,7 @@ bool Input::publishDataToDomoticz(int pollTimeIncrement, aJsonObject *emit, cons
|
|||||||
|
|
||||||
char* Input::getIdxField() {
|
char* Input::getIdxField() {
|
||||||
aJsonObject *idx = aJson.getObjectItem(inputObj, "idx");
|
aJsonObject *idx = aJson.getObjectItem(inputObj, "idx");
|
||||||
if(idx&&idx->valuestring)
|
if(idx&& idx->type == aJson_String && idx->valuestring)
|
||||||
return idx->valuestring;
|
return idx->valuestring;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1021,8 +1021,11 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
|
|||||||
if (itemArg->type == aJson_Array) {
|
if (itemArg->type == aJson_Array) {
|
||||||
aJsonObject *i = itemArg->child;
|
aJsonObject *i = itemArg->child;
|
||||||
while (i) {
|
while (i) {
|
||||||
Item it(i->valuestring);
|
if (i->type == aJson_String)
|
||||||
it.Ctrl(cmd, n, Par, send,suffixCode,subItem); //// was true
|
{
|
||||||
|
Item it(i->valuestring);
|
||||||
|
it.Ctrl(cmd, n, Par, send,suffixCode,subItem); //// was true
|
||||||
|
}
|
||||||
i = i->next;
|
i = i->next;
|
||||||
} //while
|
} //while
|
||||||
} //if
|
} //if
|
||||||
@@ -1142,11 +1145,14 @@ int Item::isActive() {
|
|||||||
debugSerial<<F(" Grp:");
|
debugSerial<<F(" Grp:");
|
||||||
aJsonObject *i = itemArg->child;
|
aJsonObject *i = itemArg->child;
|
||||||
while (i) {
|
while (i) {
|
||||||
Item it(i->valuestring);
|
if (i->type == aJson_String)
|
||||||
|
{
|
||||||
|
Item it(i->valuestring);
|
||||||
|
|
||||||
if (it.isValid() && it.isActive()>0) {
|
if (it.isValid() && it.isActive()>0) {
|
||||||
debugSerial<<F(" active\n");
|
debugSerial<<F(" active\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
i = i->next;
|
i = i->next;
|
||||||
} //while
|
} //while
|
||||||
@@ -1319,6 +1325,7 @@ int Item::VacomSetFan(int8_t val, int8_t cmd) {
|
|||||||
int Item::VacomSetHeat(int8_t val, int8_t cmd) {
|
int Item::VacomSetHeat(int8_t val, int8_t cmd) {
|
||||||
uint8_t result;
|
uint8_t result;
|
||||||
int addr;
|
int addr;
|
||||||
|
if (itemArg->type != aJson_String) return 0;
|
||||||
|
|
||||||
Item it(itemArg->valuestring);
|
Item it(itemArg->valuestring);
|
||||||
if (it.isValid() && it.itemType == CH_VC) addr=it.getArg();
|
if (it.isValid() && it.itemType == CH_VC) addr=it.getArg();
|
||||||
@@ -1448,7 +1455,7 @@ int Item::checkFM() {
|
|||||||
aJson.addNumberToObject(out, "sw", (int) node.getResponseBuffer(0));
|
aJson.addNumberToObject(out, "sw", (int) node.getResponseBuffer(0));
|
||||||
if (RPM && itemArg->type == aJson_Array) {
|
if (RPM && itemArg->type == aJson_Array) {
|
||||||
aJsonObject *airGateObj = aJson.getArrayItem(itemArg, 1);
|
aJsonObject *airGateObj = aJson.getArrayItem(itemArg, 1);
|
||||||
if (airGateObj) {
|
if (airGateObj && airGateObj->type == aJson_String) {
|
||||||
int val = 100;
|
int val = 100;
|
||||||
Item item(airGateObj->valuestring);
|
Item item(airGateObj->valuestring);
|
||||||
if (item.isValid())
|
if (item.isValid())
|
||||||
|
|||||||
@@ -517,6 +517,29 @@ void onMQTTConnect(){
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* getStringFromConfig(aJsonObject * a, int i)
|
||||||
|
{
|
||||||
|
aJsonObject * element = NULL;
|
||||||
|
if (!a) return NULL;
|
||||||
|
if (a->type == aJson_Array)
|
||||||
|
element = aJson.getArrayItem(a, i);
|
||||||
|
// TODO - human readable JSON objects as alias
|
||||||
|
|
||||||
|
if (element && element->type == aJson_String) return element->valuestring;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* getStringFromConfig(aJsonObject * a, char * name)
|
||||||
|
{
|
||||||
|
aJsonObject * element = NULL;
|
||||||
|
if (!a) return NULL;
|
||||||
|
if (a->type == aJson_Object)
|
||||||
|
element = aJson.getObjectItem(a, name);
|
||||||
|
if (element && element->type == aJson_String) return element->valuestring;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ip_ready_config_loaded_connecting_to_broker() {
|
void ip_ready_config_loaded_connecting_to_broker() {
|
||||||
short n = 0;
|
short n = 0;
|
||||||
int port = 1883;
|
int port = 1883;
|
||||||
@@ -528,15 +551,15 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
|||||||
char syslogDeviceHostname[16];
|
char syslogDeviceHostname[16];
|
||||||
if (mqttArr && (aJson.getArraySize(mqttArr)))
|
if (mqttArr && (aJson.getArraySize(mqttArr)))
|
||||||
{
|
{
|
||||||
deviceName = aJson.getArrayItem(mqttArr, 0)->valuestring;
|
deviceName = getStringFromConfig(mqttArr, 0);
|
||||||
debugSerial<<F("Device Name:")<<deviceName<<endl;
|
debugSerial<<F("Device Name:")<<deviceName<<endl;
|
||||||
}
|
}
|
||||||
#ifdef SYSLOG_ENABLE
|
#ifdef SYSLOG_ENABLE
|
||||||
//debugSerial<<"debugSerial:";
|
//debugSerial<<"debugSerial:";
|
||||||
delay(100);
|
delay(100);
|
||||||
if (udpSyslogArr && (n = aJson.getArraySize(udpSyslogArr))) {
|
if (udpSyslogArr && (n = aJson.getArraySize(udpSyslogArr))) {
|
||||||
char *syslogServer = aJson.getArrayItem(udpSyslogArr, 0)->valuestring;
|
char *syslogServer = getStringFromConfig(udpSyslogArr, 0);
|
||||||
if (n>1) syslogPort = aJson.getArrayItem(udpSyslogArr, 1)->valueint;
|
if (n>1) syslogPort = getStringFromConfig(udpSyslogArr, 1);
|
||||||
|
|
||||||
inet_ntoa_r(Ethernet.localIP(),syslogDeviceHostname,sizeof(syslogDeviceHostname));
|
inet_ntoa_r(Ethernet.localIP(),syslogDeviceHostname,sizeof(syslogDeviceHostname));
|
||||||
/*
|
/*
|
||||||
@@ -555,11 +578,11 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
|||||||
|
|
||||||
if (!mqttClient.connected() && mqttArr && ((n = aJson.getArraySize(mqttArr)) > 1)) {
|
if (!mqttClient.connected() && mqttArr && ((n = aJson.getArraySize(mqttArr)) > 1)) {
|
||||||
// char *client_id = aJson.getArrayItem(mqttArr, 0)->valuestring;
|
// char *client_id = aJson.getArrayItem(mqttArr, 0)->valuestring;
|
||||||
char *servername = aJson.getArrayItem(mqttArr, 1)->valuestring;
|
char *servername = getStringFromConfig(mqttArr, 1);
|
||||||
if (n >= 3) port = aJson.getArrayItem(mqttArr, 2)->valueint;
|
if (n >= 3) port = getStringFromConfig(mqttArr, 2);
|
||||||
if (n >= 4) user = aJson.getArrayItem(mqttArr, 3)->valuestring;
|
if (n >= 4) user = getStringFromConfig(mqttArr, 3);
|
||||||
if (!loadFlash(OFFSET_MQTT_PWD, passwordBuf, sizeof(passwordBuf)) && (n >= 5)) {
|
if (!loadFlash(OFFSET_MQTT_PWD, passwordBuf, sizeof(passwordBuf)) && (n >= 5)) {
|
||||||
password = aJson.getArrayItem(mqttArr, 4)->valuestring;
|
password = getStringFromConfig(mqttArr, 4);
|
||||||
debugSerial<<F("Using MQTT password from config");
|
debugSerial<<F("Using MQTT password from config");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -792,7 +815,7 @@ void Changed(int i, DeviceAddress addr, float currentTemp) {
|
|||||||
debugSerial<<endl<<F("T:")<<valstr<<F("<");
|
debugSerial<<endl<<F("T:")<<valstr<<F("<");
|
||||||
aJsonObject *owObj = aJson.getObjectItem(owArr, addrstr);
|
aJsonObject *owObj = aJson.getObjectItem(owArr, addrstr);
|
||||||
if (owObj) {
|
if (owObj) {
|
||||||
owEmitString = aJson.getObjectItem(owObj, "emit")->valuestring;
|
owEmitString = getStringFromConfig(owObj, "emit");
|
||||||
debugSerial<<owEmitString<<F(">")<<endl;
|
debugSerial<<owEmitString<<F(">")<<endl;
|
||||||
if ((currentTemp != -127.0) && (currentTemp != 85.0) && (currentTemp != 0.0))
|
if ((currentTemp != -127.0) && (currentTemp != 85.0) && (currentTemp != 0.0))
|
||||||
{
|
{
|
||||||
@@ -801,7 +824,7 @@ void Changed(int i, DeviceAddress addr, float currentTemp) {
|
|||||||
|
|
||||||
#ifdef WITH_DOMOTICZ
|
#ifdef WITH_DOMOTICZ
|
||||||
aJsonObject *idx = aJson.getObjectItem(owObj, "idx");
|
aJsonObject *idx = aJson.getObjectItem(owObj, "idx");
|
||||||
if (idx && idx->valuestring) {//DOMOTICZ json format support
|
if (idx && && idx->type ==aJson_String && idx->valuestring) {//DOMOTICZ json format support
|
||||||
debugSerial << endl << idx->valuestring << F(" Domoticz valstr:");
|
debugSerial << endl << idx->valuestring << F(" Domoticz valstr:");
|
||||||
char valstr[50];
|
char valstr[50];
|
||||||
sprintf(valstr, "{\"idx\":%s,\"svalue\":\"%.1f\"}", idx->valuestring, currentTemp);
|
sprintf(valstr, "{\"idx\":%s,\"svalue\":\"%.1f\"}", idx->valuestring, currentTemp);
|
||||||
@@ -819,7 +842,7 @@ void Changed(int i, DeviceAddress addr, float currentTemp) {
|
|||||||
mqttClient.publish(addrstr, valstr);
|
mqttClient.publish(addrstr, valstr);
|
||||||
}
|
}
|
||||||
// And translate temp to internal items
|
// And translate temp to internal items
|
||||||
owItem = aJson.getObjectItem(owObj, "item")->valuestring;
|
owItem = getStringFromConfig(owObj, "item");
|
||||||
if (owItem)
|
if (owItem)
|
||||||
thermoSetCurTemp(owItem, currentTemp); ///TODO: Refactore using Items interface
|
thermoSetCurTemp(owItem, currentTemp); ///TODO: Refactore using Items interface
|
||||||
} // if valid temperature
|
} // if valid temperature
|
||||||
|
|||||||
@@ -396,11 +396,11 @@ if (topics && topics->type == aJson_Object)
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if (_root) strncpy(buf,_root->valuestring,buflen);
|
if (_root && _root->type == aJson_String) strncpy(buf,_root->valuestring,buflen);
|
||||||
else strncpy_P(buf,homeTopic,buflen);
|
else strncpy_P(buf,homeTopic,buflen);
|
||||||
strncat(buf,"/",buflen);
|
strncat(buf,"/",buflen);
|
||||||
|
|
||||||
if (_l2) strncat(buf,_l2->valuestring,buflen);
|
if (_l2 && _l2->type == aJson_String) strncat(buf,_l2->valuestring,buflen);
|
||||||
else
|
else
|
||||||
switch (tt) {
|
switch (tt) {
|
||||||
case T_DEV:
|
case T_DEV:
|
||||||
|
|||||||
Reference in New Issue
Block a user