[TODO]
object//sensor_or_relay
'system' - system messages start up
'alarm': 'ExtPwr' 'DrainOn' 'Flood'
'set': 'RemCtrl' 'Pump1' 'Pump2'
'pressure' - pressure data
'status': 'Pump1' 'Pump2' 'Pump3' 'DoorOpen' 'Rake' 'Level1' 'Level2' 'Level3'
- Install latest Raspbian on RPi
- Enable SSH and I2C via raspi-config on RPi
- Update system
sudo rpi-update
sudo apt update && sudo apt dist-upgrade
apt install -y git python3 python3-pip
apt-get install -y python3-smbus python3-rpi.gpio i2c-tools
apt install openvpn wvdial policykit-1 tmux
#for debugging install mosquitto-clients
apt install mosquitto-clients
Install paho-mqtt
pip3 install paho-mqtt
Clone repository
mkdir /opt/watertower
cd /opt/watertower
git clone https://github.com/z80x1/watertower.git
chmod +x /opt/watertower/RPi/wtower.py
Examples config file
$ cat /etc/wtower.conf
[default]
Nodetype = tower
Nodename = wt2
BrokerIp = 10.10.10.213
BrokerPort = 1883
$ cat /etc/wtower.conf
[default]
Nodetype = kns
Nodename = kns01
BrokerIp = 10.10.10.213
BrokerPort = 8883
Unit file
# cat /etc/systemd/system/wtower.service
[Unit]
Description = monitoring pumps and sensors
#After=wvdial.target
After=network-online.target
Wants=network-online.target
[Service]
Type=idle
ExecStart=/opt/watertower/RPi/wtower.py
#StandardOutput=syslog
#StandardError=syslog
#SyslogIdentifier=wtower
Restart=always
RestartSec=10
[Install]
WantedBy = multi-user.target
Enable service
systemctl enable wtower.service
systemctl start wtower.service
#unneeded with Raspbian 9 and Huawei E172 modem
sudo usb_modeswitch -v 12d1 -p 14fe -J
# cat /etc/wvdial.conf
[Dialer life]
Modem = /dev/ttyUSB0
Baud = 460800
Init1 = ATZ
Init2 = AT+CGDCONT=1,"IP","internet"
Phone = *99***1#
Stupid mode = 1
Username = " "
Password = " "
Manual run wvdial
sudo wvdial life &
# cat /opt/modem.sh
#!/bin/bash
usb_modeswitch -v 12d1 -p 14fe -J
sleep 1
wvdial life
sudo chmod +x /opt/modem.sh
wvdial service
# cat /etc/systemd/system/wvdial.service
[Unit]
Description = WvDial service
#After = network.target
[Service]
Type=idle
ExecStart=/opt/modem.sh
Restart=always
RestartSec=10
[Install]
WantedBy = multi-user.target
Enable service
systemctl enable wvdial.service
systemctl start wvdial.service
- Install Docker on server
apt install mosquitto-clients docker.io
-
Add user wtower
-
Using vigr utility add wtower to groups adm,sudo,docker,netdev
-
Pull and run mosquitto container
docker pull eclipse-mosquitto
sudo mkdir -p /srv/mosquitto/{data,log}
sudo chown -R :docker /srv/mosquitto
sudo chmod -R g+w /srv/mosquitto
sudo chmod -R 777 /srv/mosquitto/{log,data}
/srv/mosquitto/run_broker.sh
Publishing instructions to relays
mosquitto_pub -h localhost -t wt2/set/Pump2 -m on -q 1 --retain
Only Pump1, Pump2 and RemCtrl topics are permitable. Payload can be either 'on' or 'off'.
Subscribing to all messages coming to broker
mosquitto_sub -h localhost -t '#' -v | xargs -d$'\n' -L1 sh -c 'date "+%D %T.%3N $0"'
Connecting to broker with TLS enabled
mosquitto_sub -h localhost -p 8883 --cafile /srv/mosquitto/data/tls/ca.crt --insecure -t '#' -v | xargs -d$'\n' -L1 sh -c 'date "+%D %T.%3N $0"'
Run HTTP server
cd web/mqtt-panel
docker run -dit --name my-apache-app -p 8080:80 -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4
Point your browser to http://localhost:8080