I built a simple controller to turn on and off some LED’s and turn on a smoke generator for my sisters hobbies. It worked here at my home while I developed it just fine. I could turn on or off the LED’s and the smoke gnerator at will. The thing would reconnect perhaps once or twice in a few days of testing. I then shared the app with my Sister who is in another state. She was able to control it from her phone while the unit was powered and operating from my home. Seems to be working just fine.
Well I packaged the hardware up and sent it to my sister. She hooked up power and turned it on. It was configured for her WiFi router and password. Now it does show connected for about a second or two then immediately show disconnected. Does this in a lop over and over. We can not control the LED’s or the smoke generator while it is temporarily online. Any suggestions as the code I used was fairly generic? See below.
#define BLYNK_PRINT Serial
//#if defined(ESP8266)
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
#include <BlynkSimpleEsp8266.h>
//#else
//#include <WiFi.h> //https://github.com/esp8266/Arduino
//#include <BlynkSimpleEsp32.h>
//#endif
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxxxxxxxxxxxxxx";
char pass[] = "yyyyyyyyyyyyyyy";
int lastConnectionAttempt = millis();
int connectionDelay = 5000; // try to reconnect every 5 seconds
void setup()
{
// Debug console
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
// check WiFi connection:
if (WiFi.status() != WL_CONNECTED)
{
// check delay:
if (millis() - lastConnectionAttempt >= connectionDelay)
{
lastConnectionAttempt = millis();
// attempt to connect to Wifi network:
if (pass && strlen(pass))
{
Serial.println("Lost connections. Trying to reconnect...");
WiFi.begin((char*)ssid, (char*)pass);
}
else
{
Serial.println("Lost connections. Trying to reconnect...");
WiFi.begin((char*)ssid);
}
}
}
else
{
Blynk.run();
}
}