BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Buffer overflow when starting my app

Hello, I’m using an Arduino Mega with an ESP8266. It has 2 boards of 16 relays connected

I’m getting Buffer Overflow when I want to start my app on the phone (when I play the push button)
I have several Timers which I use my Virtual Pins for. Also buttons to turn my lights on and off.

I tried an empty code with only my auth, wifi, ssid and the common blynk stuff, but it keeps happening…


 #define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

// Your  WiFi credentials + Auth Token in the Blynk App.
char auth[] = "auth";
char ssid[] = "Netwerk ssid";
char pass[] = "password";

// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial3
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi
(&EspSerial);
BlynkTimer timer;
int ReCnctFlag;  // Reconnection Flag
int ReCnctCount = 0;  // Reconnection counter  

//Boven alles neer
BLYNK_WRITE(V1) { // V1 is the virtual pin that toggles this operation
if (param.asInt()==1) {
        digitalWrite(24, LOW);
        digitalWrite(28, LOW);
        digitalWrite(32, LOW);
        digitalWrite(36, LOW); 
        digitalWrite(40, LOW);
        digitalWrite(44, LOW);
        digitalWrite(48, LOW); 
        delay(500);
        digitalWrite(24, HIGH);
        digitalWrite(28, HIGH);
        digitalWrite(32, HIGH);
        digitalWrite(36, HIGH); 
        digitalWrite(40, HIGH);
        digitalWrite(44, HIGH);
        digitalWrite(48, HIGH);}}
//Boven alles hoog
BLYNK_WRITE(V2) { // V2 is the virtual pin that toggles this operation
if (param.asInt()==1) {
        digitalWrite(22, LOW);
        digitalWrite(26, LOW);
        digitalWrite(30, LOW);
        digitalWrite(34, LOW); 
        digitalWrite(38, LOW);
        digitalWrite(42, LOW);
        digitalWrite(46, LOW); 
        delay(500);  
        digitalWrite(22, HIGH);
        digitalWrite(26, HIGH);
        digitalWrite(30, HIGH);
        digitalWrite(34, HIGH); 
        digitalWrite(38, HIGH);
        digitalWrite(42, HIGH);
        digitalWrite(46, HIGH);}}
//Beneden alles neer
BLYNK_WRITE(V3) { // V3 is the virtual pin that toggles this operation
if (param.asInt()==1) {
        digitalWrite(33, LOW);
        digitalWrite(37, LOW);
        digitalWrite(41, LOW);
        digitalWrite(45, LOW);
        delay(500);
        digitalWrite(33, HIGH);
        digitalWrite(37, HIGH);
        digitalWrite(41, HIGH);
        digitalWrite(45, HIGH);   }}
//Beneden alles hoog
BLYNK_WRITE(V4) { // V1 is the virtual pin that toggles this operation
if (param.asInt()==1) {
        digitalWrite(31, LOW);
        digitalWrite(35, LOW);
        digitalWrite(39, LOW);
        digitalWrite(43, LOW); 
        delay(500);
        digitalWrite(31, HIGH);
        digitalWrite(35, HIGH);
        digitalWrite(39, HIGH);
        digitalWrite(43, HIGH);}}
//LED BUITEN
BLYNK_WRITE(V5) { // V1 is the virtual pin that toggles this operation
if (param.asInt()==1) {
        digitalWrite(5, HIGH);
        digitalWrite(7, HIGH);}}
//kleine rolluik beneden
BLYNK_WRITE(V6) { // V1 is the virtual pin that toggles this operation
if (param.asInt()==1) {
        digitalWrite(41, LOW);
        digitalWrite(45, LOW);
        delay(500);
        digitalWrite(41, HIGH);
        digitalWrite(45, HIGH);}}
//grote rolluik beneden
BLYNK_WRITE(V7) { // V1 is the virtual pin that toggles this operation
if (param.asInt()==1) {
        digitalWrite(33, LOW);
        digitalWrite(37 , LOW);
        delay(500);
        digitalWrite(33, HIGH);
        digitalWrite(37, HIGH);}}

