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

MQTT data via Node-Red To Blynk to controll NodeMCU connected hardware

Hi,

So I have several NodeMCU’s around house mainly looking Temp, Humidity and CO2 levels. Some post directly to either mosquitto MQTT (runnin locally), Thingsboard.io or directly to BLYNK. So I have some knowledge how to get things working… sort of :slight_smile:
But as nodemcu can not handel two connection (to MQTT and BLYNK) in the same time I have managed to create in node-red a flow where CO2 MQTT data is pushed to BLYNK apps virtual pin 5.
Here (Blynk App) I can see nicely the value on value display and it is syncing it self nicely as MQTT data get refreshed. My problem is that the CO2 data that the nodemcu would need to use as indicator how much the hardware connected triac would actually give current to HVAC unit, does not get updated as INT value that nodemcu could use. Seems that the node-red update somehow does not trigger the BLYNK_WRITE (V5) action here correctly ?? Any Idea ??

I’ ve put in the BLYNK APP also slider and that data gets nicely to V6 ( and displays correctly in serial print screen).

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "xxx";
char ssid[] = "xxx";
char pass[] = "xxx";

void setup()
{
  // Debug console
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
 }

BLYNK_WRITE(V5)
{
  int value = param.asInt();
  Serial.print("CO2 Data:");
  Serial.println(value);
}

BLYNK_WRITE(V6)
{
  int slider = param.asInt();
  Serial.print("TEST:");
  Serial.println(slider);
}

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

I use in the Node-Red MQTT-IN -> BLYNK Websocks command WRITE to Virtual Pin 5.

Thank you for any help

Yes it can, see this example:

But, that doesn’t answer your question.
If I understand your problem correctly (and I’ve tried your code and what I think you used as the Node-Red flow and re-created the issue) then you need to use the Bridge node.

Here’s the Bridge Node setup, with the same auth code as you used in your connection:

image

Serial Monitor output:

TEST:512
CO2 Data:336
TEST:336
CO2 Data:580
TEST:580

The display widget in the app attached to V6 also gets updated.

BTW, when you post code it needs to be surrounded by triple backticks so that it displays correctly, and the quotation marks don’t get corrupted when you copy/paste it into the Arduino IDE.
I fixed it6 for you this time, but in future please add the triple backticks yourself at the beginning and end of the code.
Triple backticks look like this:
```

Pete.

Thank you Pete, and first apologies not reading the forum rules fully on the quotations… I’t was really end result of trying to find 12 hrs solution by your self from variaty of stolen codes, own “ahaa” moments and desparation…You might regognize the feeling :slight_smile: I’ll promise to do better.

The bridge you suggested is not actually what I’m looking for (I think). The idea is that MQTT (pushed out by Node-Red is the value I want the V5 read (and now it shows it correctly in BLYNK value field) and use that info as INT for the NodeMCU to do the calculation.

The slider was just a test to see data is moving back to nodemcu from different pin (V6), which it dis so idea was not to link these two pins (5 and 6).

Thank you, Sami

Okay, I misunderstood some of the detail, but the solution is the same - use the Bridge widget rather than the Write widget:

Pete.

Thanks Pete, works like a charm. You are a “mindsaver”.

1 Like