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

Múltiples virtual write Reset the esp8266 nodemcu, How to Fix?


#1

I’m using multiple Virtual Write (10 to be exact), which are controlled by Sliders from blynk app, then to be sent each value by the serial port. The code that will be used is working but not efficiently, since when sliding constantly the Slider seems to send too many values ​​and causes the esp8266 nodemcu to disconnect from the BLYNK server. How do I prevent this from happening?

// declare three strings:
String string1, string2, string3, string4, string5, string6, string7, string8, string9, string10, string11, string12, string13, string14, string15, string16, string17, string18, string19, string20; ;

int old_value1, old_value2, old_value3, old_value4, old_value5, old_value6, old_value7, old_value8, old_value9, old_value10;

int virtualpin1, virtualpin2, virtualpin3, virtualpin4, virtualpin5, virtualpin6, virtualpin7, virtualpin8, virtualpin9, virtualpin10;

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include "SimpleTimer.h" //Timer Rotation Library

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "       ";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "       ";
char pass[] = "     ";



BLYNK_WRITE(V1)
{
  virtualpin1 = param.asInt(); // assigning incoming value from pin V1 to a variable
  // process received value
  // adding a variable integer to a string:Virtualpin1
  if(virtualpin1 != old_value1){
  old_value1 = virtualpin1;  // save the changed value
  string1 = "A";
  string2 = string1  + old_value1;
  Serial.print(string2);    
  }

}

BLYNK_WRITE(V2)
{
  virtualpin2 = param.asInt(); // assigning incoming value from pin V2 to a variable
     // process received value
     // adding a variable integer to a string:Virtualpin2
  if(virtualpin2 != old_value2){
  old_value2 = virtualpin2;  // save the changed value
  string3 = "B";
  string4 = string3  + old_value2;
  Serial.print(string4);
  }

}


BLYNK_WRITE(V3)
{
   virtualpin3 = param.asInt(); // assigning incoming value from pin V3 to a variable

   // process received value
  // adding a variable integer to a string:Virtualpin2
  if(virtualpin3 != old_value3){
  old_value3 = virtualpin3;  // save the changed value
  string5 = "C";
  string6 = string5  + old_value3;
  Serial.print(string6);   
  }
}


BLYNK_WRITE(V4)
{
  virtualpin4 = param.asInt(); // assigning incoming value from pin V4 to a variable

     
     // process received value
     // adding a variable integer to a string:Virtualpin2
  if(virtualpin4 != old_value4){
  old_value4 = virtualpin4;  // save the changed value
  string7 = "D";
  string8 = string7  + old_value4;
  Serial.print(string8); 
  }

}

BLYNK_WRITE(V5)
{
  virtualpin5 = param.asInt(); // assigning incoming value from pin V5 to a variable

   // process received value
   // adding a variable integer to a string:Virtualpin2
  if(virtualpin5 != old_value5){
  old_value5 = virtualpin5;  // save the changed value
  string9 = "E";
  string10 = string9  + old_value5;
  Serial.print(string10);  
  }

}

BLYNK_WRITE(V6)
{
  virtualpin6 = param.asInt(); // assigning incoming value from pin V6 to a variable

   // process received value
   // adding a variable integer to a string:Virtualpin2
  if(virtualpin6 != old_value6){
  old_value6 = virtualpin6;  // save the changed value
  string11 = "F";
  string12 = string11  + old_value6;
  Serial.print(string12);    
  }
}

BLYNK_WRITE(V7)
{
  
  virtualpin7 = param.asInt(); // assigning incoming value from pin V7 to a variable

   // process received value
   // adding a variable integer to a string:Virtualpin7
  if(virtualpin7 != old_value7){
  old_value7 = virtualpin7;  // save the changed value
  string13 = "G";
  string14 = string13  + old_value7;
  Serial.print(string14);    
  }

}


BLYNK_WRITE(V8)
{
  virtualpin8 = param.asInt(); // assigning incoming value from pin V8 to a variable

   // process received value
   // adding a variable integer to a string:Virtualpin8
  if(virtualpin8 != old_value8){
  old_value8 = virtualpin8;  // save the changed value
  string15 = "H";
  string16 = string15  + old_value8;
  Serial.print(string16);    
  }
}

BLYNK_WRITE(V9)
{
  virtualpin9 = param.asInt(); // assigning incoming value from pin V8 to a variable

   // process received value
   // adding a variable integer to a string:Virtualpin8
  if(virtualpin9 != old_value9){
  old_value9 = virtualpin9;  // save the changed value
  string17 = "I";
  string18 = string17  + old_value9;
  Serial.print(string18);    
  }

}
BLYNK_WRITE(V10)
{
  virtualpin10 = param.asInt(); // assigning incoming value from pin V8 to a variable

   // process received value
   // adding a variable integer to a string:Virtualpin8
  if(virtualpin10 != old_value10){
  old_value10 = virtualpin10;  // save the changed value
  string19 = "J";
  string20 = string19  + old_value10;
  Serial.print(string20);    
  }



}

void setup()
{
  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
   
}

void loop()
{
   Blynk.run();
}

#2

@John_Isaias_Florian I properly formatted your code for forum viewing. Please take note on how that was done, for the future. Thank you.


#3

Note sure what you are controlling or how frequently you need to update the values from the sliders, but easiest way is to set your sliders for Send on Release.


#5

I would like to use SimpleTimer timer but I do not know how to implement it in the code, Or use other way for to get and send data.
I would like the opinion of an expert like you what is the best way to receive and send data through VIRTUAL WRITE without the ESP8266 disconnect between times when receiving data.


#6

I’m controlling some Led via PWM.
I have tested with Send on Release and it works. I would like the intensity change to be a bit faster than when the Send Relase option is used.


#7

I don’t understand why you need the if() routines for controlling a PWM pin? But otherwise doing so is relatively simple and shouldn’t cause any disconnections… providing you are not trying to adjust too many sliders simultaneously and/or rapidly swiping back and forth on them.

BLYNK_WRITE(Vx)  // Runs everytime LED slider widget is moved.
{
  intensity = param.asInt();  // Get slider value.
  analogWrite(PIN, intensity);  // Send slider value to PWM pin.
}  // END Blynk Function

The key to anything using wireless communication is not to send too much, too fast. Shorter bursts are best, thus timers. Check out the example sketch as well as many other examples here in the forum with the search function.

http://docs.blynk.cc/#blynk-firmware-blynktimer


#8

I’ve made some changes to the code as you suggested, eliminating the IF. But I think the problem persists, after I use the sliders in a period of time the esp8266MCU disconnects and reconnects. I think it is that the buffer is full of information and I dont know how to clear for only stores the new values.

This is the mesage that throws me on the serial monitor when communication is cut off [106620] Heartbeat timeout.


#9

You could probably built in a slight delay on changing the slider.

int blabla; // Global var
BLYNK_WRITE(V1)
{
blabla = param.asInt();
int timerX = timer.setTimeout(100, doStuffHere); // Do stuff after 100ms, use the blabla variable there
}