Blynk sends commands but doesn't recieve status

I have Blynk running with an ESP8266. Things were working good until about 2 weeks ago when I started trying to incorporate a push notification. Ever since, Blynk connects but can only toggle the LED on and off. It cannot see any of the virtual writes. Just to make sure it wasn’t a hardware issue, I wrote the following program to turn on the LED when any input is on.(Every input works.) Any thoughts to resolve this?#include <ESP8266WiFi.h> //library for esp8266 wifi

#include <BlynkSimpleEsp8266.h>  //library for Blynk ESP8266

char auth[] = "a91e3c27a81543c090a160785293a9b2";  //Blynk authorization
#define BLYNK_PRINT Serial  
#define WIFI_SSID  "NETGEAR16"  // Home network name
#define WIFI_PASS  "XXXXXXXXXX"  // Home network password
#define ESP8266_LED 5  // for using output 5 LED

// voidsetup is the initialization routine

void setup()
{
  pinMode(0, INPUT_PULLUP);
  pinMode(ESP8266_LED, OUTPUT);
  pinMode(4, INPUT_PULLUP);
  pinMode(13,INPUT_PULLUP);
  pinMode(12,INPUT_PULLUP);
  
  Serial.begin(115200);
  Blynk.begin(auth, WIFI_SSID, WIFI_PASS);

}
void loop()
{
  Blynk.run();
  
// int sense = !digitalRead(5);
//   if (sense == HIGH) {
//     Blynk.virtualWrite(V1, HIGH);}
//     else {
//      Blynk.virtualWrite(V1, LOW);}
      
int wash = !digitalRead(0);  
  if (wash == HIGH) {
    Blynk.virtualWrite(V2, HIGH);}
    else {
      Blynk.virtualWrite(V2, LOW);}
      
int rinse = !digitalRead(4);
      if (rinse == HIGH) {
    Blynk.virtualWrite(V3, HIGH);}
    else {
      Blynk.virtualWrite(V3, LOW);}
      
int spin = !digitalRead(13);
      if (spin == HIGH) {
    Blynk.virtualWrite(V4, HIGH);}
    else {
      Blynk.virtualWrite(V4, LOW);}
      
int complete = !digitalRead(12);
      if (complete == HIGH) {
    Blynk.virtualWrite(V5, HIGH);}
    else {
      Blynk.virtualWrite(V5, LOW);}
      
if((spin == HIGH)|| (wash == HIGH)|| (rinse == HIGH) || (complete == HIGH)) { // || (locked == HIGH)) { 
   digitalWrite(5, HIGH);}
  else {
   digitalWrite(5, LOW);}
  
  }

Hello. You shouldn’t use virtualWrite within loop. See here.

You may use either BLYNK_READ either timer. Please check our docs.

Isn’t the issue more that he’s writing every time through the loop? Not that he’s doing it within the loop.

Check the status of the pins and only update blynk when they change. Don’t do it every time through the loop.

Based on your feedback, I changed and shortened my sketch to what’s listed below. pretty sure this code will only virtual write on the transition, but I’m new to this.

Basically just looking at transitions of the input to write the V18 LOW or HIGH. (Changed that too.)

The LED turns on and off as expected, but still nothing on my smart phone. Yet I can still turn the LED on and off with the button command on the phone.

I removed and re-installed the Blynk app, changed the authorization code, and switched to V18 from V2. Still doesn’t work. Any other suggestions?

Thanks for your help.

#include <ESP8266WiFi.h> //library for esp8266 wifi
#include <BlynkSimpleEsp8266.h> //library for Blynk ESP8266

char auth[] = “xxxxxxxxxxxxxxxxxxxxx”; //Blynk authorization
#define BLYNK_PRINT Serial
#define WIFI_SSID “NETGEAR16” // Home network name
#define WIFI_PASS “pastelroad668” // Home network password
#define ESP8266_LED 5 // for using output 5 LED

// voidsetup is the initialization routine
int senseold = LOW;
int washold = LOW;
int rinseold = LOW;
int spinold = LOW;
int completeold = LOW;
int lockold = LOW;

