![]() Great! Step 5: Integrate the script with Google Drive If you check the contents of the file (for example, cat speedtest/speedtest.csv), you can see lines like these:ĭate,Time,Ping (ms),Download (Mbit/s),Upload (Mbit/s) …we will have a CSV file with broadband speed data in our new directory. Now, if we run our Python script like this: python speedtest.py > speedtest/speedtest.csv Once synced, everything inside the directory will correspond the contents of our similar Google Drive directory. If you’re wondering why we need a directory for a single file, it’s because we’re going to sync that directory to Google Drive. Let’s create a directory for our CSV file: mkdir speedtest You can run the script with the following command: python speedtest.pyĪnd if you do, you should see a line like this:Īlright, we’re ready to move on! Step 4: Create a directory The script runs speedtest-cli in its simple mode, parses the output, and prints it out in CSV format. (I’m assuming that you’re saving the script in the /home/pi/ directory – if not, just change the path here: if os.stat(‘/home/pi/speedtest/speedtest.csv’).st_size = 0.)Īfter you have the lines in place, you can save the file and exit the editor by pressing Ctrl+X, Y, and Enter. Print ''.format(time.strftime('%m/%d/%y'), time.strftime('%H:%M'), ping, download, upload) Print 'Date,Time,Ping (ms),Download (Mbit/s),Upload (Mbit/s)' If os.stat('/home/pi/speedtest/speedtest.csv').st_size = 0: Upload = re.findall('Upload:\s(.*?)\s', response, re.MULTILINE)ĭownload = download.replace(',', '.') Ping = re.findall('Ping:\s(.*?)\s', response, re.MULTILINE)ĭownload = re.findall('Download:\s(.*?)\s', response, re.MULTILINE) Response = subprocess.Popen('speedtest-cli -simple', shell=True, stdout=subprocess.PIPE).stdout.read() Here’s what we should have inside the file (you can, of course, copy-paste these lines): import os Let’s create a new Python file: sudo nano speedtest.py Therefore, we’ll need to parse the data and make it conform. However, that output doesn’t conform to the CSV syntax. Though, for our purposes, using speedtest-cli’s simple mode is more convenient: speedtest-cli -simple With speedtest-cli now installed, you can measure your broadband speed easily with this command: speedtest-cli Next, let’s use pip to install speedtest-cli: sudo pip install speedtest-cli If you a message that reads “python-pip is already the newest version,” that means that we’re good to go. You can make sure that you have pip by running this command: sudo apt-get install python-pip That’s easy to do so by using a tool called pip that comes preinstalled on Raspbian Jessie and Stretch. Speedtest-cli isn’t available right away from the Raspbian archives, but we can install it from the Python Package Index (PyPI). ![]() We’re going to use speedtest-cli, which, in the words of its creator, is “a command line interface for testing internet bandwidth using .” There are various methods to measure the speed of broadband connection. Sudo apt-get upgrade Step 2: Install speedtest-cli Run the following commands in Terminal: sudo apt-get update How to use your Raspberry Pi to monitor broadband speed Step 1: Check for updatesĪs usual, let’s start with checking for the latest updates. This how-to will assume you already have Raspbian installed on your Pi. Sound like a handy thing? Then let’s get started. CSV is a very simple file format that can be opened in Microsoft Excel or imported to Google Sheets. The monitor will create a CSV (comma-separated values) file to your Google Drive and update that file once an hour. ![]() But once we’ve laid the groundwork, we can automate our broadband monitor so that it keeps right on monitoring for as long as we want. This project involves a fair bit of setup, including downloading and installing some packages, writing a Python script, and more. In this article, we’ll show you how to use the Raspberry Pi to monitor broadband speed.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |