mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 19:59:50 +03:00
More control and relability
This commit is contained in:
@@ -11,22 +11,33 @@ int abstractIn::publish(int value, char* subtopic)
|
||||
{
|
||||
char valstr[16];
|
||||
printUlongValueToStr(valstr, value);
|
||||
publish(valstr,subtopic);
|
||||
return publish(valstr,subtopic);
|
||||
};
|
||||
|
||||
int abstractIn::publish(float value, char* subtopic)
|
||||
{
|
||||
char valstr[16];
|
||||
printFloatValueToStr(value, valstr);
|
||||
publish(valstr,subtopic);
|
||||
return publish(valstr,subtopic);
|
||||
};
|
||||
|
||||
int abstractIn::publish(char * value, char* subtopic)
|
||||
{
|
||||
char addrstr[MQTT_TOPIC_LENGTH];
|
||||
if (in)
|
||||
{
|
||||
aJsonObject *emit = aJson.getObjectItem(in->inputObj, "emit");
|
||||
strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
||||
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
||||
strncat(addrstr,subtopic,sizeof(addrstr));
|
||||
if (mqttClient.connected()) mqttClient.publish(addrstr, value, true);
|
||||
if (emit)
|
||||
{
|
||||
strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
||||
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
||||
strncat(addrstr,subtopic,sizeof(addrstr));
|
||||
if (mqttClient.connected())
|
||||
{
|
||||
mqttClient.publish(addrstr, value, true);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user