No connect to WiFi when using SimpleTimer.h

AndonProject
Posts: 3
Joined: Wed Dec 06, 2017 9:29 am

No connect to WiFi when using SimpleTimer.h

Postby AndonProject » Wed Dec 06, 2017 9:39 am

Dear Community

For my project I am using an ESP32 to connect to a WLAN network for communicating using MQTT.
The program offers several features. It worked fine, except when I included some program code for buzzering. To make the noise more comfortable I used two timers to let it sound for several intervals. But when the timer is included, the WiFi network does not reconnect anymore. I googled for a day and I have not found neither a similar problem nor an answer for that.
I am using following libraries:

Code: Select all

/* Libraries */
#include <WiFi.h>
#include <MQTTClient.h>
#include <ArduinoOTA.h>
#include "Arduino.h"
#include <SimpleTimer.h>
Furthermore, I started a timer in the setup and disabled it afterwards, because I only need the timer when I get a callback from the MQTT broker. I thought it is not smart to define a new timer everytime one is needed.
I used for connecting to WiFi the example code provided. For reconnecting I adapt to following code which is called in the loop().

Code: Select all

void loopWiFi()
{
  if(WiFi.status() != WL_CONNECTED)
  {
    WiFi.disconnect(true);
    delay(2000);
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    int numOfTries = 0;
    while(WiFi.status() != WL_CONNECTED)
    {
      delay(500);
      numOfTries++;
      if(numOfTries>10)
      {
        #if SERIAL_ENABLE
          Serial.println("WiFi not connected after 10 attempts!");
        #endif
        break;
      }
    }
  }
  return;
}
Have you got any experiences with this issue?

Thanks
AndonProject

Who is online

Users browsing this forum: No registered users and 34 guests