New Node-Red library: node-red-contrib-blynk-ws

Hello everybody,
I would like to share this new node-red library with you:

It extends the functionality of the great library, but no longer up-to-date, node-red-contrib-blynk-websockets.

For any problems or bugs or improvements do not hesitate to contact me or open a issue here
If you have the availability and the knowledge, feel free to open a pull request

Here below find the README :


node-red-contrib-blynk-ws

Blynk app integration with Node Red using WebSockets protocol

NPM
npm version

Websockets version

This works for both local and cloud Blynk servers.
For local, wss:// works if you ve got a certificate installed on Blynk cloud server.
For Blynk cloud server, you can use ws://blynk-cloud.com:8080/websockets or with SSL wss://blynk-cloud.com:9443/websockets as the server url.

If you installed Node Red globally use this command to install
npm install --global node-red-contrib-blynk-ws

Supports both SSL wss:// and non secure ws:// connection to local server and Blynk cloud server.

Supported events and widgets

  • read event
  • write event
  • app event
  • write command
  • set property
  • emails
  • notify
  • LCD widget

Blynk App Settings

Use Raspberry PI as hardware to access 128 virtual pins or Generic Board for 32.

How to use

See help of every nodes

Debug

Use the verbose -v flag when starting Node-Red to get more information
or use node-red-log and enable log on Configuration Node as needed

Compatibility

This library is retrocompatible and can replace node-red-contrib-blynk-websockets.
To do this:

  • stop node-red
  • install node-red-contrib-blynk-ws npm install node-red-contrib-blynk-ws
  • remove node-red-contrib-blynk-websockets npm uninstall node-red-contrib-blynk-websockets
  • edit your flow file eg: "my-flows.js" search for ‘blynk-websockets-’ and replace with ‘blynk-ws-’
  • start node-red.

Attributions

The node-red-contrib-blynk-ws was born as a fork of node-red-contrib-blynk-websockets
https://github.com/tzapu/node-red-contrib-blynk-websockets
Some javascripts code was derived from blynk-library-js:
https://github.com/vshymanskyy/blynk-library-js
MIT licence

6 Likes

Hi Gab,

If I call Blynk.virtualWrite via a hardware button (or timer) it is not picked up by node-red. The mobile app connected to the same virtual pin works without issue. Any idea?

Can we see some code?

Pete.

“VirtualWrite” are handled by the “Write event” node, are you sure you have used this node?

write_event

Otherwise, post more information like device source code or nodered’s flows

Gab

Hi all
gab.lau thanks for awesome work

One question - cant set msg.color properties for blynk “LED” pin with Set Properties node. Can set custom title, but no color. Always black or white \
For blynk “Labeled Value” pin - color set fine.

Code example, for pin10 all fine, color and label. For pin13 - no color, only label

