|
|
@@ -87,24 +87,11 @@ void MqttClient::handleClient() {
|
|
|
}
|
|
|
|
|
|
void MqttClient::sendUpdate(const MiLightRemoteConfig& remoteConfig, uint16_t deviceId, uint16_t groupId, const char* update) {
|
|
|
- String topic = settings.mqttUpdateTopicPattern;
|
|
|
-
|
|
|
- if (topic.length() == 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- String deviceIdStr = String(deviceId, 16);
|
|
|
- deviceIdStr.toUpperCase();
|
|
|
-
|
|
|
- topic.replace(":device_id", String("0x") + deviceIdStr);
|
|
|
- topic.replace(":group_id", String(groupId));
|
|
|
- topic.replace(":device_type", remoteConfig.name);
|
|
|
-
|
|
|
-#ifdef MQTT_DEBUG
|
|
|
- printf_P(PSTR("MqttClient - publishing update to %s: %s\n"), topic.c_str(), update);
|
|
|
-#endif
|
|
|
+ publish(settings.mqttUpdateTopicPattern, remoteConfig, deviceId, groupId, update);
|
|
|
+}
|
|
|
|
|
|
- mqttClient->publish(topic.c_str(), update);
|
|
|
+void MqttClient::sendState(const MiLightRemoteConfig& remoteConfig, uint16_t deviceId, uint16_t groupId, const char* update) {
|
|
|
+ publish(settings.mqttStateTopicPattern, remoteConfig, deviceId, groupId, update);
|
|
|
}
|
|
|
|
|
|
void MqttClient::subscribe() {
|
|
|
@@ -121,6 +108,27 @@ void MqttClient::subscribe() {
|
|
|
mqttClient->subscribe(topic.c_str());
|
|
|
}
|
|
|
|
|
|
+void MqttClient::publish(const String& _topic, const MiLightRemoteConfig &remoteConfig, uint16_t deviceId, uint16_t groupId, const char* message) {
|
|
|
+ if (_topic.length() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String topic = _topic;
|
|
|
+
|
|
|
+ String deviceIdStr = String(deviceId, 16);
|
|
|
+ deviceIdStr.toUpperCase();
|
|
|
+
|
|
|
+ topic.replace(":device_id", String("0x") + deviceIdStr);
|
|
|
+ topic.replace(":group_id", String(groupId));
|
|
|
+ topic.replace(":device_type", remoteConfig.name);
|
|
|
+
|
|
|
+#ifdef MQTT_DEBUG
|
|
|
+ printf_P(PSTR("MqttClient - publishing update to %s: %s\n"), topic.c_str(), update);
|
|
|
+#endif
|
|
|
+
|
|
|
+ mqttClient->publish(topic.c_str(), message);
|
|
|
+}
|
|
|
+
|
|
|
void MqttClient::publishCallback(char* topic, byte* payload, int length) {
|
|
|
uint16_t deviceId = 0;
|
|
|
uint8_t groupId = 0;
|