Zigbee2mqtt network map
Posted: Monday 17 February 2020 12:17
Hi,
Don't know if someone did this before but I wanted to visualize my zigbee network map from within domoticz.
After some digging around I found : https://community.openhab.org/t/zigbee2 ... p/57784/29
It looked realy nice, and i wanted to implement this in my domoticz environement.
So i wrote a little python script to make this possible.
Prerequisites:
Graphviz installed (sudo apt-get install graphviz)
Graphviz dev files installed (sudo apt-get install -y graphviz-dev)
Python module : Paho mqtt client (pip3 install paho-mqtt)
you need an web server to display the map.
I used the default from domoticz (/domoticz/www) because it is already available, but any other will do.
First place the following files into the web root folder :
https://github.com/ariutta/svg-pan-zoom ... oom.min.js
(you can download it with and move it to the web root folder)
This is needed so the generated svg file can be zoomed in/out from the browser.
The create a html file in the web root folder (e.g. ZigBee.html) with the following content :
Adjust if needed the File References settings.
Schedule the python script to run e.g. every day, (after running refresh your browser cache, as I noticed the page does not update automatically)
After running the script you can go to your domoticz url with the "ZigBee.html" in the address.
e.g. http://domoticz_server_ip:port_number/ZigBee.html

What it does :
The script connects to the mqtt server and issue's two commands
An subscribe to the "zigbee2mqtt/bridge/networkmap/graphviz" topic and a publish to the "zigbee2mqtt/bridge/networkmap", "graphviz"" topic
The "client.loop_forever() is needed to wait for the mqtt server to respond with a message, because the subscribe/publish command need a little while to complete. It is basically an command to the sniffer to poll it's network and report the connections back.
This should not be done very frequently because it could congest your ZigBee network for a little while (especially in large networks with a lot of polling requests to do)
When a message is received (the data for the dot file) it wil be send to the dotfile.
This is the structure needed for graphviz to create a SVG file.
The the svg file is created with the "sfdp" command and placed into the web root folder.
Any suggestions and/or improvements are welcome.
(The next step is to replace the blocks with nice graphic/images but first I have to read in to the graphviz dot language....)
Regards
Peer
Don't know if someone did this before but I wanted to visualize my zigbee network map from within domoticz.
After some digging around I found : https://community.openhab.org/t/zigbee2 ... p/57784/29
It looked realy nice, and i wanted to implement this in my domoticz environement.
So i wrote a little python script to make this possible.
Prerequisites:
Graphviz installed (sudo apt-get install graphviz)
Graphviz dev files installed (sudo apt-get install -y graphviz-dev)
Python module : Paho mqtt client (pip3 install paho-mqtt)
you need an web server to display the map.
I used the default from domoticz (/domoticz/www) because it is already available, but any other will do.
First place the following files into the web root folder :
https://github.com/ariutta/svg-pan-zoom ... oom.min.js
(you can download it with
Code: Select all
wget https://github.com/ariutta/svg-pan-zoom/blob/master/dist/svg-pan-zoom.min.jsThis is needed so the generated svg file can be zoomed in/out from the browser.
The create a html file in the web root folder (e.g. ZigBee.html) with the following content :
- Spoiler: show
- Spoiler: show
Adjust if needed the File References settings.
Schedule the python script to run e.g. every day, (after running refresh your browser cache, as I noticed the page does not update automatically)
After running the script you can go to your domoticz url with the "ZigBee.html" in the address.
e.g. http://domoticz_server_ip:port_number/ZigBee.html

What it does :
The script connects to the mqtt server and issue's two commands
An subscribe to the "zigbee2mqtt/bridge/networkmap/graphviz" topic and a publish to the "zigbee2mqtt/bridge/networkmap", "graphviz"" topic
The "client.loop_forever() is needed to wait for the mqtt server to respond with a message, because the subscribe/publish command need a little while to complete. It is basically an command to the sniffer to poll it's network and report the connections back.
This should not be done very frequently because it could congest your ZigBee network for a little while (especially in large networks with a lot of polling requests to do)
When a message is received (the data for the dot file) it wil be send to the dotfile.
This is the structure needed for graphviz to create a SVG file.
The the svg file is created with the "sfdp" command and placed into the web root folder.
Any suggestions and/or improvements are welcome.
(The next step is to replace the blocks with nice graphic/images but first I have to read in to the graphviz dot language....)
Regards
Peer