I hope I can get some tips on the following:
I have Node-Red + Mosquitto broker running on a Raspberry Pi 3
I also have installed ESPEasy on a Node MCU Dev board and I am ready to start testing communication from Node Red to the ESP via MQTT
But one thing I want to do, I have not been able to find any examples or help on.
I plan to create several custom lighting devices, each with an ESP8266 running EasyESP
I want to have a section on my Node Red dashboard that shows all of the devices.
I could easily add a node for each on my dashboard but I want them to be detected and added automatically as each device is turned on.
I suppose I could add (say) 20 of my lighting devices on the dashboard, and as each is turned on, it publishes a custom message which Node-Red reads and changes the icon for that device to make it enabled(each would need an ID).
But it would be better to have each device appear/disappear from the dashboard as they are turned on/off.
Any ideas?
Detecting new devices
Moderators: grovkillen, Stuntteam, TD-er
Re: Detecting new devices
I have a rule in every ESP I deploy, like this:
on System#Boot do //
Publish sensors/espeasy/announceESP,%sysname% // Announce ESP
endon
Then in NR I write this to a table, with a process to validate those in the table as a valid ESP, which, when it announces, I check against.
I also have a NR report on my phone that checks if those that are supposed to be live, are live. I plan to blog about my systems management approach on my blog http://iotplay.blogspot.com ; did not get so far yet....
on System#Boot do //
Publish sensors/espeasy/announceESP,%sysname% // Announce ESP
endon
Then in NR I write this to a table, with a process to validate those in the table as a valid ESP, which, when it announces, I check against.
I also have a NR report on my phone that checks if those that are supposed to be live, are live. I plan to blog about my systems management approach on my blog http://iotplay.blogspot.com ; did not get so far yet....
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.
Re: Detecting new devices
Thanks Jr I will definately be checking out your blog
Re: Detecting new devices
JR- tried your code snippet and it works fine
The MQTT message shows up in node-red debug window whenever my device boots.
My next plan it to figure out how to create my own custom node that will display an icon dynamically as each device is detected and display the status of each.
Hopefully I am on the right track and not re-inventing any existing wheels
My javascript so far looks at the mqtt payload which is a line of Json that includes such things as deviceID, Color and state.
If it sees a Device ID that isn't already in the devices variable (array of devices) it adds it to the array and the UI
If it sees a property value that has changed in the payload, it updates the property
A timer also runs to remove any devices from the array if it didn't get a payload with that device ID after X seconds.
The MQTT message shows up in node-red debug window whenever my device boots.
My next plan it to figure out how to create my own custom node that will display an icon dynamically as each device is detected and display the status of each.
Hopefully I am on the right track and not re-inventing any existing wheels
My javascript so far looks at the mqtt payload which is a line of Json that includes such things as deviceID, Color and state.
If it sees a Device ID that isn't already in the devices variable (array of devices) it adds it to the array and the UI
If it sees a property value that has changed in the payload, it updates the property
A timer also runs to remove any devices from the array if it didn't get a payload with that device ID after X seconds.
Re: Detecting new devices
I carry in MySQL the devices, and if I expect that device to be live or not.
Then, I check against the once that are supposed to be live, if they are live with advanced ping test. See screen1.
Screen 1: ESP live check.
I write the ESP's which announces them selves on the network, via the below rules, to a table, then, I present this table so I can see how often the ESP announces itself, (i.e. it rebooted) see screen 2, as well as when I have lost the mqtt connection.
Screen 2: Screen showing mqtt msg lost, and Systems announced on the network
Here is the Systems Table on MySQL where I hold the systems, and its expected status.
Screen 3: MySQL table
The actual events goes into a table, SysTaskVal.
Screen 4: Events
If you want to read more of how I designed the database, see this post: http://iotplay.blogspot.co.za/2016/05/a ... ation.html
Then, I check against the once that are supposed to be live, if they are live with advanced ping test. See screen1.
Screen 1: ESP live check.
I write the ESP's which announces them selves on the network, via the below rules, to a table, then, I present this table so I can see how often the ESP announces itself, (i.e. it rebooted) see screen 2, as well as when I have lost the mqtt connection.
Code: Select all
on System#Boot do //
gpio,16,0 // R1 - pool - off
Publish sensors/espeasy/announceESP,%sysname% // Announce ESP
endon
on RebootUnit do Reboot
Screen 2: Screen showing mqtt msg lost, and Systems announced on the network
Here is the Systems Table on MySQL where I hold the systems, and its expected status.
Screen 3: MySQL table
The actual events goes into a table, SysTaskVal.
Screen 4: Events
If you want to read more of how I designed the database, see this post: http://iotplay.blogspot.co.za/2016/05/a ... ation.html
- Attachments
-
- scr4_rhza_Table for Task Events.png (18.7 KiB) Viewed 4521 times
-
- scr1_rhza_ESPs live check.png (30.78 KiB) Viewed 4522 times
-
- scr2_rhza_esp mqtt lost and announced on nw.png (28.33 KiB) Viewed 4522 times
-
- scr3_rhza_System Table.png (24.07 KiB) Viewed 4522 times
-----------
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.
IOTPLAY. Tinkerer, my projects are @ http://GitHub.com/IoTPlay, and blog https://iotplay.org. Using RPi, Node-Red, ESP8266 to prove Industry 4.0 concepts.
Who is online
Users browsing this forum: No registered users and 44 guests