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

Family Control of Same Device

It’s difficult to be specific, as I don’t know what you want to achieve, but here’s an overview…

image

The green boxes on the left are Blynk write event nodes. One (the “Family” app) is connected to one Auth code, the ‘Admin’ app to another. These are triggered when the widget attached to pin V1 (in either version of the app) is pressed.

Despite the apps being different, they both have a pin V1, and it performs the same function for both users. (In fact, the pins could have totally different numbers in the two apps, as they are both connected to different Auth codes, but you’d be making your life much more difficult that way.

The ‘Admin’ app has more controls, one of which is connected to pin V100 and this does some “special stuff” that is only available to the Admin user.

The outputs to the board are on the right hand side and these are blynk-ws-out-write nodes.

What you do in the middle will depend on you. They could be straight forward pass-through connections, or you could put some of your logic in the flow.

Data from the device can be passed to the app(s) in a similar way.

Pete.

Thank you so much for the help. This look promising. Node-red is completely new to me (as is blynk), and I am having some fundamental issues.
image
This is my simple trial scenario. The left node VP4 is 'write event" which is a “blynk-ws-in-write” block from the “node-red-contrib-blynk-ws” plugin. It is configured to connect to my local server as ws://192.168.1.202:8090/websockets ans with the token from the blynk app project. Note, my blynk server uses port 8090 and this works from the ESP8266 as well as the app.
The right node VP5 is a “blynk-ws-out-write” block from the same plugin. It connects to the same server, but has a different auth key. That auth key is the one that matches my ESP8266.

No joy on either end, so I powered down my ESP thinking it should still connect to the second app project, right? Both app projects show no device online.

My blynk server is throwing errors:
17 Feb 16:50:41 - [info] [blynk-ws-client:myblynk_1] Client Error
17 Feb 16:50:41 - [info] [blynk-ws-client:myblynk_1] Reconnect in 5 seconds…
17 Feb 16:50:41 - [info] [blynk-ws-client:myblynk_1] Websocket closed: ws://192.168.1.202:8090/websockets
17 Feb 16:50:41 - [info] [blynk-ws-client:myblynk_1] Reconnect in 5 seconds…
17 Feb 16:50:41 - [error] [blynk-ws-client:9f068218.b9bc8] Websocket Error: socket hang up
17 Feb 16:50:41 - [info] [blynk-ws-client:9f068218.b9bc8] Client Error
17 Feb 16:50:41 - [info] [blynk-ws-client:9f068218.b9bc8] Reconnect in 5 seconds…
17 Feb 16:50:41 - [info] [blynk-ws-client:9f068218.b9bc8] Websocket closed: ws://192.168.1.202:8090/websockets
17 Feb 16:50:41 - [info] [blynk-ws-client:9f068218.b9bc8] Reconnect in 5 seconds…
17 Feb 16:50:46 - [info] [blynk-ws-client:myblynk_1] Start connection: ws://192.168.1.202:8090/websockets
17 Feb 16:50:46 - [info] [blynk-ws-client:9f068218.b9bc8] Start connection: ws://192.168.1.202:8090/websockets
17 Feb 16:51:09 - [error] [blynk-ws-client:myblynk_1] Websocket Error: socket hang up
17 Feb 16:51:09 - [info] [blynk-ws-client:myblynk_1] Client Error
17 Feb 16:51:09 - [info] [blynk-ws-client:myblynk_1] Reconnect in 5 seconds…
17 Feb 16:51:09 - [info] [blynk-ws-client:myblynk_1] Websocket closed: ws://192.168.1.202:8090/websockets
17 Feb 16:51:09 - [info] [blynk-ws-client:myblynk_1] Reconnect in 5 seconds…
17 Feb 16:51:09 - [error] [blynk-ws-client:9f068218.b9bc8] Websocket Error: socket hang up

Any advice would be greatly appreciated.
-Greg

What version of the local server are you running?

The latest version has a bug, as discussed here…

Pete.

Ahhh… I’m running server-0.41.15.jar

So I should find a prior version?

Found a response to the issue on GIT. Using ws://192.168.1.202:8090/websocket - without the trailing “s” - shows both nodes now connected.

Strangely, the activity from the node-red server still shows errors - and the “s” is still there even though it’s not in the url setting:
17 Feb 17:52:46 - [error] [blynk-ws-client:myblynk_1] Websocket Error: socket hang up
17 Feb 17:52:46 - [info] [blynk-ws-client:myblynk_1] Client Error
17 Feb 17:52:46 - [info] [blynk-ws-client:myblynk_1] Reconnect in 5 seconds…
17 Feb 17:52:46 - [info] [blynk-ws-client:myblynk_1] Websocket closed: ws://192.168.1.202:8090/websockets
17 Feb 17:52:46 - [info] [blynk-ws-client:myblynk_1] Reconnect in 5 seconds…
17 Feb 17:52:46 - [error] [blynk-ws-client:SmallGarage] Websocket Error: socket hang up
17 Feb 17:52:46 - [info] [blynk-ws-client:SmallGarage] Client Error
17 Feb 17:52:46 - [info] [blynk-ws-client:SmallGarage] Reconnect in 5 seconds…
17 Feb 17:52:46 - [info] [blynk-ws-client:SmallGarage] Websocket closed: ws://192.168.1.202:8090/websockets
17 Feb 17:52:46 - [info] [blynk-ws-client:SmallGarage] Reconnect in 5 seconds…
17 Feb 17:52:51 - [info] [blynk-ws-client:myblynk_1] Start connection: ws://192.168.1.202:8090/websockets
17 Feb 17:52:51 - [info] [blynk-ws-client:SmallGarage] Start connection: ws://192.168.1.202:8090/websockets

Have you actually read the link, including the need to restart Node-Red?
It’s all in the link!

Pete.

Yes, I read it. So went to the blynk repository to get the old version and found the issue and a reply about about removing the “s” from the url with version 41.15. So I am still running 41.15 with “s” removed. And yes, I restarted node-red (and blynk server)… twice. The errors shown still are displayed.

The good news is both endpoint nodes behave as expected. One blynk app can set virtual pin 4, and the other app correctly reads virtual pin 5 and shows the changed state.

All the while both nodes show Client Error and reconnect in 5 secs, repeatedly.

Again, can’t thank you enough for getting me this far, this fast!!!
:slight_smile:

Thanks,
-Greg

Admittedly, I’m not a SW guy and have a mere few hours exposure to blynk and node-red, but changing the url to “/websocket” and still seeing “/websockets” (still with the “s”) in the errors from node-red seems like it may point to a remaining issue?

Still, I’m pretty amazed the app and nodes are working despite these errors and reconnects.

:slightly_smiling_face:

BTW, I noticed the “Websocket Error: socket hang up” and “Client Error” messages reoccur ever 23 seconds. This happens to be the same interval I see dropped connection to my ESP8266 from the blynk app without node-red in the picture at all.

So maybe this is a blynk server issue?

Changed to blynk server 41.14 and all the client error and reconnect messages from node-red disappeared. So apparently there is more the problem with 41.15 than just the trailing “s”

-G
-Greg

I’m still a little confused about why you needed to find out about about dropping the ‘s’ from the end of ‘websockets’ when the info was in the topic that I linked to.

My guess is that you have additional Blynk connections defined in Node-Red and that one of these is still using ‘websockets’ rather than ‘websocket’.
I’m running version 0.41.15 of Blynk local server with Node-Red and have no problems - now that I changed all of my connections to ‘websocket’.

Pete.

Yes your link mentioned the “s” which I believe originated in the git issue thread.
I definitely don;t have additional blynk connections in node-red. In fact, I can rename the node and the node-red connection errors reflect the new name (“smallgarage”, as you can see in my error post).
As I said, it works - but the errors are printed by node-red with 41.15. Btw, I am running node-red in a bash terminal, so there is an xterm attached that node-red can output to. I suspect that if (and when) I make it a sysctl service, the client error and reconnect messages would be undetected/unseen. Is there a node-red log somewhere that would have the same messages I am seeing in the xterm?

I am using 41.14 since there are no errors. When I get some time, I will re-run with 41.15 and see if the errors persist, and post the results (although I already did this with a blynk and node-red reboot).

-G

There is, but these…

messages can be seen in the Node-Red debut console.

No, the topic I linked you to was created/solved on 10th Feb. The GitHub issue was raised on 16th Feb, and this issue…

was raised at the same time.

Pete.

Again, thanks for getting me going with this! I have the single left side and signle right side node flow working where I can control the ESP. If I understand how this working it looks something like this:
App1 --> blynkserver w/key1 --> nodered_in_write w/key1 --> nodered_write_out w/key2 --> blynkserver w/key2 --> ESP8266 w/key2

Is this correct?

So now I’m trying to add App2 w/key3 and I’m running into issues. Previously key2 was connected to a blynk app, but I refreshed it get a 3rd key. Now I have App1 w/key1, App2 w/key3, and two nodered in_write blocks, one w/key1 and one w/key3. All these are connected to the blynk server.

However, the nodered write_out and ESP both have key2 and neither are connecting to the blynk server (esp error is invalid auth token). It looks like the blynk server replace key2 with key 3 and key 2 no longer exists? Do I need a permanent dummy App with a key that matches the ESP and nodered write_out before the blynk server will allow those to connect?

Thanks,
-Greg

I added a button and new device to App1. This gave me a new key2, which I also put on the ESP. All nodered and the ESP are now connected.

The new button can control the ESP HW as expected. But if i hit button 1 on App1 or the button on App2 (all of which are virtual pin 4, as is button 2 on App1), the second button on App1 chnages state but the ESP never sees it.

Any ideas?

-Greg

You’ve lost me there I’m afraid. Maybe best to start with a fresh project on each app and new auth codes.
The device obviously needs a valid auth code, which could exist as a second device in your Admin version of the app, or in a separate project.

Pete.

Ya sorry for the confusion. I prob tried too many things, so back to basics…

With this new Flow (old flow deleted), I have an app w/key3 with one button that flips VP5, which is connected to the node on the left, also VP5. I thought that would drive the node on the right, which should drive VP4 out to the blynkserver via key2. The ESP is also connected o the blynk server via key2 and will respond to VP4.

However, the ESP will not respond to the button press on the app.

-G

What code are you running on the ESP?

Pete,

micropython, BlynkLib, vshymanskyy version

This same ESP code works fine if I drive it with a VP4 button directly from an app.

Partial code:

@blynk.on(“V4”)
def v4_write_handler(value):
global l
if int(value[0]) == 1:
p2.value(0)
else:
p2.value(1)

blynk = blynklib.Blynk(BLYNK_AUTH, server=
while True:
blynk.run()

It looks like the VP4 is making it out of node-red, since I have seen the VP4 button flip states in a different app that was connected with the same key as the ESP.

The left node is a blynk_ws_in_write.
The right node is a blynk_ws_out_write.

Still trying to understand all the interconnects. With my simple scenario (picture above) from the blynk server’s perspective:

It has a connection to an App with key3 and a connection to nodered blynk-ws-in-write with key3.

Then it also has a connection to a nodered blynk-ws-out-write with key2 and a connection to the ESP with key2. But that key only got created because an app generated that key, is there a 3rd connection to that app with key2? Does 3 endpoint confuse the blynk server? Is there a wasy to have the ESP and nodered connected aith a key without an app also having that key?

Sorry, I forgot that you need a Sync node to force the server tp push the new value out to the device…

I’ve set-up 3 devices (with non politically correct names :wink:)…

  • Master (Admin app)
  • Slave (Family app)
  • Dummy (to give an auth code that is used by the ESP).

In this flow, I’m just using Master and Dummy.

Pressing the button attached to V1 in the master app triggers the Write Event in the top left. This goes to to the Write node in the top right.
It also goes via a 5ms delay to the Sync node which is also connected to pin V1 on Dummy. This is what forces the server to send the latest value from the server to the ESP. The delay is to ensure that it is the updated value, not the previous value.

The Write Event node on the bottom left is triggered when the updated values is received by Pin 1 on the Dummy device (the ESP). The result is printed in the debug area by the Msg node.

Pete.

I tried your example, still no control of the ESP. I do see “1” and “0” as the msg.payload when I hit the V5 button in the App.

It appears to me that node-red is sending the V4 command out to the blynk server, since a second app with a V4 button and the same key as the ESP sees the msg and changes the button state in the app. It just seems that blynk server is not also sending that V4 msg to the ESP, only to the app. Does the blynk server expect to only send it to one endpoint?

Btw, this behavior is identical without the delay & sync, i.e. the blynk app still sees the V4 from node-red and sends it to the app and the button changes. The only thing that didn;t happen without the sync, is the debug msg never displayed on the V5 button press in the app (although again, the V4 button did change state).

Unless you give some indication which auth codes your various nodes are using it’s very difficult to comment.

Pete.

After digging a little more and testing with some python code on my laptop, it looks as though node-red was doing what it needed to do the whole time. Apparently the blynk server was getting the update virtual pin info from node-red and updating the app (buttons, led, value, etc) but never sent the updated virtual pin value to the ESP. So the ESP never saw a write event, even though it all started with an app button press. Still not sure why the blynk server never sends the button press to the ESP when node-red is involved. I guess only if the app itself is the source, will the server send to all endpoints.

The ESP needed a blynk.sync_virtual(4) to get the new value from the blynk server.

So after all that, it tuns out that a couple of lines of python code is all that is needed to allow multiple family members to each have their own blynk app and control a single ESP. So I’m going to keep it simple for now and use a python background job to do the bridging.
:slight_smile:

It would nice for the next user if all these lessons learned were in a readme as part of the blynk and/or node-red git repository.

Now that all these pieces are talking to each other, I can work on making the ESP endpoints more robust and auto-healing, as well as user-friendly blynk app for the fam.

Thanks again for all your help on this!

-Greg

1 Like