|
|
@ -44,44 +44,44 @@ int relayToIdx(unsigned int relayID) { |
|
|
|
return getSetting(buffer).toInt(); |
|
|
|
} |
|
|
|
|
|
|
|
void domoticzSetup() { |
|
|
|
|
|
|
|
mqttRegister([](unsigned int type, const char * topic, const char * payload) { |
|
|
|
|
|
|
|
String dczTopicOut = getSetting("dczTopicOut", DOMOTICZ_OUT_TOPIC); |
|
|
|
void _domoticzMqtt(unsigned int type, const char * topic, const char * payload) { |
|
|
|
|
|
|
|
if (type == MQTT_CONNECT_EVENT) { |
|
|
|
mqttSubscribeRaw(dczTopicOut.c_str()); |
|
|
|
} |
|
|
|
String dczTopicOut = getSetting("dczTopicOut", DOMOTICZ_OUT_TOPIC); |
|
|
|
|
|
|
|
if (type == MQTT_MESSAGE_EVENT) { |
|
|
|
if (type == MQTT_CONNECT_EVENT) { |
|
|
|
mqttSubscribeRaw(dczTopicOut.c_str()); |
|
|
|
} |
|
|
|
|
|
|
|
// Check topic
|
|
|
|
if (dczTopicOut.equals(topic)) { |
|
|
|
if (type == MQTT_MESSAGE_EVENT) { |
|
|
|
|
|
|
|
// Parse response
|
|
|
|
DynamicJsonBuffer jsonBuffer; |
|
|
|
JsonObject& root = jsonBuffer.parseObject((char *) payload); |
|
|
|
if (!root.success()) { |
|
|
|
DEBUG_MSG_P(PSTR("[DOMOTICZ] Error parsing data\n")); |
|
|
|
return; |
|
|
|
} |
|
|
|
// Check topic
|
|
|
|
if (dczTopicOut.equals(topic)) { |
|
|
|
|
|
|
|
// IDX
|
|
|
|
unsigned long idx = root["idx"]; |
|
|
|
int relayID = relayFromIdx(idx); |
|
|
|
if (relayID >= 0) { |
|
|
|
unsigned long value = root["nvalue"]; |
|
|
|
DEBUG_MSG_P(PSTR("[DOMOTICZ] Received value %d for IDX %d\n"), value, idx); |
|
|
|
relayStatus(relayID, value == 1); |
|
|
|
} |
|
|
|
// Parse response
|
|
|
|
DynamicJsonBuffer jsonBuffer; |
|
|
|
JsonObject& root = jsonBuffer.parseObject((char *) payload); |
|
|
|
if (!root.success()) { |
|
|
|
DEBUG_MSG_P(PSTR("[DOMOTICZ] Error parsing data\n")); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// IDX
|
|
|
|
unsigned long idx = root["idx"]; |
|
|
|
int relayID = relayFromIdx(idx); |
|
|
|
if (relayID >= 0) { |
|
|
|
unsigned long value = root["nvalue"]; |
|
|
|
DEBUG_MSG_P(PSTR("[DOMOTICZ] Received value %d for IDX %d\n"), value, idx); |
|
|
|
relayStatus(relayID, value == 1); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
void domoticzSetup() { |
|
|
|
mqttRegister(_domoticzMqtt); |
|
|
|
} |
|
|
|
|
|
|
|
#endif
|