From 02efa8bf24619ccaf03145028f79a5ca48173b9b Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Fri, 20 Jan 2023 10:30:46 +0300 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=20=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=BF=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BF=D1=80=D0=B8=20=D1=80=D0=B0=D0=B7=D1=80?= =?UTF-8?q?=D1=8B=D0=B2=D0=B5=20=D1=81=D0=BE=D0=B5=D0=B4=D0=B8=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c4ab566..031dc25 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -67,6 +67,7 @@ void reconnect(); void mqtt_callback(char *topic, byte *payload, unsigned int length); void mqtt_publish_config(); void mqtt_publish_state(); +void mqtt_subscribe_to_commands(); float temp; float hum; @@ -81,10 +82,6 @@ void setup() setup_wifi(); setup_time(); setup_mqtt(); - - mqtt_publish_config(); - delay(100); - mqtt_publish_state(); } void loop() @@ -171,9 +168,6 @@ void setup_mqtt() { reconnect(); } - - client.subscribe("homeassistant/status"); - halight.subscribeToCommandTopic(); } void reconnect() @@ -195,6 +189,13 @@ void reconnect() delay(5000); } } + + client.subscribe("homeassistant/status"); + mqtt_publish_config(); + delay(100); + mqtt_publish_state(); + delay(100); + mqtt_subscribe_to_commands(); } void mqtt_callback(char *topic, byte *payload, unsigned int length) @@ -225,4 +226,9 @@ void mqtt_publish_config() void mqtt_publish_state() { halight.sendState(); +} + +void mqtt_subscribe_to_commands() +{ + halight.subscribeToCommandTopic(); } \ No newline at end of file