[go: nahoru, domu]

Skip to content

Visualize The MQTT Cluster Network

Julius Heine edited this page Oct 31, 2018 · 17 revisions

Send data via alfred periodically

Create a systemd service which sends data to alfred periodically:

nano /home/pi/sendtoalfred.sh

#!/bin/bash

while true
do 
    # hostname at 65
    cat /etc/hostname | sudo alfred -s 65

    # vernemq node name at 66
    CONFIG_FILE=/home/pi/vernemq/_build/rpi32/rel/vernemq/etc/vernemq.conf
    TARGET_KEY=nodename

    VERNEMQNODENAME=$(cat $CONFIG_FILE | grep $TARGET_KEY | cut -d ' ' -f 3)
    echo "${VERNEMQNODENAME}" | sudo alfred -s 66

    # current milliseconds at 67
    echo $(($(date +%s%N)/1000000)) | sudo alfred -s 67
    sleep 1
done

Make the script executable:
chmod u+x /home/pi/sendtoalfred.sh

Create a systemd service which starts the script at startup:

sudo nano /etc/systemd/system/sendtoalfred.service

[Unit]
Description=Send data to batman alfred
After=network.target

[Service]
WorkingDirectory=/home/pi/
ExecStart=/home/pi/sendtoalfred.sh
User=pi
Type=simple
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

Afterwards run the following commands:

sudo systemctl daemon-reload
sudo systemctl enable sendtoalfred.service
sudo systemctl start sendtoalfred.service

Now the script periodically send data to batman.

Get information

Read alfred "topic" number 65:

sudo alfred -r 65

Get batman-vis dot, json or jsondoc information

sudo batadv-vis

sudo batadv-vis -f json

sudo batadv-vis -f jsondoc

Use dash by plotly

Install dash py plotly

pip3 install dash==0.21.1  # The core dash backend
pip3 install dash-renderer==0.13.0  # The dash front-end
pip3 install dash-html-components==0.11.0  # HTML components
pip3 install dash-core-components==0.24.0  # Supercharged components
pip3 install plotly --upgrade  # Plotly graphing library used in examples

pip3 install visdcc # network graph plugin

Install redis for data sharing between dash and other python scripts

sudo apt-get update
sudo apt-get install redis-server
sudo nano /etc/redis/redis.conf

Comment the following in the config (lines 202 ff.):

# save 900 1
# save 300 10
# save 60 10000

Add the following in the config (line 538):

maxmemory 50mb

Reboot

Install redis libs

pip3 install redis
pip3 install hiredis
pip3 install pandas

Install tmux for easy starting and developing

sudo apt-get update
sudo apt-get install tmux -y

side by side view scripted tutorial:
Youtube Video

in /home/pi

nano ~/tmux.conf

set -g history-limit 1000
set -g status-interval 1
set -g status-left '#H#[default]'
set -g status-right '#(cut -d ” ” -f 1-4 /proc/loadavg)#[default] #%Y-%m-%d %H:%M:%S#[default]'
setw -g monitor-activity on
set -g visual-activity on

nano tmux-start-all.sh

#!/bin/bash
SESSION=main
tmux="tmux -2 -f tmux.conf"

# if the session is already running, just attach to it.
$tmux has-session -t $SESSION
if [ $? -eq 0 ]; then
       echo "Session $SESSION already exists. Attaching."
       sleep 1
       $tmux attach -t $SESSION
       exit 0;
fi

# create a new session, named $SESSION, and detach from it
$tmux new-session -d -s $SESSION
$tmux new-window    -t $SESSION:0 
$tmux send-keys 'cd /home/pi/vscode_scripts/dash' C-m
$tmux send-keys './app.py' C-m
$tmux split-window  -h -t $SESSION:0
$tmux send-keys 'cd /home/pi/vscode_scripts/mqtt' C-m
$tmux send-keys 'python3 mqttinfoscraper.py' C-m
$tmux split-window  -h -t $SESSION:0
$tmux send-keys 'cd /home/pi/vscode_scripts/mqtt; python3 mqttdatatoinfluxdb.py' C-m
$tmux new-window    -t $SESSION:1 
$tmux new-window    -t $SESSION:2  
$tmux new-window    -t $SESSION:3  
$tmux split-window  -h -t $SESSION:3
$tmux new-window    -t $SESSION:4
$tmux select-window -t $SESSION:0
$tmux attach -t $SESSION

then in terminal:

#make executeable
chmod u+x tmux-start-all.sh

#start
./tmux-start-all.sh

Other commands:

C-b , d (detach)

tmux a -t main (attach main)

tmux kill-server

Sources