Help before I spend time rewriting

Hi,

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?

Thanks

Chris

afaik, this is doable. however, not beginner stuff.
@Lichtsignaal or @PeteKnight maybe have more experience with this setup.

also, search the forum for keywords like: client and server on the same hardware raspberry

The real solution is to fix your Wi-Fi instability problems.

Pete.

2 Likes

Stability with Arduino Mega and ESP (ESP-01 in my case) is fully doable :wink:

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 :smiley:

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
  }
}
1 Like

Yes, you can run the USB script in the background using common Linux method.

Simplest is the just add the ampersand “&” (without quotes) behind a command line. This will run it in the background.

Combine it with crontab to run at boot or as a system.d service for a more convenient solution (last one is prefered: https://www.raspberrypi.org/documentation/linux/usage/systemd.md )

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?

Thanks

Chris

No, As shown above, my Arduino Mega works just fine :slight_smile:

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()

Hmm no I compiled fine, connected to WiFi fine and I could ping correctly, config worked but then connect never connected.

Let me have another go with that code and I’ll post it once I’ve recovered from the various commented out sections of code :grin:

Thanks again for the help

So I’ve dug out my previous code and managed to get it to work now thanks to the help on this thread especially from Gunner.

I think the mistake I was making was trying to connect WiFi then doing blynk config and connect. This always failed.

Switching it to do config, connect WiFi then blynk connect seems to have worked so far.

Now I need to revive my reconnection code and see what happens.

I apologise in advance if I have to come back for help but I’ve got further today than in the last 3 weeks !

1 Like