I recently read Use Raspberry Pi to Measure Broadband Speeds to Hold Your ISP Accountable on Make and realised that this was an excellent candidate for monitoring my somewhat unstable Virgin Media connection.
I use an OpenWRT router (running a VPN to add a little bit of privacy), so I could adapt the article to run on the router rather than an attached Raspberry Pi.
Here are the steps adapted for OpenWRT...
OpenWRT uses opkg
rather than apt-get
, so that is used throughout as a replacement.
Install pip
-- a packaging manager for Python and the speedtest-cli
package from the pip
repositories.
opkg install python-pip
pip install speedtest-cli
Test out the installed package:
root@OpenWrt:~# speedtest-cli
Retrieving speedtest.net configuration...
Retrieving speedtest.net server list...
Testing from Virgin Media (x.x.x.x)...
Selecting best server based on latency...
Hosted by Virgin Media (Nottingham) [2.68 km]: 20.29 ms
Testing download speed........................................
Download: 156.39 Mbit/s
Testing upload speed..................................................
Upload: 9.84 Mbit/s
So far so good.
Next, we need to run the following script. I've saved it at /root/bin/speedtest-ifttt.sh
Update log=/tmp/$user/speedtest-csv.log
to log=/$user/tmp/speedtest-csv.log
Add the key to line 82
secret_key="SECRET_KEY"
OOTB, OpenWRT doesn't have bash or curl, so install that too:
opkg install bash curl
Make a directory to save the temperary file:
mkdir ~/tmp
Add execute permission:
chmox +x /root/bin/speedtest-ifttt.sh
Now, run the file once & see if it creates a Google Sheet and saves details to the sheet
/root/bin/speedtest-ifttt.sh
If all is good, add this to the cron
job and sit back:
crontab -e
15,45 * * * * /root/bin/speedtest-ifttt.sh
Right now, I'm measuring the speed every 30 minutes at 15, 45 mins past the hour. This can be changed to be run more frequently, as required.
At this point, I created a chart in the Sheet so that I could view the data being collected.
Here are the results so far: