From 82fbc7be4365d9e5854b2e32fadb3a2234d24f9d Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Wed, 19 Jun 2019 22:27:33 +0200 Subject: [PATCH] MQTT: Small fixes. Most notably, MQTT_TOPIC/status will now contain hostname and IP of pitrix. --- src/mqtt.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/mqtt.cpp b/src/mqtt.cpp index a7d77a3..f3bac73 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -58,7 +58,12 @@ void mqtt_callback(char* original_topic, byte* pl, unsigned int length) { if(topic.compareTo("mode")==0) { LOGln("MQTT * Changing mode..."); - change_current_effect(payload); + bool result = change_current_effect(payload); + if (result) { + LOGln("MQTT * Effect changed."); + } else { + LOGln("MQTT * Could not change effect."); + } return; } else if (topic.compareTo("reboot")==0) { LOGln("MQTT * Rebooting"); @@ -85,10 +90,12 @@ void mqtt_callback(char* original_topic, byte* pl, unsigned int length) { } boolean mqtt_connect() { - LOG("MQTT * Connecting to MQTT server with client id %s", hostname); + LOGln("MQTT * Connecting to MQTT server with client id %s", hostname); if (mqtt_client.connect(hostname, MQTT_USER, MQTT_PASS, MQTT_TOPIC "status", 0, true, "OFFLINE", true)) { LOGln("MQTT * Connected."); - mqtt_client.publish(MQTT_TOPIC "status", "ONLINE", true); + char buffer[40]; + snprintf(buffer, 40, "ONLINE %s %s", hostname, WiFi.localIP().toString().c_str()); + mqtt_client.publish(MQTT_TOPIC "status", buffer, true); mqtt_client.subscribe(MQTT_TOPIC "+"); mqtt_client.subscribe(MQTT_TOPIC_WEATHER "#"); }