void setup()
{ 

  // Debug console + Set ESP8266 baud rate
  Serial.begin(9600);
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);  
pinMode(0,OUTPUT);
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
pinMode(14,OUTPUT);
pinMode(15,OUTPUT);
pinMode(16,OUTPUT);
pinMode(17,OUTPUT);
pinMode(18,OUTPUT);
pinMode(19,OUTPUT);
pinMode(20,OUTPUT);
pinMode(21,OUTPUT);
pinMode(22,OUTPUT);  //badkamer omhoog
pinMode(23,OUTPUT);  
pinMode(24,OUTPUT);  //badkamer omlaag
pinMode(25,OUTPUT);
pinMode(26,OUTPUT);  //hal omhoog
pinMode(27,OUTPUT);
pinMode(28,OUTPUT);  //hal omlaag
pinMode(29,OUTPUT);
pinMode(30,OUTPUT);  //kinder voor omhoog
pinMode(31,OUTPUT);  //keuken omhoog
pinMode(32,OUTPUT);  //kinder voor omlaag
pinMode(33,OUTPUT);  //keuken omlaag
pinMode(34,OUTPUT);  //kinder zij omhoog
pinMode(35,OUTPUT);  //tafel omhoog
pinMode(36,OUTPUT);  //kinder zij omlaag
pinMode(37,OUTPUT);  //tafel omlaag
pinMode(38,OUTPUT);  //slaap zij omhoog
pinMode(39,OUTPUT);  //voorkant omhoog
pinMode(40,OUTPUT);  //slaap zij omlaag
pinMode(41,OUTPUT);  //voorkant omlaag
pinMode(42,OUTPUT);  //slaap achter omhoog
pinMode(43,OUTPUT);  //zijkant omhoog
pinMode(44,OUTPUT);  //slaap achter omlaag
pinMode(45,OUTPUT);  //zijkant omlaag
pinMode(46,OUTPUT);  //bureau omhoog
pinMode(47,OUTPUT);
pinMode(48,OUTPUT);  //bureau omlaag
pinMode(49,OUTPUT);
pinMode(50,OUTPUT);
pinMode(51,OUTPUT);
pinMode(52,OUTPUT);

digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
digitalWrite(14, HIGH);
digitalWrite(15, HIGH);
digitalWrite(16, HIGH);
digitalWrite(17, HIGH);
digitalWrite(18, HIGH);
digitalWrite(19, HIGH);
digitalWrite(20, HIGH);
digitalWrite(21, HIGH);
digitalWrite(22, HIGH);
digitalWrite(23, HIGH);
digitalWrite(24, HIGH);
digitalWrite(25, HIGH);
digitalWrite(26, HIGH);
digitalWrite(27, HIGH);
digitalWrite(28, HIGH);
digitalWrite(29, HIGH);
digitalWrite(30, HIGH);
digitalWrite(31, HIGH);
digitalWrite(32, HIGH);
digitalWrite(33, HIGH);
digitalWrite(34, HIGH);
digitalWrite(35, HIGH);
digitalWrite(36, HIGH);
digitalWrite(37, HIGH);
digitalWrite(38, HIGH);
digitalWrite(39, HIGH);
digitalWrite(40, HIGH);
digitalWrite(41, HIGH);
digitalWrite(42, HIGH);
digitalWrite(43, HIGH);
digitalWrite(44, HIGH);
digitalWrite(45, HIGH);
digitalWrite(46, HIGH);
digitalWrite(47, HIGH);
digitalWrite(48, HIGH);
digitalWrite(49, HIGH);
digitalWrite(50, HIGH);
digitalWrite(51, HIGH);
digitalWrite(52, HIGH);
}
void UpTime() {
  Blynk.virtualWrite(V0, millis() / 1000);  // Send UpTime seconds to App
  Serial.print("UpTime: ");
  Serial.println(millis() / 1000);  // Send UpTime seconds to Serial
}
void loop() {
  timer.run();

  if (Blynk.connected()) {  // If connected run as normal
    Blynk.run();
  } else if (ReCnctFlag == 0) {  // If NOT connected and not already trying to reconnect, set timer to try to reconnect in 30 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);
      Blynk.connect();  // Try to reconnect to the server
    });  // END Timer Function
  }
}

Serial 3 on the Mega is connected to pins 14 & 15. You shouldn’t be doing pinMode declarations and digitalWrites to these pins.

What does that code look like, and what does your serial monitor show?

Pete.

Hey Pete,

I removed those and it doesn’t work… The monitor shows the connection, but the momenet I open my Blynk App and press Play, it shows Buffer Overflow.

These is the ‘empty’ code I uploaded to test it

#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

// Your  WiFi credentials + Auth Token in the Blynk App.
char auth[] = "";
char ssid[] = "";
char pass[] = "";

// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial3
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi
(&EspSerial);
  
void setup()
{ 
  // Debug console + Set ESP8266 baud rate
  Serial.begin(9600);
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
}
void loop() {
   Blynk.run();
}
´´´

Show me!

Pete.

EDIT:

Pete, after looking in too the Robotdyn Pinout schedule I also removed digitalPin 3, because it has an INT5 value in it. Currently it’s been running for 10 minutes solid. Thanks already for giving the advice to delete the digitalPin 14+15!!

So if anybody finds this topic in the future don’t use digitalPin 14+15 and other pins with an INT function on it. Google for Robotdyn Mega Wifi R3 Pinout and you will find it!