void setup()
{
pinMode(0, INPUT_PULLUP);
pinMode(ESP8266_LED, OUTPUT);
pinMode(4, INPUT_PULLUP);
pinMode(13,INPUT_PULLUP);
pinMode(12,INPUT_PULLUP);
pinMode(16,INPUT_PULLUP);

Serial.begin(9600);
Blynk.begin(auth, WIFI_SSID, WIFI_PASS);

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

// int sense = !digitalRead(5);
// if (sense == HIGH) {
// Blynk.virtualWrite(V1, HIGH);}
// else {
// Blynk.virtualWrite(V1, LOW);}

int wash = !digitalRead(0);
if ((wash == HIGH)&&(washold == LOW)) {
Blynk.virtualWrite(V18, HIGH);
digitalWrite(5,HIGH);}
if ((wash == LOW)&&(washold == HIGH)) {
Blynk.virtualWrite(V18, LOW);
digitalWrite(5,LOW);}
washold = wash;

}

Please edit your post. Code should be formatted.

Example:

 ``` <--- insert this 
 Paste your code 
 ``` <--- insert this 

This makes your code beautiful with highlighted syntax, like this:

//comment goes here 
void helloWorld() { 
   String message =  "hello" + "world"; 
}

It is wise with Blynk to use separate functions and timers for repeated actions as not to flush too much data to the cloud or clogg up your own device, after all, a microprocessor is quit limited in it’s capabilities.

In the Blynk Examples there is one called “Pushdata”. This has an excellent example of such usage. I highly recommend looking at that and if there are things unclear we’re here to help :slight_smile:

1 Like

Thanks Pavel for the formatting tip.
I could not get simple timer to load. I downloaded the library but it would not compile.
So I just used a delay of ~5 seconds.
I still see no update on my phone for V2.
Is it possible the buffer on the server is full of writes from earlier code?
Does it get cleared when I close the App?
Thanks again.

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "XXXXXXXXXXXXXXXXXXXXX";
#define BLYNK_PRINT Serial  
#define WIFI_SSID  "NETGEAR16"
#define WIFI_PASS  "pastelroad668"
#define ESP8266_LED 5

void setup()
{
  pinMode(0, INPUT);
  pinMode(ESP8266_LED, OUTPUT);
    
  Serial.begin(9600);
  Blynk.begin(auth, WIFI_SSID, WIFI_PASS);
  
int wash = !digitalRead(0);  

}
void loop()
{
  Blynk.run();
int wash = !digitalRead(0);  
  if (wash == HIGH) {
    Blynk.virtualWrite(V2, HIGH);
    digitalWrite(5, HIGH);}
    else {
      Blynk.virtualWrite(V2, LOW);
      digitalWrite(5, LOW);
    }
  delay(5000);
  
}

@MJC57 I think you need to try and get SimpleTimer working. Blynk has a 5 second heartbeat timeout (10 seconds I think in the latest beta) so your ESP will keep disconnecting without SimpleTimer and a delay(5000).

For Blynk users that are not running ESP standalone the general recommendation is not to go beyond version 1.6.5 of the IDE because there are ‘issues’.

Maybe these same issues are in the latest versions of Arduino for ESP. Are you able to use a 1.6.5 equivalent for the ESP?

Back in November @pa0akv had a problem with SimpleTimer and ESP as highlighted here Simple timer problem. Their solution was the actual placement of the timer function between setup() and loop(). I’m not sure if that is really the fix because generally it doesn’t matter too much where you put the timer function. I have seen occasions though where it is important and maybe it is for the ESP standalone set up.

When I try to include Simpletimer, the compiler terminates. Looking at the error window, it is looking for the Simpletimer in a totally different directory than where I have it loaded (c;/program files(x86)Arduinolibraries. Why would it be looking elsewhere?
Thanks for all your help and patience!

Maybe you can download the zip file and re-import it via your IDE? That sometimes work to straighten things out.

@MJC57 does your Arduino for ESP have a version number equivalent to 1.6.5 (1.6.6 and 1.6.7)?

For me the IDE (Arduino with ESP not ESP standalone) has at least 2 library locations. There are libraries that come with the version of the IDE you are using and then there are the extra libraries you add. Depends on the version but generally the libraries you add are in a subdirectory of your sketchbook folder and not surprisingly called libraries.

If you do file and preferences in the IDE the first item shows where your sketchbook is located.
You can decide where and for me it is C:\Users\Public\NewArduinoSketchesAndLibraries
So in …\NewArduinoSketchesAndLibraries\ I have a libraries folder and currently just 6 additional libraries. 4 of them are required for Blynk to work as it is almost impossible to do anything without SimpleTimer.

Blynk
BlynkESP8266_HardSer
BlynkESP8266_SoftSer
SimpleTimer