Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By andre_teprom
#71056 I am doing a project of a vending machine system on which the main task is obviously to count the coins, but whenever the wireless connection is lost, the system keep blocked in a closed loop. I'm using the standard template present at the Webserver sketch:

Code: Select all  while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print (".");
      }


I've thinking of using I/O interrupt in order to provide a quick call to the counting routine, or even exit the loop and return again, skipping a new attempt to reconnect if it is done. I mean: To instantiate the WiFi.status() just once, but seems like wont work.

Does anyone have faced to a similar issue, or have some insight on how to solve that ?
Last edited by andre_teprom on Sun Oct 22, 2017 10:48 am, edited 1 time in total.
User avatar
By andre_teprom
#71077
Code: Select allvoid _wifiDisconnectHandler(const WiFiEventStationModeDisconnected& event){
// cleanup etc, prepare for re-connect
}


Ok, but the problem is what is within this event handler.
The only way I'm aware to restart wifi connection is by calling the WiFi.status() != WL_CONNECTED) loop.
User avatar
By rudy
#71080
andre_teprom wrote:The only way I'm aware to restart wifi connection is by calling the WiFi.status() != WL_CONNECTED) loop.

If you read the documentation you will find your answer.

http://arduino-esp8266.readthedocs.io/e ... mples.html

The process of connection, disconnection and printing messages is done in background



Code: Select all#include <ESP8266WiFi.h>

const char* ssid = "********";
const char* password = "********";

WiFiEventHandler gotIpEventHandler, disconnectedEventHandler;

bool ledState;


void setup()
{
  Serial.begin(115200);
  Serial.println();

  pinMode(LED_BUILTIN, OUTPUT);

  gotIpEventHandler = WiFi.onStationModeGotIP([](const WiFiEventStationModeGotIP& event)
  {
    Serial.print("Station connected, IP: ");
    Serial.println(WiFi.localIP());
  });

  disconnectedEventHandler = WiFi.onStationModeDisconnected([](const WiFiEventStationModeDisconnected& event)
  {
    Serial.println("Station disconnected");
  });

  Serial.printf("Connecting to %s ...\n", ssid);
  WiFi.begin(ssid, password);
}


void loop()
{
  digitalWrite(LED_BUILTIN, ledState);
  ledState = !ledState;
  delay(250);
}