gablau / node-red-contrib-blynk-iot

Blynk IoT / Blynk 2.0 library implementation for Node-RED using TLS
MIT License
17 stars 7 forks source link

Dynamically set Auth Token #6

Closed ssozonoff closed 1 year ago

ssozonoff commented 2 years ago

Hi,

Since the Auth token is defined per device on the Blynk side it would make sense that we could set this property dynamically. But this would require a connection per auth token if I understand correctly.

Something isn't right with this design.

Thanks.

Peterkn2001 commented 2 years ago

I'm not sure that this is a feasible suggestion.

First of all, I think it's a bad idea to run Blynk code on the physical devices. It's much better to run MQTT code on the devices and leave Node-Red to deal with the communication with the Blynk server, in which case dynamic auth tokens wouldn't be used.

If you do run Blynk code on the devices then you still have the option to use static provisioning of auth tokens.

If you do want to use the Edgent sketches and do dynamic provisioning then being able to dynamically set the auth token in the Node-Red connection has no value that I can see. It would only be useful if the device could send it's auth token to Node-Red and this be used to update the auth token stored against that connection, but this is a chicken and egg situation - you cant get a connection to the device without knowing it's auth token, and without a connection the device cant send it's auth token. This means that it will always be necessary to open the Blynk web console, copy the auth token from the devoice once it's been provisioned, and paste this into the current Node-Red connection dialogue box. Having the ability to inject this auth token seems to have no benefits.

If auth tokens were still sent via e-mail then it would be a different matter, as it would be possible to use Node-Red to parse the data from the email and inject it into the connection, but that isn't how it works now.

Pete.

ssozonoff commented 2 years ago

Hi,

Thanks for your reply, maybe I am missing something ?

Blynk code is not running on the device the device communicates with a "Hub" which then forwards the data to Node-Red via MQTT.

My understanding of the model in the new version of Blynk is you have a template defining the data-streams and then one or more device using this template. In order to target (write to) a specific device (as defined in the Blynk console) you need the "device specific" auth token. So while you can build common logic in Node-Red you still need a connection per device. I have worked around this by using Rest API directly and HTTP nodes.

Serge

Peterkn2001 commented 2 years ago

From the point of view of this contrib, Blynk Legacy and Blynk IoT are exactly the same - with the exception that a Template ID is needed for IoT. In Legacy you went into the app and created a Project, then added one or more devices. Each device has it's own auth token, and you pasted that auth token into the Node-Red connection to "fool" Blynk into thinking that Node-Red was a physical device such as a NodeMCU, as opposed to a virtual hub handling the communications.

With Blynk IoT, you create a Template (similar to the Project in Legacy), and define your datastreams. You then create a Device from this Template, copy the auth token assigned to that Device, along with the Template_ID, and paste these into the Node-Red connection. When you deploy the Node-Red flow the new Device will appear online.

Although I have maybe 25 physical devices, I have only one Blynk Device set-up. I can use all 255 datastreams to attach Blynk widgets, and I use groups of widgets for communications that relate to specific physical devices. This has the advantage that widgets relating to multiple physical devices can be displayed on the same app dashboard, which is something you could do anyway with Legacy, but not with IoT.

The only thing to watch out for is that if you have the Basic (Free) subscription you are limited to 30 widgets per device. The Plus plan limit is 80 widgets per device and Pro plan is 255 per device.

Pete.

ssozonoff commented 2 years ago

Sure but I need to group devices in organisations so I dont have the luxury to have one device and scope the data via other means. I understand where you are coming from and I have found an alternative way of achieving what I needed. Kind thanks for taking the time to respond and feel to close this issue.

Serge

gablau commented 1 year ago

Technically it is not possible, because each device opens a connection to the server to send data. It's not like sending data via an http API, here is an open bidirectional channel for any device.

Of course you can create as many "configuration nodes" as you want. So you can simulate more than one device with a single installation of node-red

Best Regards Gabriele