Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. void keeplive(){
  2.     check=0;
  3.  
  4.   if((millis() - wifi_reconnect_time) > wifi_check_time){//se sono passati piu x secondi dall ultimo controllo
  5.     DEBUG_PRINT("Controllo WiFi");
  6.     smartDebug();
  7.     wifi_reconnect_time = millis(); //questo รจ il tempo dell'ultimo controllo
  8.     if(WiFi.isConnected()) {
  9.       wifi_check_time = 15000L; //se sono connesso,controllo ogni 15 secondi che la connessione ci sia
  10.     }else { //se non connesso cerca di connettere e collegarti a MQTT
  11.       check=connectWiFi();
  12.       delay(1000);
  13.     }
  14.     smartDelay(100);
  15.     client.loop();
  16.     if (client.connected()==0){ //MQTT non รจ collegato 0 = f
  17.       //DEBUG_PRINT("MQTT KO!! " + String(client.connected()));
  18.       mqtt_reconnect_tries++;
  19.       smartDelay(100);
  20.       connectMQTTmia();
  21.       //resub();
  22.       //reconnect();
  23.     }
  24.     else {
  25.       mqtt_reconnect_tries=0; //se collegato azzero
  26.       DEBUG_PRINT("MQTT OK!!");
  27.     }
  28.     if(mqtt_reconnect_tries > 3){
  29.       wifi_check_time = 300000L;
  30.       smartDelay(100);
  31.       spegniChr();
  32.     }
  33.   }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement