I am working on an internship IOT project. Since I am working with many sensors, I want to generate flows by adding only the macadress on the dashboard.
For now,I have made the flow of one sensor on Node Red, and the automatic scanning and connection to the sensors by coding it with python.
But I still dont know how to clone the flow of one sensor automatically andapply it to a different mac adress.
Do you have an idea on how can it be done ?
Thank you in advance.
If you write your flow to handle multiple Mac addresses/sensor types, you won't need to dynamically create flows.
What you are asking can be done but it is like using a sledgehammer to crack a nut.
I dont know how can one flow handle multiple adresses!
it's a monitoring and control system, so for each sensor I need to apply the same flow on it.
Start with one then when you add another sensor see what differences there are in the payload/topic & use logic to determine what to do.
I can't give much more than that as you have provided zero details.
I am using one raspberry pi for both sensors
a python script to read data from the sensors
and node red for the control part.
As I am willing to connect more sensors, I am looking for a way to automate the process of generating the flow for each added sensor.
What makes this a little bit more complex is you are using dashboard (the UI nodes cannot be duplicated in the flow or a subflow) easily.
I would probably go down this route...
Define an MQTT structure (e.g. sensors/mac/status)
Define a global context array to hold Mac addresses that is updated via an admin page.
Use that array to hold X number of measures & timestamps as an object (eventually this would be a database). Say, last 1000 values.
When an MQTT value arrives - if the Mac is in your array, then add (push) the value/timestamp to its array.
loop through the array and generate a drop-down & upon selecting the item populate the graph.
Loop through the array and generate (by using a template) graphs and indicators for all Macs.
Sometimes, it is just easier to modify the flows than create a dynamic dashboard.
Alternatively, you might want to look at uibuilber.
Thank you for your reply.
As for the MQTT, I tried it as a first solution, and created a local server to connect between the raspberry and node red, but the sensors keep disconnecting each time the network goes down or I cut of the internet connexion.
this is what I get on the terminal : // Device STLB230 disconnected unexpectedly. //
However, if I turn off the wifi from the raspberry, the sensors do not disconnect.
This is why I started using http instead of MQTT.
Do you have an idea about what could be the problem ?
Do you really need to filter by mac address? If you are using HTTP, aren't you only interested in anything that connects to your http endpoint?
If so, all you need to do is create a flow or global variable that is an object key'd on mac address. When you get a connection, add the new data to the variable. So if your data var is called "data" and your mac address is in msg.payload.mac, you can add the data to
data[msg.payload.mac] - that's if you are using a function node. If using a change node you can do it but the syntax is obviously slightly different.
Now you have your data in an easily accessible format and you can consume it directly in the ui Dashboard using a ui_template or you can turn it into an array and send it direct to a chart (
data.values() will turn the data object into an array in a function node).
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.