Detecting new devices

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
billymac
Normal user
Posts: 11
Joined: 16 Mar 2017, 16:11

Detecting new devices

#1 Post by billymac » 16 Mar 2017, 16:57

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?

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Re: Detecting new devices

#2 Post by JR01 » 16 Mar 2017, 20:17

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....
-----------
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.

billymac
Normal user
Posts: 11
Joined: 16 Mar 2017, 16:11

Re: Detecting new devices

#3 Post by billymac » 16 Mar 2017, 20:21

Thanks Jr I will definately be checking out your blog

billymac
Normal user
Posts: 11
Joined: 16 Mar 2017, 16:11

Re: Detecting new devices

#4 Post by billymac » 30 Mar 2017, 16:48

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.

JR01
Normal user
Posts: 260
Joined: 14 Feb 2016, 21:04
Location: South Africa

Re: Detecting new devices

#5 Post by JR01 » 02 Apr 2017, 10:39

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.

Image
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
Image
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.
Image
Screen 3: MySQL table

The actual events goes into a table, SysTaskVal.
Screen 4: Events
Image

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
scr4_rhza_Table for Task Events.png (18.7 KiB) Viewed 4516 times
scr1_rhza_ESPs live check.png
scr1_rhza_ESPs live check.png (30.78 KiB) Viewed 4517 times
scr2_rhza_esp mqtt lost and announced on nw.png
scr2_rhza_esp mqtt lost and announced on nw.png (28.33 KiB) Viewed 4517 times
scr3_rhza_System Table.png
scr3_rhza_System Table.png (24.07 KiB) Viewed 4517 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.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests