фикс переподключения при разрыве соединения

This commit is contained in:
Maxim Slipenko 2023-01-20 10:30:46 +03:00
parent a9e13b78c5
commit 02efa8bf24

View File

@ -67,6 +67,7 @@ void reconnect();
void mqtt_callback(char *topic, byte *payload, unsigned int length); void mqtt_callback(char *topic, byte *payload, unsigned int length);
void mqtt_publish_config(); void mqtt_publish_config();
void mqtt_publish_state(); void mqtt_publish_state();
void mqtt_subscribe_to_commands();
float temp; float temp;
float hum; float hum;
@ -81,10 +82,6 @@ void setup()
setup_wifi(); setup_wifi();
setup_time(); setup_time();
setup_mqtt(); setup_mqtt();
mqtt_publish_config();
delay(100);
mqtt_publish_state();
} }
void loop() void loop()
@ -171,9 +168,6 @@ void setup_mqtt()
{ {
reconnect(); reconnect();
} }
client.subscribe("homeassistant/status");
halight.subscribeToCommandTopic();
} }
void reconnect() void reconnect()
@ -195,6 +189,13 @@ void reconnect()
delay(5000); 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) void mqtt_callback(char *topic, byte *payload, unsigned int length)
@ -226,3 +227,8 @@ void mqtt_publish_state()
{ {
halight.sendState(); halight.sendState();
} }
void mqtt_subscribe_to_commands()
{
halight.subscribeToCommandTopic();
}