#!/bin/bash
# additional dependencies: graphviz imagemagick

# put temporal files in ram filesystem
file="/dev/shm/networkmap"
fechahora=$(date '+%F-%H:%M')
ROOT="0x00000000000000"  # put your coordinator here
mqtthost="xxx.xxx.xxx.xxx" # change if your mosquitto is on another host
user="xxxxxxxxxxx"
pass="xxxxxxxxxxx"
echo $fechahora

mosquitto_sub -h $mqtthost -u $user -P $pass -t zigbee2mqtt/bridge/networkmap/graphviz -C 1 > ${file}routes.dot &
mosquitto_pub -h $mqtthost -u $user -P $pass -t zigbee2mqtt/bridge/networkmap/routes -m graphviz

# wait until mosquitto_sub ends
wait

cat ${file}routes.dot| dot -Kneato -Groot=$ROOT -Goverlap=false -Gnodesep=1 -Granksep=1 -Tsvg > ${fechahora}routes.svg

# display with imageMagick command
display ${fechahora}routes.svg &