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