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:
1 parent
ca3bc436ee
commit
347783a1c4
2 files changed
+23
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user