I have tried for many weeks to get a stable connection using an Arduino mega and eso8266 as a shield and have finally decided that it can’t be stable enough for me. I have used bkynk.begin, config etc but nothing prevents it eventually dropping and hanging.
I’m using a local server and I’m pretty sure that .y problems are mainly instability in my local network and WiFi.
I have searched on the below but been unable to find an answer.
If I am using a raspberry pi as a local server. Can I also run the usb script on the raspberry pi to avoid using the esp8266 and WiFi at all.
Will the usb script recognise that the server is running on the same device as the usb script and not send data to the router?
This is what happens when I am busy with other projects and don’t keep reloading new additions to my testbench… it actually gets to stay running on it’s own
I use this for connection
char auth[] = "xxxxxxxxxx"; // Local Server
//char auth[] = "xxxxxxxxxx"; // Cloud Server
char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxxxx";
char server[] = "xxx.xxx.xxx.xxx";
// char server[] = "blynk-cloud.com";
int port = 8080;
And in void setup()
wifi.setDHCP(1, 1, 1); //Enable dhcp in station mode and save in flash of esp8266
Blynk.config(wifi, auth, server, port);
if (Blynk.connectWiFi(ssid, pass)) {
Blynk.connect();
}
And my reconnection routine is a bit complex with notifications… but this is the jist of it
void loop() {
timer.run();
CNTR++; // Loop/second counter for App display
digitalWrite(HTB, !digitalRead(HTB)); // heartbeat LED
if (Blynk.connected()) { // If connected run as normal
Blynk.run();
} else if (ReCnctFlag == 0) { // If NOT connected and not already tring to reconnect, set timer to try to reconnect in 60 seconds
ReCnctFlag = 1; // Set reconnection Flag
Serial.println("Starting reconnection timer in 30 seconds...");
timer.setTimeout(30000L, []() { // Lambda Reconnection Timer Function
ReCnctFlag = 0; // Reset reconnection Flag
ReCnctCount++; // Increment reconnection Counter
Serial.print("Attempting reconnection #");
Serial.println(ReCnctCount);
wifi.setDHCP(1, 1, 1); //Enable dhcp in station mode and save in flash of esp8266
Blynk.config(wifi, auth, server, port);
Blynk.connect(); // Try to reconnect to the server
if (Blynk.connectWiFi(ssid, pass)) {
Blynk.connect();
}
}); // END Timer Function
}
}
Hi Gunner, thanks to all for the responses. When I used Blynk config I had a very similar looking routine to the one gunner poster but I couldn’t get Blynk.connect to work for me. Just failed and passed through disconnected.
I did read on one of the community threads that blynk config and connect don’t work so well on a mega.
I know my WiFi connected ok as prior to calling blynk connect I had it ping an external site successfully.
Am I right it’s a problem with mega and blynk connect?
No, As shown above, my Arduino Mega works just fine
If I recall correctly… there was some compiling issues with Arduinos running the Blynk.config() command. Or more accurately the command not compiling with the #include <BlynkSimpleShieldEsp8266.h> library. But somewhere along the line that seems to have changed, without fanfare.
And as for using the USB link with RPi… never tried, but I suspect, as already mentioned, that using the Linux script should work fine.
But then you need to use this library instead: #include <BlynkSimpleStream.h> and it may require use of Blynk.begin() instead of Blynk.config()