• Hardware model: Arduino Mega communicate with a Nodemcu board. The Nodemcu talks with blynk. Sends and recieves commands over the serial line from the mega, and then passes them on to the blynk local server on a rPi 3.
• Smartphone OS: Works perfect over IOS app. Trying to make a browserbased app.
• Blynk server or local server: Local server
• Blynk Library version: 0.51 and 0.33.2 server.
Hi. Im trying to make websockets work with NodeRed. So far I can connect to my project, but I cant get any values from the write even node. When I instead does a set write event it works fine, and the values get updated in the app.
But when I try to load the values my Nodemcu sends every time it gets changed nothing happens.
For an example I have Blynk.virtualWrite(V21, NodeMCULoops); write its new value every second, but nothing changes in the debug og any kind of output to show the value.
What am I doing wrong?
Are you using the same project for all the widgets on your App, and your NodeMCU and your Node-Red nodes?
If you are then I’d suggest trying something a bit simpler - Add a Button widget to your project and connect it to a Virtual pin then add a Node-Red node that connects to it. This should prove that you’re able rio recieve data into Node-Red from the widgets via the server.
It works when I make a button and presses that. Then the value gets picked up by node-red.
But when my NodeMCU writes something to blynk. The value gets updated in the mobile app, but the Node-Red doesnt pick up the value.
Interesting, I’ve never tried to use it that way, so dont know if it should work or not (I assume it should).
Maybe a question for @gab.lau
The way I use Node-Red and Blynk is that I don’t run any Blynk code on my MCUs, just an MQTT client and code to send and process MQTT messages.
These messages then go to Node-Red and then interact with Blynk in that way.
Thanks for tagging someone that might could help.
I just completed transforming all my stuff to blynk interface and blynk code. So I would rather it to stay like this, than having to setup a MQTT server. Instead of having to learn a whole new way again
The person I tagged is Gabriele, who wrote the Node-Red contrib.
I fully understand that you wouldn’t want to change your setup again.
The one thing that I wasn’t certain about was that you said you are “Trying to make a browserbased app”. Does this mean you want something in addition to Blynk, or is the Blynk app what you were referring to?
It just means I wanna make a dashboard I can go through my webbrowser to check all my projects at one place.
I still use the blynk app with indivudually apps for every of my controllers.
So its like having a big dashboard on a 21" where I can easier look over everything.
I was planning to use: https://github.com/node-red/node-red-dashboard
so it actually looks quite similar to blynk
I went down that route originally, but found the Node-Red dashboard too cumbersome and the effort required to sync physical switches, Blynk widgets and dashboard controls more trouble than it was worth.
@mortenjs, I’ve been through it and failed. I mean I failed to read Blynk’s Virtual Pins into Node Red. If it is possible, I have no idea how to achieve this goal, so with curiosity gonna observe others efforts .
Still using all this idea (with a dashboard), but I had to double the servers. Blynk has Blynk server, MQTT is concentrated on Mosqitto. Blynk can control MQTT using websockets nicely, but seems to reject the opposite.
As Pete said, I keep the library node-red-contrib-blynk-ws and if I can I will gladly give you help.
I state that I use the Blynk-cloud server, and like Pete, the nodes of my home automation are in MQTT and are managed by node-red on a Raspberry Pi 2.
But let’s get to the point, I think it’s a configuration problem, I’ll explain how my installation works:
Through the Blynk app in my project I created a new device that I called “Node-red”, type: “RaspberryPi 2”, connection: “Ethernet”, the app gave me an access token.
In Node-red this access token I write to the “configuration node” (blynk-ws-client)
In this way the virtual pins have a connection to the server, from which to receive or send data. End.
Simply node-red will be a client of “blynk server” (cloud or local).
Now I would like to know, how did you set up your apps, nodered and where did you put which apikey?
Ok then, Me first:
In Blynk App I created a device: Hardware: Generic Board, Conn type: WiFi. That is for token and project “slot” on Blynk’s server. Then in Node-red a new client (blynk-ws-client) has been created, and configured:
- project key: as assigned
- no pin or protocol logging
Then a flow - one of them: (just a screenshot)
Deploy… etc… EVERYTHING WORKS AS EXPECTED!
And now… Turn it all 180 degree:
- Existing Blynk project, lets say an ESP temperature sensor:
- A token as assigned and used: Both in hardware Blynk node and app
- A “copy of” that node created as another
blynk-ws-client (auth token the same as on hardware node, url pointing to server as in working example)
- a node (which one??) trying to receive data from hardware client… (in fact from server). HOW??! It seems to be not possible or out of my skills…
I do that by sending the temperature via an MQTT message from the ESP to Node-Red every 5 seconds. No different from receiving the relay status from your Sonoff.
Am I misunderstanding your problem? What you’ve described here is quite a bit different from what you said earlier:
As short as possible: A hardware with ONLY Blynk protocol implemented can’t (??) “communicate” with NODE-RED by means of virtual pins. A hardware with ONLY MQTT protocol implemented CAN communicate both ways (as in my working flow). It is not “a big deal”, as I already managed to do it all “interconnected”, but that required flashing a new firmware to few devices.
you have a device in the app called “DEV1” with token “abcd” for example.
Then this token uses it both in an ESP8266 and on a pc / rpi with nodered.
did I get it right?
I do not know if you can do something like that. I have to do some tests.
but I think you should have in the app 2 device: “DEV1 ESP8266” and “DEV2 nodered” with two different access tokens. and then we use the blynk bridge function to let the 2 devices communicate.
Yes @gab.lau, you got it right. As for the bridge, I will wait for a better implementation of it (a similar to the one handled by MQTT protocol would be much better). Until that, I just turned (mostly) to the way @PeteKnight is using: Hardware nodes using MQTT protocol “talking” to Blynk app (and server) through node-red.
Okay, I tested this myself and obtained the same results as @mortenjs and @marvin7. I use the Blynk Cloud server. This was mjy methodology:
Create some Blynk code that toggles the state of pin V1 from 0 to 1 once every second. The same Auth Code is used at all stages of this, and it’s linked to my project called Test.
Add a blynk-ws-in-write node with a connection to the same Test Auth Code and linked to V1. A debug node is connected to the output.
Nothing appears in the debug screen. I added a button widget to the app linked to the same project and linked to V1. This flashes on/off once every second as expected.
The solution is to use an HTTP GET command to obtain the value of the V pin as shown below:
The HTTP Request node used the following URL:
As you can see in the screenshot, the result looks like this:
so it needs a bit of manipulation/parsing to remove the unwanted quotes and square brackets, but it does work.
The inject node simply triggers the HTTP GET as frequently as you need the data, and the RBE node only allows changed values through.
Thanks. lots to look at. I will have a look at it later today and post how it goes.
and yea I can also get it to work through http request. But wont it be way faster and better if it was done through ws, and then only when there is pushed a new value.
Now I have to make a http request for every pin in 500ms interval. Wont that make a bottleneck with floading of the server?
There seems to be one more way, which I tried to use with IP camera and Node red as an alarm server. With Blynk however you would need to use webhook widget to “notify” the server. Then in node red just use the “TCP in” node as a server, and it should work. I’m not using it with Blynk, but it shouldn’t be much different then my “alarm server”
I did some tests …
Blynk works like this: there is a single channel of communication between the “blynk server” and a “blynk node”, so if a node updates a virtualpin only the server (ad smartphone app) knows if it has been updated. The other nodes, even if with the same access token, are not informed.
However, there are the “syncAll” and “syncVirtual” commands that have the function of requesting the status of all pins or a specific pin to the server.
I modified my library (not yet released) to implement the two new commands and I did some tests:
If from the device1 I write a value on pin V3 and then from device2 I request a syncVirtual of pin V3 I receive a writing event on pin V3 with the updated value. Same with the syncAll command, but for all widget in the project.
The cons of this solution is that nodered must polling virtual pins with a certain amount of time to stay updated. For a few pins and for not too short time intervals, I think it’s an excellent solution.
I’m also testing the bridge command … stay tuned
New 0.5.0 version of the library for Node-Red is here node-red-contrib-blynk-ws.
Some usefull additions / changes:
- Implemented the “bridge” and “sync” nodes.
- With the bridge node you can send direct commands to other devices
- With the sync node you can ask the server to resend the last values of one or all of the pins.
- I also fixed the reception of the bridge commands, which did not work properly before this version of the library
See full changelog
Please send feedback!!