Fix pilight value as subject (#752)

* feat: pilight gateway now send value

* feat: when device id is empty, try fo find it from the message payload
This commit is contained in:
Charles R authored and GitHub committed 2020-09-02 16:46:37 -05:00
1 parent ca3bc436ee
commit 347783a1c4
2 files changed
+23

No files matched your search

+16
View File
@@ -47,6 +47,22 @@ void pilightCallback(const String& protocol, const String& message, int status,
RFPiLightdata.set("message", msg);
RFPiLightdata.set("protocol", (char*)protocol.c_str());
RFPiLightdata.set("length", (char*)deviceID.c_str());
const char* device_id = deviceID.c_str();
if (!strlen(device_id)) {
// deviceID returned from Pilight is only extracted from id field
// but some device may use another name as unique identifier
char* choices[] = {"key", "unit", "systemcode", "unitcode", "programcode"};
for (uint8_t i = 0; i < 5; i++) {
if (msg[choices[i]]) {
device_id = (const char*)msg[choices[i]];
break;
}
}
}
RFPiLightdata.set("value", device_id);
RFPiLightdata.set("repeats", (int)repeats);
RFPiLightdata.set("status", (int)status);
pub(subjectPilighttoMQTT, RFPiLightdata);
+7
View File
@@ -253,10 +253,17 @@ void pub(char* topicori, JsonObject& data) {
if (client.connected()) {
String topic = String(mqtt_topic) + String(topicori);
#ifdef valueAsASubject
# ifdef ZgatewayPilight
String value = data["value"];
if (value != 0) {
topic = topic + "/" + value;
}
# else
SIGNAL_SIZE_UL_ULL value = data["value"];
if (value != 0) {
topic = topic + "/" + String(value);
}
# endif
#endif
#ifdef jsonPublishing