I’m trying to control an LED through node red and Blynk app via local server setup. As a first step, I tried connecting “Read pin event” node(Configured to read virtual pin 0) to debug node. I’m not getting any output in debug tab in node red as expected. Read event node is configured correctly though!
I wonder what that stumbling block is? My ultimate steps to this project are as follows:
- Create virtual buttons as control in Blynk App
- Read those pin status from Node-Red.
- Use status variables inside exec node (python program) to control an LED/Motor via physical pins in Rpi.
- Show the status of LED/Motor back in Blynk App.
Any help regarding this is much appreciated.
PS: I’ve gone through the forum, read few posts related to node-red & blynk but not succeeded in solving this. @scargill 's post here says using mqtt is easy to monitor and control many things. As a newbie to mqtt, how should I proceed, if solution through blynk_ws node package isn’t possible?
From what you’ve said here, it should be working fine.
I assume that in the Blynk app you’ve added a device (it doesn’t really matter what type of device if you’re only using virtual pins) and e-mailed the token to yourself and inserted this in the Blynk websocket node in Node-Red?
Is there any chance that you are using multiple devices in your app and have linked the button widget to the wrong device? (this has tripped-me up before!).
Is the button widget in the app definitely connected to pin V0?
When you do get this working, don’t forget that LED widgets in the Blynk app expect a 255 value for ON, so you’ll be using msg.payload=255 and outputting this to a Blynk-ws write node that’s connected to a virtual pin used by the LED widget
Thanks for the reply.
Yes, I did the same.
No, I’m using only one device.
I’m aware of it. In fact, I’ve checked that with sending a value of 0 and 255 from inject node to blynk write node. It works like a charm. My problem is, node red is not “reading” the pin status.
It’s mentioned that read event node will contain pin number that triggered the event. But am not getting that either in the debug tab.
Okay, I think I know what you’re doing wrong. You’re using a Read Event node and for some unknown reason, you have to use a Write Event node to read the data from the widget virtual pin!
Ah! It solved the issue. Thank you very much, Pete. But why am I not getting any value when using read event? What’s the use of it? Also, any suggestions on how to get started with MQTT in node red?
I’m not sure. I played around until I got it working then didn’t ask any questions!. I think it was written by @tzapulica maybe he can explain?
I use MQTT for all my home automation, but I made it up as I went along so I’m probably not the best person to ask!
This is a simple example of how I do it…
Assume you have a Sonoff S20 with a lamp plugged in to it in the living room.
The Sonoff doesn’t run any Blynk-specific code at all, it basically has Wi-Fi and MQTT code and monitors an MQTT topic called “UK/LivingRoom/Lamp/Power”.
If Node-Red (or any other software that can publish MQTT commands) writes “On” or “Off” to “UK/LivingRoom/Lamp/Power” then the code running on the Sonoff will see this and turn the lamp on or off. You could use 0 and 255 instead of On or Off, if you wanted to keep compatibility with Blynk LED widgets if you wanted to.
The Sonoff has a physical push-button switch which is monitored and debounced by the code running on the Sonoff and if it detects a physical button push it writes an On or Off (depending on the current status of the lamp) to “UK/LivingRoom/Lamp/ButtonStatus”. Node-Red sees this and writes that to “UK/LivingRoom/Lamp/Power”, thus toggling the condition of the lamp.
Node-Red also issues a 0 or a 1 to the virtual pin on the Blynk app, so that the button widget in the app is synchronized with the actual state of the lamp.
I use static IP addresses on all of my devices and use Node-Red to ping them every 5 seconds. If they don’t respond then I update a status LED widget in the app, so this gives me a kind of heartbeat function.
This is a very simple example of how I use MQTT, but it can be very powerful with quite a small amount of effort.
For example I have some RGB LED lighting strips that I control via Blynk/Node-Red/MQTT, with separate topics for Red, Green and Blue values and this works really well.
I’m also working on a heating/aircon system for our place in Spain where multiple ESP8266 based devices will be controlling heaters Aircon units, blinds, fans, etc and using data from ESP8266 connected temperature and humidity sensors dotted around the house. The primary controller will be a wall-mounted Nextion touch-screen connected to an ESP8266 which will send and receive bdata via MQTT to Node-Red.
It’s much easier to control these devices that are dotted around the house using MQTT and Node-Red, then add-on the Blynk functions to Node-Red to allow the system to be controlled via the app from any location.
I find that MQTT Lens, which is a Google Chrome plug-in app, is very useful when monitoring the flow of MQTT messages. It’s much easier than having debug nodes dotted around your Node-Red flows.
Hope this helps to get you started. feel free to ask if you need any specific help.
Thanks for this descriptive reply Pete. It is interesting to learn these stuff. I’ll give it a try!
please use this new Node as the one from @tzapulica is out dated here is the Link https://github.com/gablau/node-red-contrib-blynk-ws
Thanks, @scropion86. Anyway, I’m using that version only.