Blynk, Node-Red, and ESP8266 problem


Using Blynk and Node-Red talking to an ESP8266.

I have a Blynk UI button, talks over virtual pin V1, and toggles a hardware pin on the ESP8266. Works great. I wanted to add Node-Red to control the hardware pin as well. The Blynk button output is either 0 or 1 (default), Node-Red is set up to inject a 0 or 1 into V1.

When I Node-Red inject a 0 or 1 (and it doesn’t matter if it is a string or integer), the Blynk UI button changes to reflect the changed state of V1. However, the hardware pin does not change! I have searched the forum for a similar problem without success.

I must be doing something wrong on the Node-Red end, but I am baffled that the Blynk UI recognizes the changed state of V1, but the hardware does not.


Blynk write event and Node-Red

Having read your description, I’m not clear if you’re running both Blynk and MQTT code on your ESP8266, or just MQTT.

Cab you share some screenshots of your Node-Red config and the code (correctly formatted of course) you’re running on your ESP?




Just using Blynk, no MQTT involved. Since I was focused on V1, chucks of code have been commented out.

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h> // Used to establied serial communication on the I2C bus
#include "SparkFunTMP102.h" // Used to send and recieve specific information from our sensor
#include <ArduinoOTA.h>

// 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[] = "";

bool flag = true;
bool buttonFlag = false;
bool LEDflag = true;
bool Waterflag = false;

TMP102 sensor0(0x48);
BlynkTimer timer;

BLYNK_WRITE(V1) //Button Widget is writing to pin V1
  int pinData = param.asInt();
  if (pinData == 1) 
    digitalWrite(D7, 1);
    digitalWrite(D7, 0);

/* not at this time
void checkTemperature()
  float temperature;
  temperature = sensor0.readTempF();
  Blynk.virtualWrite(V3, temperature);
  if (flag == true)
  { if (temperature <50)
    {"", "Subject", "Temperature < 50F");
    flag = false;
  if (temperature > 60)
    flag = true;
/*void checkMotion()
  if (flag==true)
    {if (digitalRead(D5)==1)"", "Subject", "Garage motion");
    flag = false;
    if (!digitalRead(D5))
      flag = true;
    WidgetLED led1(V0);
    if (digitalRead(D5))

void checkWater() //borrowing D5 from checkMotion routine
  if (Waterflag == false)
      if(digitalRead(D5) == LOW)
          Waterflag = true; //avoid multiple messages
"", "Subject", "Water Heater Alert!");
          delay(6000); //Blynk allows only one email every five seconds
"", "Subject", "Water Heater Alert!");
void setup()
  // Debug console
  pinMode(D5, INPUT);
  pinMode(D4, OUTPUT);
  pinMode(D7, OUTPUT);
  digitalWrite(D7, 0);

  //timer.setInterval(200L, checkTemperature);
  //timer.setInterval(1000L, checkMotion);
  timer.setInterval(5000L, checkWater);

  Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,155), 8080);"", "Subject", "My Blynk garage project is online.");

void loop()

The Node-Red is pretty simple:



Hmmm, this is so different from the way that I use Blynk and Node-Red that I can’t really shed any light on the issue.





Appreciate you taking a peek at it. Looking forward to your 5th installment of controlling the world from either Spain or England.

1 Like


No problem.

Thinking about it a bit more, this issue did ring a vague bell with me. A quick search came up with this thread:

It seems like a similar situation.

I’m currently working on revamping the MQTT code that I use on my devices, and adding-in some direct Blynk communication as well as the MQTT --> Node-Red --> Blynk method that I currently use. I’ve not shared the code that I run on my devices before (mostly because it needed this revamp first), so that should be too far off.





Perfect! The suggestion by gab.lau was very informative. Instead of the Blynk “write” node, one uses the “bridge” node. The authorization code for the Blynk code on the ESP8266 is what is required for the bridge node configuration.

Glad you remembered that thread, since I did not come across it when searching.

1 Like


@arcs_n_sparks: I have not seen any part of your code about mqtt. If you do not set it up how can the trigger from node-red to be transferred to hardware as well as Blynk to be updated and vice versa.




No MQTT required (although I like what Pete Knight has done, and will gradually shift in that direction). The Node-Red Blynk library by gal.lau has a number of functions, including a “bridge” node that does what Blynk implemented. That allows a Node-Red message to be sent to the hardware (with appropriate authorization code).

It appears the Blynk server keeps the Blynk UI app synchronized with the current state of virtual pins. So if Node-Red changes the status of a virtual pin, that gets reflected in the UI.

So for the Node-Red diagram below, I have a Blynk UI switch on V1. When I push that switch, it communicates a ‘1’ directly to the ESP8266 hardware (no Node-Red required). That turns on a relay and is reflected in my code above. The “set message” node sends a ‘0’ message that is then delayed 20 minutes. After 20 minutes, Node-Red sends the ‘0’ message to the hardware via the bridge. The status of V1 is then changed on the UI courtesy of the Blynk server.

1 Like