A dream came true for all home internet connection subscriber and a hellish nightmare for the internet providers marketing departments…

If there’s one thing that’s the same about everyone’s broadband connection, it’s that it’s slow. Usually slower than it was advertised to be when you got it. But slow isn’t as irritating as sporadic, when you get constant drops and outages in your internet connection, it can drive you to frustration.

It drove one man in Washington D.C. to monitor his broadband connectionwith a Raspberry Pi, and automatically tweet Comcast when his connection drops to a fraction of advertised speed.

Another project, simpler too, is based on  speedtest-cli, a command line interface to the speedtest.net servers written in Python.

It’s really easy to install. Just open up a terminal window on your Raspberry Pi and type the following at the command line,

<strong>$</strong> sudo apt-get install python-pip
<strong>$</strong> sudo pip install speedtest-cli

this will install pip — a package management system for Python — if you don’t already have it installed, and then the speedtest-cli package from thepip repositories.

Once installed it’s rather easy to grab and measure your broadband speed.

<strong>$</strong> speedtest-cli
Retrieving speedtest.net configuration...
Retrieving speedtest.net server list...
Testing from Acme Broadband Provider. (XXX.XXX.XXX.XXX)...
Selecting best server based on latency...
Hosted by Foo Limited (Metropolis) [2.52 km]: 35.27 ms
Testing download speed........................................
Download: 14.47 Mbit/s
Testing upload speed..................................................
Upload: 1.46 Mbit/s
<strong>$</strong>

In any case, now that we have our command line tool installed, we can run it automatically using cron, which allows you to schedule commands to run at specified times (every hour), and log the output to a file.

The easiest way to do this is to create a quick script, let’s call it speedtest-cron.sh, which will log the date and the output of the test to a file,

#!/bin/bash
 
date >> /home/pi/speedtest.log
/usr/local/bin/speedtest --simple >> /home/pi/speedtest.log

To format the raw data output from the script and prepare a “communication” to the ISP,  IFTTT‘s Maker Channel, introduced towards the middle of last year, comes in handy. I went ahead and created a recipe on IFTTT to take the data passed to a Maker Channel event called “speedtest” and automatically fill a Google Sheet with the output of speedtest-cli script.

The easiest way to get the data from our Raspberry Pi to IFTTT at this point is to modify the speedtest-cli-extras script. Instead of printing out the output to a log file, we’ll make a POST web request with the event name and our secret key — the key is assigned when you connect the channel — of the form,

https://maker.ifttt.com/trigger/speedtest/with/key/<strong>{secret_key}</strong>

with a JSON body consisting of  three values — the latency, download, and upload speeds — to be passed on to the action in the recipe.

 You will have a google drive spreadsheet with all the scheduled measurements. To check the further steps and details visit Make:
One thought on “Track Internet Dropouts, monitor ADSL bandwidth and Notify Your ISP with RPi”
  1. Thanks for this! Very cool stuff. Just a few points…

    1) I’ve noticed a bug where the script occasionally adds an extra leading “.” to the result, i.e. “59.78” is reported as “.59.78”, this doesn’t break the script as written here, but it did break my modified version…

    2) I found that the RPi I was using under-reported my DL speed by about 20% versus the same command line speedtest run from my macbook. I was able to correct for this by maxxing out the overclock on my Pi.

    3) Having used speedtest from the web a LOT, I’ve found that I sometimes get a fluke or misleading result. Because of this, I felt a single speedtest run once hourly might not paint an accurate enough picture. Instead, I’ve modified your script so that it runs the speedtest 3 times each time it is fired, and averages the results of those three tests. Because the leading “.” bug broke this, I also added code to check for and remove that “.”. I’m not sharing the code, because I’m a noob and it’s pretty hacky, but this might be a feature you would want to consider adding.

Leave a Reply

Your email address will not be published. Required fields are marked *