Handling WiFi connection for a mobile project

I'm working on a project where an ESP8266 in installed in a car. The handling of the WiFi is where I am unsure. When the car is at home, it's within the WiFi range. Of course when it drives away it is not.

Reading this useful guide by randomnerd, not sure if I can just handle it like the example:

void initWiFi() {
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.print("Connecting to WiFi ..");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(1000);
  }
  Serial.println(WiFi.localIP());
  WiFi.setAutoReconnect(true);
  WiFi.persistent(true);
}

and have a check function called regularly from loop that would be similar to :

if (WiFi.status() != WL_CONNECTED) {
bool home = false
} else {
bool home = true 
}

Or alternatively:

When the car leaves home (often away for many hours) , is it necessary/good practice to call WiFi.disconnect() ?

And when car is away from WiFi , should I call WiFi.begin(ssid, password); continously until reconnected? Or could be done at intervals of say 10 mins. Being car based it runs off the large 12V battery, so not really going to run it flat pulling only ~100mA max., but still seems not good.

Welcome any advice regarding the myriad of WiFi options!
Thanks

Probably not, otherwise you won't register if you're at home again.

The AutoReconnect setting should handle that. Did you have problems with that?

Actually auto reconnect seems to work fine. Not sure why is was worrying :blush:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.