Adding a broadband monitor to Weewx weather Station

 

Every time we have a spell of hot weather my broadband goes down the tubes. Last week it went from the normal no-very-good 16Mb down to to 2Mb when the mercury hit 30C. So, to investicate I need to build a system to monitor the outdoor temperature and broadband sync speed. I already have the former running on a Raspberry Pi, now I need to monitor the sync speed and integrate it with Weewx.

The Plan

Use FritzConnection to make a script to read the sync speed of my Fritz!Box.

Install the fritzconnection module for Python3 and check it works:

pi@PiWeewx:~ $sudo pip3 install fritzconnection
...
pi@PiWeewx:~ $ fritzstatus -i 192.168.1.1 -p my_password

If all is well the above will give a comprehensive a summary of the router status.

Now we need to make an executable script by adding a sherbang line at the top: #!/usr/bin/env python and using chmod +x myscript.py to modify the file permissions.

#!/usr/bin/env python3
import time
from fritzconnection.lib.fritzstatus import FritzStatus
fStatus = FritzStatus(address='192.168.1.1', password='xxxx??xxx')
while True:
print(fStatus.max_bit_rate)
time.sleep(2)

Get the code running as a service that logs connection speed to a file

For this we use init.d. This requires a second script that controls the stopping and starting of the service. See this tutorial for details. My script looks like this:

#! /bin/sh
# /etc/init.d/fritzboxloggerd
### BEGIN INIT INFO
# Provides: fritzboxloggerd
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start logging Router sync speed
# Description: Router sync speed is logged using the program fritzboxlogger.py.
### END INIT INFO

# Put any commands you always want to run here.
case "$1" in
start)
echo "Star logging"
# run the program you want to start
python3 /home/pi/fritzboxlogger.py
;;
stop)
echo "Stopping logging"
# end the program you want to stop
# (Effective but not very pretty)
killall fritzboxlogger.py
;;
*)
echo "Usage: /etc/init.d/example {start|stop}"
exit 1
;;
esac

some mods to the script. See this article by Dexter Industries (who have some very good tips on working with Raspberry Pi computers.

https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/#init

Integrate it with Weewx using the FileParse example code.