19:44:42.438 ->     ___  __          __
19:44:42.438 ->    / _ )/ /_ _____  / /__
19:44:42.479 ->   / _  / / // / _ \/  '_/
19:44:42.479 ->  /____/_/\_, /_//_/_/\_\
19:44:42.515 ->         /___/ v0.6.1 on Arduino Mega
19:44:42.548 -> 
19:44:43.024 -> [599] Connecting to Netwerk 66b
19:44:46.233 -> [3816] WIFI CONNECTED
19:44:46.233 -> AT version:1.7.4.0(May 11 2020 19:13:04)
19:44:46.301 -> SDK version:3.0.4(9532ceb)
19:44:46.301 -> compile time:May 27 2020 10:12:22
19:44:46.368 -> Bin version(Wroom 02):1.7.4
19:44:46.368 -> OK
19:44:54.565 -> [12145] +CIFSR:STAIP,"192.168.0.120"
19:44:54.599 -> +CIFSR:STAMAC,"5c:cf:7f:e3:1b:26"
19:44:54.633 -> [12154] Connected to WiFi
19:45:04.856 -> [22450] Buffer overflow
19:45:07.857 -> [25437] Login timeout
19:45:18.879 -> [36459] Buffer overflow
19:45:21.853 -> [39446] Login timeout
19:45:32.862 -> [50455] Buffer overflow
19:45:35.857 -> [53441] Login timeout
19:45:46.893 -> [64470] Buffer overflow
19:45:49.860 -> [67456] Login timeout
19:46:00.883 -> [78481] Buffer overflow
19:46:03.858 -> [81468] Login timeout
´´´

Normal practice is to only have pinMode declarations and corresponding digitalWrite commands for the pins that you intend to have peripherals (such as relays, switches etc) connected to.

It’s also good practice to give these names, so that you can debug the code easier…

#define relay_1  24        // Relay_1 is connected to GPIO 24

digitalWrite(relay_1 , LOW);

Glad its sorted now.

Pete,.

Hey Pete,

Sadly, you can remove the Solved… It happens again. Every pin I use has no other secondary uses like TX or INT…

How are you powering your relays?

Pete.

Hello

I am using the 5V + GND ports from Mega board.

They a need separate power supply, that shares the same GND connection as the Mega.
This may not be the cause of your problem, but do some tests without the relays connected.

Also, is this actually a Mega + EPSP-01, or a Robotdyn or equivalent combo board?
Was the AT version:1.7.4.0 firmware already installed on the ESP-01?

Pete.

Hey Pete,

This is a Robotdyn version.
I added an Arduino Uno only to power the relay’s with the 5v and use the GND from the Robotdyn.

Edit: currently it’s working again… I’ll keep you up to date.

Edit2: and it’s gone again. Sigh

I flashed the AT using this tutorial:

Still having issues with the bord connecting and disconnecting.

Hmmm, you’ll see that I tend to describe these as the “worst of both worlds”, and for good reason.
The Mega itself is a poor starting point for an IOT solution. Coupled with an ESP in the way that these guys do it makes it even worse.
My guess is that its your firmware, but it really isn’t worth the effort of playing around with them, they will always be a poor compromise in my opinion.

If you really do need to run 32 relays from a single MCU then I’d daisy-chain 4 MCP23017 boards together and control them with a NodeMCU or Wemos D1 Mini, like this…

However, I seriously doubt that having a topography where all 32 relays are situated in one location is a practical option for most IoT projects. I prefer to have one or two relays connected to a single MCU and located next to the equipment that is being controlled, and linked together via WiFi, but it does depend on your application.

Pete.

Hello Pete,

So you recommend using 2 esp32 with 2 relay boards?

I’ll be searching in my current setup later today. It’s strange that it works for 5-10minutes and then it goes crazy.

Als it worked fine from saturdaynight 5PM till sunday 2PM and then did crazy stuff

Is that what I said?

It would help if you provided some background to the project you are building.

Pete.

Hey Pete,

So I want to use relays to turn on my lights and shutters. There is no 230v on the switches, because everything works with 24v switches that goe to my electric box. There I can add extra cable’s so the relay’s can simulate as an extra switch.

I have to use 32 relays for all my shutters (22) and 10 for lights. I would need an other 16 to do all my lights (but that isn’t my first concern).

I first used an ESP32 with a 4 Channel relay to test everything and that worked fine. That’s why I upgraded to a bigger board (Robotdyn) with more relays, thinking it would work fine…

My first though would be to use a Shelly 2.5 device for each of your shutters. These can operate on 24v and are small enough to fit in most switch boxed. This would allow you to retain the existing switches and add IoT control too.
The switches incorporate an ESP8266, and can easily be re-programmed to run your own code, so can be “Blynkified” if you wish.

If you do add relay control at the supply distribution side then retaining existing physical switching will be a challenge and even if this is possible then you need to write your code carefully so that things continue to work when there is no WiFi/Internet available, or when the Blynk server is down. Using Blynk.begin isn’t a good starting point, as this is a blocking command and will stop all code execution in case of a lack of connectivity.

Pete.

Hey Pete, thanks for all the information.

Currently the setup is running. I discovered that their is an issue with the virtual pins or with the timers
I’m still looking in too it in detail. At a certain point the device loses it’s connection with Blynk and it buffer overflows again if there are timers or virtual pins in the app.

Well, there are no timers or virtual pin handlers in the ‘empty’ code that you were using, yet that still caused you problems.

Pete.

Pete,

I’m using the code I provided in the first post. So the virtual pins are in place.

I add a TimerWidget with the app and set in pin V2 by example.

So are you saying that the ‘empty’ code no longer causes buffer overflow issues? If so, what has changed?

Pete.