My Internet often stinks. I need a way to monitor the results of a speed test over time. Let's install a Linux computer in the house, have it run a speed test, and report it up to ThingSpeak. Now we can see a trend!
Look at this terrible trend:
We can see that my download speed dropped off from the normal 60-70 Meg. Time to call the ISP!Step 1: Install speedtest.cli
Go ahead and install it as per their instructions on their Github page. Now go ahead and run it to be sure it is working okay:
[pete@bernie speedtest]# speedtest-cli Retrieving speedtest.net configuration... Retrieving speedtest.net server list... Testing from XFINITY ()... Selecting best server based on latency... b'Hosted by Merit Network, Inc (Grand Rapids, MI) [44.11 km]: 57.593 ms' Testing download speed........................................ Download: 66.97 Mbit/s Testing upload speed.................................................. Upload: 11.96 Mbit/s [pete@bernie speedtest]#
Note that your test automatically picked a server. For trends over time, it's nice to always use the same server. Let's look at the server list, but only the first 500 characters, as it's a long list:
[pete@bernie speedtest]# speedtest-cli --list | colrm 500 Retrieving speedtest.net configuration... Retrieving speedtest.net server list... b'2406) Charter Communications (Allendale, MI, United States) [28.19 km]\n6125) Merit Network, Inc (Grand Rapids, MI, United States) [44.11 km]\n10548) Triton Technologies Inc (Grand Rapids, MI, United States) [44.11 km]\n2036) Bloomingdale Communications (Bloomingdale, MI, United States) [44.49 km]\n5866) Supernet Communications (Watervliet, MI, United States) [65.35 km]\n3240) Secant Technologies (Kalamazoo, MI, United States) [68.82 km]\n5516) CTS Telecom (Climax, MI, United States) [87.57 k [pete@bernie speedtest]#
I like Merit Network. I think I'll use that one. Note the node id "
6125". We'll need that later.
Let's set up ThingSpeak. Go ahead and sign up for Thingspeak at https://thingspeak.com/
Click on New Channel, and set it up as follows:
You can see that our speedtest program will provide ping, download and upload. Looking good. Click Save Channel, and then click on API Keys.
Note your Channel ID and your key, here.Step 3: Write your code
Get a copy of the speedtestupdate.py code, and edit the key to match your API key. Also edit the server to match the server ID you wish to use. Go ahead and run speedtestupdate.py now:
[pete@bernie speedtest]# ./speedtestupdate-demo.py Running Speedtest... Speedtest Done - ping 82.325 up 5.88 down 71.22
Looks good! Go back to Thingspeak and see that you have a plot:
Great! Run speedtestupdate.py a couple more times, and watch your chart fill in.Step 4: Automate with Cron
Now we need to just run this program every hour or so. Run Crontab -e and add the following line:
0 * * * * cd /home/pete && python speedtestupdate.py
I think that will get you going! Enjoy knowing just how good (or bad) your internet speed is over time.
Note: If you have bandwidth limitations on your service, this can use it up! Be careful what you set your speed test frequency for, and watch your data usage.
BONUS: MatLab Visualizations. Try using this MatLab visualization to look at 5 days worth of data. [Code updated 4/20/19 - Pete]
readChannelID = <your channel>; [downData, time] = thingSpeakRead(readChannelID, 'Fields', 2, 'NumDays',5);upData = thingSpeakRead(readChannelID, 'Fields', 3, 'NumDays',5);pingData = thingSpeakRead(readChannelID, 'Fields', 1, 'NumDays',5);grid onplot(time, [downData, upData])title('Speed (Download and Upload)')xlabel('Time')ylabel('Mbit/s')