[{"id":"921ab2b6.d3f47","type":"change","z":"16d8aea3.2b0411","name":"","rules":[{"t":"set","p":"color","pt":"msg","to":"#D3435C","tot":"str"},{"t":"set","p":"label","pt":"msg","to":"test","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":411.8833312988281,"y":345.8833312988281,"wires":[["caaf198e.a4a858","c31594b6.9e5bf"]]},{"id":"caaf198e.a4a858","type":"blynk-ws-out-set-property","z":"16d8aea3.2b0411","name":"Pin 13 - LED","pin":"13","prop":"bycode","client":"736561ba.b1a908","x":636.88330078125,"y":319.7333068847656,"wires":[]},{"id":"c31594b6.9e5bf","type":"blynk-ws-out-set-property","z":"16d8aea3.2b0411","name":"Pin 10 - Labeled Value","pin":"10","prop":"bycode","client":"736561ba.b1a908","x":668.88330078125,"y":372.8833312988281,"wires":[]},{"id":"4089b6c0.0f9dc","type":"inject","z":"16d8aea3.2b0411","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":210.46664428710938,"y":345.3666687011719,"wires":[["921ab2b6.d3f47"]]},{"id":"736561ba.b1a908","type":"blynk-ws-client","z":"","name":"Local","path":"ws://127.0.0.1:8080/websockets","key":"859ba556a7fc477*************","dbg_all":false,"dbg_read":false,"dbg_write":false,"dbg_notify":false,"dbg_mail":false,"dbg_prop":false,"dbg_low":false,"dbg_pins":""}]
1 Like

Hi dementeb,
there are no errors on your code.
I’ve tested your code on my node-red successfully.

To see the color of the led you have to turn it on, have you first written on the led a value of 255? with the write node of course.

best regards

Hello. Generaly awsome job, but I have some issueor maybe I dont know how to setup propertly. Problem is similar like Chinswain. My setup is local blynk server on pi with node-red. Hardware ESP826 measure temp in bedroom and controling relay for heater, slider setup min temp in room. From app on mobile data displays nicely on red but temp from esp dont. Red using write event and connected to debug. I can only see valus from switch(relay) or slider(min temp). Any idea what i can check to correct issue?

Based on that description I don’t think I can help.
If you’d like to share the code that’s running on the ESP, and a screenshot of the Node-Red Node then I’d probably have a better idea of what you’re trying to explain.

Pete.

Hi Marcin,
as Pete said, to help you we need the code, please both the sketch loaded on the esp and the flow of node-red.

gab.lau

Hi All,

Does this library still work ? I am currently getting the following error ?

Unhandled response { type: 41, typeString: undefined, msgId: 1, status: 19 }

Thanks,
Serge

Hi Serge,
which version of the library still use?? Please update to 0.4.0 version!!

Thanks, that solved it.

New release today!! Please send feedback!!

0.5.0 - 2018-04-14

Added

  • Blynk protocol - Handle any number of Blynk commands (virtualWrite(), setProperty(), etc.) in a row see Blynk Library 0.5.0
  • Control max lenght of message and max number of commands in a single message
  • Config node - Option to enable “Multiple blynk command in single message” (blynk cloud or local server >= v0.34.0)
  • Config node - Implemented server proxy configuration
  • Config node - Option to log protocol “sync” and “bridge” messages type
  • Node - Bridge - New node that implements the functionality of sending commands to other blynk devices.
  • Node - Sync - New node that implements the “syncAll” and “syncVirtual” blynk commands
  • Node - Set Property - Implemented “step” for Step Widget (blynk cloud or local server >= v0.32.2)
  • Node - Set Property - Implemented “url” for Video Straming Widget (blynk cloud or local server >= v0.28.7)
  • Node - Set Property / LCD / Table - Send multiple blynk command in a single message
  • Node - Read Event - Option to receive all pins events
  • Node - Write Event - Option to receive all pins events
  • Node - Write Event - Added pin number that generate event in msg.pin variable
  • Initial support to Internationalisation

Changed

  • Better handle of configuration node error, now blocks child nodes if some parameter is missing.
  • More check on “pin” parameter before send message
  • The PING command is only sent if no data has been sent or received in the “heart beat” time
  • Hide “Auth token” - from all log message
  • Config node - Rename “Private key” to “Auth token” and better help message
  • Split every node on single file
  • Removed dependency from “DataView” package
  • Code clean

Fixed

  • Rightly handles the reception of the BRIDGE type commands.
  • Websocket SSL connection error on nodejs > 8.6.0 see (ws iusse #1227)
3 Likes

new blynk 2 days ago has multiway button. new local server - I updated that too, but the new button (made 3 way) doesnt work with blynk-ws (virtual button) I have 0, 1 and auto turning a led on or off where auto is off as is 0… the led wont turn off. works with normal button

the new blynk segmented switch… it is working, but feeding back into bode-red-blynk-ws write or sync nodes if something else changes the state of the switch does not seem to do anything.

I Peter,
for me all works ok, attached sample node-red flow.
Setup blynk app with one “segmented button” with 3 option on V100 pin.
If i change the state on app the virtual write intercept the change.
If i write the value “1, 2, or 3” on V100 the app update correctly.

Or did I not understand the problem?

[
    {
        "id": "890de765.2cd7d8",
        "type": "blynk-ws-out-sync",
        "z": "3c3c2216.c4bc4e",
        "name": "",
        "pin": "100",
        "pinmode": 0,
        "client": "3d8e7a37.045d06",
        "x": 380,
        "y": 80,
        "wires": []
    },
    {
        "id": "a289325d.030c4",
        "type": "inject",
        "z": "3c3c2216.c4bc4e",
        "name": "sync",
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 210,
        "y": 80,
        "wires": [
            [
                "890de765.2cd7d8"
            ]
        ]
    },
    {
        "id": "451e89b2.01a818",
        "type": "blynk-ws-out-write",
        "z": "3c3c2216.c4bc4e",
        "name": "",
        "pin": "100",
        "pinmode": 0,
        "client": "3d8e7a37.045d06",
        "x": 460,
        "y": 160,
        "wires": []
    },
    {
        "id": "50cc406f.9b5db",
        "type": "inject",
        "z": "3c3c2216.c4bc4e",
        "name": "1",
        "topic": "",
        "payload": "1",
        "payloadType": "num",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 210,
        "y": 140,
        "wires": [
            [
                "451e89b2.01a818"
            ]
        ]
    },
    {
        "id": "efb643d4.ce8b2",
        "type": "inject",
        "z": "3c3c2216.c4bc4e",
        "name": "",
        "topic": "",
        "payload": "2",
        "payloadType": "num",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 210,
        "y": 180,
        "wires": [
            [
                "451e89b2.01a818"
            ]
        ]
    },
    {
        "id": "4d4ce468.c3fefc",
        "type": "inject",
        "z": "3c3c2216.c4bc4e",
        "name": "",
        "topic": "",
        "payload": "3",
        "payloadType": "num",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 210,
        "y": 220,
        "wires": [
            [
                "451e89b2.01a818"
            ]
        ]
    },
    {
        "id": "21fafb46.f82464",
        "type": "blynk-ws-in-write",
        "z": "3c3c2216.c4bc4e",
        "name": "",
        "pin": "100",
        "pin_all": false,
        "client": "3d8e7a37.045d06",
        "x": 240,
        "y": 280,
        "wires": [
            [
                "326ea4dd.7c87ac"
            ]
        ]
    },
    {
        "id": "326ea4dd.7c87ac",
        "type": "debug",
        "z": "3c3c2216.c4bc4e",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "x": 470,
        "y": 280,
        "wires": []
    },
    {
        "id": "3d8e7a37.045d06",
        "type": "blynk-ws-client",
        "z": "",
        "name": "test",
        "path": "wss://blynk-cloud.com/websockets",
        "key": "********************************",
        "dbg_all": true,
        "dbg_read": false,
        "dbg_write": false,
        "dbg_notify": false,
        "dbg_mail": false,
        "dbg_prop": false,
        "dbg_sync": false,
        "dbg_bridge": false,
        "dbg_low": true,
        "dbg_pins": "",
        "multi_cmd": true,
        "proxy_type": "custom",
        "proxy_url": ""
    }
]

New release today!! Please send feedback!!

0.7.0 - 2018-07-30

Added

  • Node - Styled Button - New node to simplify the use of this new button
  • Node - Set Property - Implemented “onColor, offColor, onBackColor, offBackColor” property for Styled Button widget (blynk cloud or local server >= v0.36.2)
  • Node - Set Property - Implemented “fraction” property for Slide widget (blynk cloud or local server >= v0.33.3)
  • Node - Table - Implemented “select, deselcet and order” commands

Changed

  • Code refactor - Extract blynk method and variable to files in “libs” directory
  • Node - Notify - Rate limit increased to 5 msg/s (Blynk Library 0.5.3)

Fixed

  • Node - zeRGBa - Check if the widget is configured in merge mode, otherwise it will generate an alert
  • Missing log on respond illegal command
  • Message ID overflow - see Blynk Library JS PR #44
  • Show protocol warning in debug panel
5 Likes

Hi, i tested the node library yesterday and had the problem that the write command on a virtual pin changed the state in app but did not called the BLYNK_WRITE(V0) function in hardware.

Using timed Blynk.syncVirtual(V0) in hardware code solved this problem.

Is there any other workaround?

hi,
in order to better understand the situation, should you give me more information about your setup? is there an arduino device and also nodered? if you do the virtual write from arduino nodered does not receive it? how is the app configured for that virtual pin?

ESP8266 on a Sonoff Switch with blynk “basic” sketch.
V0 Button in APP Writing 1/0–>Relay Switches

grafik
–>Button in App Switches but “Relay” Code does not Exceed.

Arduino Sketch:

Summary

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

char auth[] = “”; //Token
char ssid[] = “”;
char pass[] = “”;
char namingOta[] = “Switch1”;

int lastConnectionAttempt = millis();
int connectionDelay = 5000; // try to reconnect every 5 seconds
String device;
const int buttonPin = 0; // Knopf an Sonoff
const int ledPin = 13; // LED an Sonoff
const int relayPin = 12; // Relay an Sonoff
int relayState = 0;
int ledState = 1;
int buttonState;
int lastButtonState = LOW;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;

void setup()
{
delay(10000);
Serial.begin(74880);
WiFi.mode(WIFI_STA);
Blynk.config(auth);
WiFi.begin((char*)ssid, (char*)pass);
startup();
pinMode(ledPin, OUTPUT);
pinMode(relayPin, OUTPUT);
pinMode(buttonPin, INPUT);
digitalWrite(ledPin, ledState);
digitalWrite(relayPin, relayState);
}

void loop() {
if (WiFi.status() != WL_CONNECTED) {
if (millis() - lastConnectionAttempt >= connectionDelay) {
lastConnectionAttempt = millis();
WiFi.begin((char*)ssid, (char*)pass);
Serial.println(“Reconnect Try”);
}
}
else {
Blynk.run();
ArduinoOTA.handle();
}
button();
}

void startup() {
Blynk.connect();

ArduinoOTA.setHostname(namingOta);
ArduinoOTA.begin();
}

//Button an Blynk auslesen
BLYNK_WRITE(V0) {
if (param[0].asInt() == 1)
{
digitalWrite(ledPin, 0);
digitalWrite(relayPin, 1);
ledState = 0;
relayState = 1;
}
else if (param[0].asInt() == 0)
{
digitalWrite(ledPin, 1);
digitalWrite(relayPin, 0);
ledState = 1;
relayState = 0;
}
}

//Knopf an Steckdose auslesen
void button() {
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (reading == LOW) {
ledState = !ledState;
relayState = !relayState;
digitalWrite(ledPin, ledState);
digitalWrite(relayPin, relayState);
Blynk.virtualWrite(V0, relayState);
Blynk.syncVirtual(V0);
}
}
}
lastButtonState = reading;
}