Family Control of Same Device

I’m running Blynk on an ESP8266 with micropython that controls my garage door opener. I am using my local Blynk server. I want to be able to have an app/project for family members to control the door, but it MUST be a different app from mine so “sharing” is not a solution. Picture a “basic” app and a “superuser” app. There are several reasons for this - more limited control, time consraints, fewer features in the app, the ability for my app to enable disable different users, etc.

I tried copying the auth key into another users con fig file on my server, but it won’t allow shared control with the same key.

I am able to run two blynk.run() calls in my main loop with two different keys on the ESP and this works, but I suspect I am using more ram than is needed, and it seems a little kludgy.

Is there a way I can run a “virtual” device on my server and have it bridge over to my ESP - or bridge the two server objects (or whatever they are called), so that my family members can have an app that talkes to the virtual device which then bridges a request over to the ESP to open the door?

The current version of Blynk isn’t really built for thi8s.

I do a similar thing using Node-Red on a Pi (can be the same one as your local server) and the Blynk plug-in for Node-Red.
I take this approach because its so much simpler than trying to do the hard work using Blynk Bridge.

With my approach you can have multiple Blynk ‘connections’ with different Auth codes, and send/receive data to/from one or more of these connections. The programming logic can be handled in Node-Red too, which makes it easier to make changes compared to changing the app and sketch.

Pete.

Thanks. I installed node-red and the blynk plugins. Can you please point me to a simple example of how I actually integrate node-red with an ESP8266 running blynk over micropython (something like an LED on/off or reading a pin).
What changes on the upython code on the ESP8266?
What changes on my phones blynk app?
What changes with my local blynk server?
What code do I need in node-red to connect two blynk apps to a single blynk ESP8266?

Thank You!
-Greg

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.