We're gonna install the Okla Speedtest (speedtest.net) CLI and a write the results into a Airtables table.
First we're gonna install all required dependecies to run the speedtest CLI.
sudo apt-get install gnupg1 apt-transport-https dirmngr jq
export INSTALL_KEY=379CE192D401AB61
export DEB_DISTRO=$(lsb_release -sc)
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $INSTALL_KEY
echo "deb https://ookla.bintray.com/debian ${DEB_DISTRO} main" | sudo tee /etc/apt/sources.list.d/speedtest.list
sudo apt-get update
sudo apt-get install speedtest
To run the speedtest CLI, just call speedtest
.
To save the results of the speedtest in a table using Airtable, simply visit this template table https://airtable.com/shrpCK2GwdX5ycnPq and press the "Copy base" button (upper right corner).
To get the base id, which is needed for the API calls to Airtable, click on the "Help" button in the table view and proceed to "API documentation". There you should find your base id and API key (by checking the "show api key" checkbox).
The speedtest.sh
attached to this Gist can be downloaded by running
wget https://gist.githubusercontent.com/jlis/7b570314ca1538c45444d2c88de39438/raw/speedtest.sh
Make to to make it executable using chmod +x speedtest.sh
.
Now let's edit the script and insert your API key and the base id from Airtable using nano speedtest.sh
.
Just replace the <API KEY>
with your Airtable API key and the BASE ID FROM API DOCS
with the base id you got from the API documentation earlier.
You should now be ready to run the script for the first time: ./speedtest.sh
.
If everything is working, the result should be written to your Airtable table.
To create a cronjob for the script and run it, for example, every hour, run crontab -e
to write a new cronjob.
0 * * * * /home/pi/speedtest.sh
This cronjob will run the speedtest.sh
in the pi users home directory every hour.
That's it, your Raspberry Pi should now do a speedtest every our and write the results into a table. If you have any questtions or points for improvement, please let me know.
Thank you. This was very helpful and worked almost flawlessly. However, please note that Ookla are now (10 August 2021) distributing their version of speedtest cli differently from your example. See https://www.speedtest.net/apps/cli.
I also had some problems getting the cron job to run, which turned out to be because I had put speedtest in /usr/local/bin and cron wasn't finding it. Moved it to /usr/bin and all was well.