@@ -148,7 +148,7 @@ long lastScheduleTime5000 = millis();
148148int count = 0 ;
149149const char *user = (&C.mqtt.user)->c_str ();
150150const char *pass = (&C.mqtt.pass)->c_str ();
151- const char *host = (&C.mqtt.host)-> c_str () ;
151+ String mqttHost = " " ;
152152
153153WiFiClient espClient;
154154PubSubClient client (espClient);
@@ -182,6 +182,8 @@ void setup()
182182 .init ();
183183
184184 uint16_t port = (uint16_t )C.mqtt .port ;
185+ const char *host = (&C.mqtt .host )->c_str ();
186+ mqttHost = String (host);
185187 Serial.println (host);
186188 Serial.println (port);
187189 Serial.println (user);
@@ -211,12 +213,14 @@ boolean reconnect()
211213 client.subscribe (node_temperature_set_topic);
212214 client.subscribe (node_mode_set_topic);
213215
214- client.publish (node_toast, (String (node_heart_topic) + ' ,'
215- + String (node_study_topic) + ' ,'
216- + String (node_fan_set_topic) + ' ,'
217- + String (node_swing_set_topic) + ' ,'
218- + String (node_temperature_set_topic) + ' ,'
219- + String (node_mode_set_topic)).c_str ());
216+ client.publish (node_toast, node_heart_topic);
217+
218+ Serial.println (node_study_topic);
219+ Serial.println (node_fan_set_topic);
220+ Serial.println (node_swing_set_topic);
221+ Serial.println (node_temperature_set_topic);
222+ Serial.println (node_mode_set_topic);
223+
220224 }
221225 delay (100 );
222226 return client.connected ();
@@ -366,6 +370,7 @@ boolean downLoadFile(int index_id)
366370 http.writeToStream (filestream);
367371 SERIAL_DEBUG.printf (" download %s ok\n " , filename.c_str ());
368372 flag = true ;
373+ client.publish (node_toast, " download is ok" );
369374 }
370375 else
371376 {
@@ -379,6 +384,8 @@ boolean downLoadFile(int index_id)
379384 return flag;
380385}
381386bool netRestart = false ;
387+ const long lastUnConnectTime = millis();
388+ const long min_5 = 1000 * 60 * 5 ;
382389void loop ()
383390{
384391
@@ -392,11 +399,19 @@ void loop()
392399 }
393400 else
394401 {
402+
403+ delay (500 );
395404 if (netRestart)
396405 {
397406 ESP.restart ();
407+ return ;
398408 }
399- delay (500 );
409+
410+ if (millis () - lastUnConnectTime > min_5) {
411+ ESP.restart ();
412+ return ;
413+ }
414+
400415 Serial.println (" Wifi is not connect" );
401416 }
402417}
@@ -451,7 +466,7 @@ void callback(char *topic, byte *payload, unsigned int length)
451466 root[" wifi_ssid" ] = &C.wifi .ssid ;
452467 root[" wifi_user" ] = &C.wifi .password ;
453468
454- root[" mtqq_ip" ] = host ;
469+ root[" mtqq_ip" ] = mqttHost ;
455470 root[" mtqq_user" ] = user;
456471 root[" mtqq_pass" ] = pass;
457472
0 commit comments