Intermittent WiFi reconnection problem

  1. My goal is: In case my internet connection goes down and comes back again, I want my device to re connect.
  2. My actions are: I have properly configured WiFi and I device token properly. Once I started the device I could see it online in mDash. I have tested it using couple of scenarios.
  • I disconnected wifi router power supply for 30 minutes and then powered it on, as soon as this happened, NodeMCU blinked for few seconds and then it got reconnected properly
  • I kept router powered on and disconnected the LAN cable so that there was only WiFi connection but no internet, and after this I again reconnected LAN cable and again after some time NodeMCU got back online again.
    I have defined sta configuration in mos.yml as follows.
  • [“wifi.sta.ssid”, “ssid”]
    • [“wifi.sta.pass”, “pass”]
    • [“sys.tz_spec”, “UCT-5:30”]
    • [“dash.enable”, true]
    • [“dash.token”, “my token here”]

“sta_connect_timeout”: 30 (This was generated in conf0.json )

  1. The result I see is: NodeMCU got offline suddenly after some time and its trying to reconnect to WiFi, however, it is not able to connect even though there is a stable internet connection now.
  2. My expectation & question is: I expect NodeMCU to try reconnecting as soon as it gets disconnected from network. Do I need to configure something else? What can I do to keep my NodeMCU connected to internet as soon as it is available? I do not want to restart or reset NodeMCU manually.

Could you clarify what app, what version are you using please?

I am using latest mos.exe downloaded from mongoose os website. Below is my code

load('api_dash.js');
load('api_events.js');
load('api_gpio.js');
load('api_timer.js');
load('api_blynk.js');

let relay = 4;

GPIO.setup_output(relay, 1)

function waterGarden(arg, cronId){
  openSolenoid();
  Timer.set(120000, 0, function(){
    closeSolenoid();
  }, null);  

}

function openSolenoid(){
  GPIO.write(relay, 0);  
}

function closeSolenoid(){
  GPIO.write(relay, 1);
}

let cronAdd = ffi('int mgos_cron_add(char*, void (*)(userdata, int),userdata)');
cronAdd("0 * * * *", waterGarden, null);

Thank you.

So in the scenario 2, the WiFi connection is not lost, but the backend connection was. Please mos config-set debug.level=3 followed by mos console, and capture the console logs. Upload the console logs somewhere (e.g. pastebin.com) and share the link.