Conduct a speedtest on a Raspberry Pi using speedtest-cli

Step 1: Install Speedtest-CLI

The first thing you’ll need to do is install a program called Speedtest-CLI on your Raspberry Pi. This program allows you to run speed tests from the command line. To install it, open a terminal window on your Raspberry Pi and enter the following command:

sudo apt-get install speedtest-cli

This command will download and install the Speedtest-CLI program on your Raspberry Pi.

Step 2: Run a Speed Test

Now that you have Speedtest-CLI installed, you can run a speed test. To do this, simply open a terminal window and enter the following command:

speedtest-cli

This command will initiate a speed test, and after a few moments, it will display the results of the test in the terminal window. You should see something like this:

Ping: 22.54 ms
Download: 24.54 Mbps
Upload: 3.25 Mbps

These numbers represent the latency (ping), download speed, and upload speed of your internet connection.

Step 3: Automate the Speed Test

If you want to run speed tests automatically at set intervals, you can use a simple Python script. Here’s an example script that will run a speed test every 5 minutes and log the results to a file:

import os
import time

while True:
    # Run speed test
    response = os.popen('speedtest-cli --simple').read()
    # Parse results
    ping = response.split('Ping: ')[1].split(' ms')[0]
    download = response.split('Download: ')[1].split(' Mbps')[0]
    upload = response.split('Upload: ')[1].split(' Mbps')[0]
    # Log results to file
    with open('/home/pi/speedtest.log', 'a') as f:
        f.write(f'{time.time()}, {ping}, {download}, {upload}\n')
    # Wait 5 minutes before running another test
    time.sleep(300)

To use this script, save it as `speedtest.py` and run it from the terminal using the following command:

python3 speedtest.py

This will initiate the script, and it will run speed tests every 5 minutes and log the results to a file called `speedtest.log` in your home directory.

Conclusion

That’s it! You now know how to run a speed test on your Raspberry Pi using Speedtest-CLI and how to automate the process using a simple Python script. You can use this information to monitor the performance of your internet connection over time and diagnose any issues that may arise.

Leave a Comment

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

Scroll to Top