Bandwidth Monitor




Introduction: Bandwidth Monitor

About: I have a background in mechatronics and that's what I like - the combination of electronics, mechanics and software to a well functioning overall system. Since I own a 3D printer (ok, there are 2 now ;-)) and…

As I often asked myself what bandwidth is currently provided by my ISP (I use a LTE modem for the Internet connection), I thought of a bandwidth monitoring system.
Since the system should be compact and power-saving, I chose a Raspberry Pi Zero as the central component. The Raspberry is connected to the modem via WLAN, therefore WLAN problems can be detected as well.


Step 1: Features

  • The Raspberry Pi Zero is connected via WLAN, tests up- and download speed and performs a ping measurement every half hour . A command line version of is used as the basis for the measurements.
  • The result of the bandwidth and ping measurement is shown on an e-ink display. The time of the measurement is also shown.
  • If the download speed falls below a defined threshold value, a relay switches the modem off and on for a short time. The modem is thus reset without any modification of the device (only the power supply is interrupted).
  • A button on the front of the device is available to trigger the bandwidth measurement manually.
  • The measured values are displayed on a Ubidots Dashboard (IOT Portal). In the overview you can also see the time history of the measured values and the reasons for the last resets.
  • In the IOT Portal you can also find a button to remotely reset the modem.
  • The Bandwidth monitor uses the power supply of the modem. No additional supply needed. The relais interrupts the forwarding of the power supply to the modem - the raspberry remains switched on.

Step 2: Wiring

In the first picture you can see the internal design of the bandwidth monitor:

The major components are:

    1. Push button
    2. E-ink Display
    3. Raspberry Pi Zero
    4. Relay Module
    5. RGB LED + Resistors (depending on the RGB LED you use)
    6. Switch
    7. DC-DC Converter
    8. Female connector

The second picture shows a schematic of the wiring. The positive pole of the supply voltage is fed via the switch to the DC-DC voltage converter (which converts the 12V supply voltage of the router to 5V for the Raspberry) and via the relay (via the normaly-connected pin) back to the output connector. Thus the modem is also supplied with power when the bandwidth monitor is switched off.

The bandwidth measurement can be started manually via a button. A RGB LED is used to visualize the various operating states.

The connection between Raspberry Pi and e-ink display is not shown in the circuit diagram. Connect the display according to the table and the pin-out above.

Step 3: 3D Printing and Building the Chase

The following parts are needed for the case (see picture above):

    1. lower part
    2. upper part
    3. front
    4. back
    5. 4x mount

All the parts can be printed without supports. You also can find the files and some of my other designs on Thingiverse:

The display can be attached to the front panel with the mounts and a doublesided tape. Button switch and femal connector are screwed to the back- and rear panel. I used 3x20mm screws to connect the two halves of the housing. The tolerances on the grooves for the front and rear panels are relatively tight. If necessary, the front and rear panels must be sanded on the edge (on the inside to avoid destroying the surface).

Step 4: Setting Up the Raspberry PI

This setup guide is based on compiling several installation instructions from different sources (e-Ink display manufacturers,...). For me the instructions have led to the desired result. Since I am not a Linux expert, no optimizations or similar were done. I am aware that there are surely better and more efficient solutions.

Lets assume you already have Raspbian installed on your Pi (there are many tutorials on how to install the basic operation system) and you have a display (via miniHDMI), mouse and keyboard connected. A correctly set up WLAN connection to the router or the Internet is also assumed. Unless otherwise stated, all installation procedures are performed in the terminal.

Install Remote desktop (to access the PI from your computer):

sudo apt-get update
sudo apt-get 
install xrdp

or you can also work headless via ssh (see e.g.

Change Password:

Install speedtest:

apt-get install python-pip
sudo pip install speedtest-cli

to test if installation was successful run Speedtest in the terminal:


if everthing is correct you should get something like in the first picture above.

Install wiringPI

sudo apt-get install git-core
git clone git://
cd wiringPi

(see also


sudo apt-get install wiringpi


Install BCM2835


Download bcm2835-1.60.tar.gz (or a newer version if available)

tar zxvf bcm2835-1.60.tar.gz
cd bcm2835-1.60
sudo make check
sudo make install

Install the Python imaging library

sudo apt-get install python-imaging


sudo apt-get install python-pil

Enable the I2C function.

Run the following command to configure your Raspberry Pi board:

sudo raspi-config

Select Interface Options-> I2C -> yes, to start up the I2C core driver. Then you also need to modify the configuration file. Run the following command to open the configuration file:

sudo nano /etc/modules

Add the following two lines to the configuration file


See also

Enable the SPI function:

Run the following command to configure your Raspberry Pi board:

sudo raspi-config

Select Interface Options-> SPI -> yes, to start up the SPI core driver.

Install additional fonts:

sudo apt-get install ttf-mscorefonts-installer

Download and install Fonts (Roboto + Droid)


To start filemanager with root privilegs and copy truetype fonts into folder /usr/share/fonts/truetype


Copy the fonts to the Downloads folder with WinSCP (ssh must be enabled to use WinSCP)

sudo cp -r /home/pi/Downloads/droid /usr/share/fonts/truetype
sudo cp -r /home/pi/Downloads/roboto /usr/share/fonts/truetype

You need root privilegs to access the font folder. Maybe there are better ways to do this (as alread mentioned I am not a Linux expert) but both ways worked for me.

Python files:

Use the filemanger to create a new folder "bandwidth_monitor"

Copy all files to directory bandwidth_monitor

Make python files and script executable

chmod +x *.py
chmod +x

Configure crontab

crontab -e

Crontab is used to schedule program execution e.g. speedtest every 30 min. Add the following lines to your crontab (see also second figure):

@reboot /usr/bin/python /home/pi/bandwidth_monitor/ &
@reboot sleep 30 && /usr/bin/python /home/pi/bandwidth_monitor/

*/30 * * * * /home/pi/bandwidth_monitor/
*/3 * * * * /usr/bin/python /home/pi/bandwidth_monitor/
13 03 * * * /usr/bin/python /home/pi/bandwidth_monitor/

Description of the scheduled tasks:

  • at reboot the restart message is written to the IOT dashboard
  • at reboot the poll test_now_button is started
  • every 30 minutes a bandwidth measurment is performed
  • every 3 minutes the status of the remote reset button (on the IOT dashboard) is checked
  • once a day a display refresh cycle is started.

See software section for a brief description of the programs.

Step 5: Software

The software is split into several files / programs: is the main program that is invoked by Crontab every half hour. It performs a bandwidth test (via the command line version of During the test, the RGB LED is blue. If the bandwidth is above the selected threshold, the value is shown on the e-ink display (along with a timestamp) and exported to the Ubidots dashboard. If the bandwidth is below the threshold the LED turns red and the measurement is repeated after a short delay. After 3 negative attempts the relay is activated and thus the power supply of the modem is interrupted. Reset code (value=2) is written to the log section. reads the status of a boolean variable on the dashboard. If killswitch_state is true the relais is activated an the power supply of the modem is interrupted. The RGB LED turns green during the polling of the killswitch. After the reset the killswitch_state is set false and an entry in the log section of the dashboard is generated (value=1). is waiting for the pushbutton on the front panel of the case to be pressed . By activating the button, a bandwidth measurement is triggered manually. When the program is started (at the reboot of the Raspberry Pi) the RGB LED is blinking red. writes the reset code (value=3) to the log section of the dashboard. This indicates that the bandwidth monitor has been restarted. During program start the RGB LED flashes blue. and are simple scripts that can be used to test the hardware function of the RGB LED and the relay. and are device driver for the e-ink display provided by Waveshare.

In order to allow the programs to access the Ubidots dashboard, you have to add your individual tokens and device or variable names (if you use different notations). Search for section like the one shown in the image above (replace XXXXXXXX by your token).

Comprehensive tutorials on how to build the dashboard and how to integrate the dashboard into a Python program can be found directly on the Ubidots page ( or via Google.

Step 6: IOT Dashboard

The dashboard hosted by Ubidots (see contains several areas which are briefly described below.

    1. Time sequence of up- and download speed. Every half hour a new value is inserted into the diagram.
    2. Time course of the measured ping time. Every half hour a new value is inserted in the diagram.
    3. Time sequence of the average download speed. The average value over 24 hours is calculated and written to the diagram.
    4. Spreadsheet representation of the current measurement values including time stamp.
    5. Remote control button for resetting the modem via the Internet. Query occurs every 3 minutes, i.e. it may take some time until the action is carried out.
    6. Logging of the last resets including the reason for the reset (remote triggering, switching off or loss of voltage, falling below the minimum bandwidth)

Comprehensive tutorials on how to build the dashboard and how to integrate the dashboard into a Python program can be found directly on the Ubidots page ( or via Google.

Step 7: Introduction of Basic Functions

Raspberry Pi Contest 2020

Participated in the
Raspberry Pi Contest 2020

Be the First to Share


    • Maps Challenge

      Maps Challenge
    • Metal Contest

      Metal Contest
    • Summer Fun: Student Design Challenge

      Summer Fun: Student Design Challenge



    2 months ago

    Hi! Great project, congratulations! Where I have to Change the code to use with a physical Ethernet Port on a rapberry pi 3 or 4? many thanks


    Question 7 months ago on Step 7

    Great project!!! I made this one in a hurry (just a few hours) because I am travelling but I needed a gadget like this. I simplified the setup and code for a bare-bones setup with just a raspberry pi zero w, 3 jumper wires, a 1 channel relay and two power adapters (one for the router, and one for the raspberry pi)

    One suggestion to improve this would be to create a customisable output power supply for the router (something I have to do, since my router requires a 12V 0.5A power supply)

    Question: Any reason we need to use a raspberry pi variant here instead of a esp8266 or esp32? While this was a really educational and fun project, I would like to cut costs on this as far as possible for learning purposes


    8 months ago on Step 7

    Wow - a very nice practical and professionally presented application for Pi with clear documentation. I chanced upon your project from a web search and was so impressed I signed up to on the spot. My goal is to learn and build just this sort of real world practical project with the amazing Pi during the latest UK Covid lock down (which started today). I hadn't considered a Bandwidth monitor (but will now add it to my list). Inspirational - Thanks so much.


    Reply 8 months ago

    Thank you for your kind feedback! I also prefer practical projects (if you haven't already found it, I made an additional PI based instructable:
    All the best for the implementation and of course for the time in the lock down. One can see a positive aspect: if you are not allowed to go out, you have more time for projects of this kind.
    P.S. in Austria we have now a so called "lock down light". We have to stay at home from 8PM to 6AM.


    Reply 8 months ago

    Technology is brill. Locked down @ home but chatting with an Ozzie!. We have in-laws in NZ. In 2012 did the 'pom tourist world tour' flying from Hong Kong for a Brisbane road trip north - on way back from NZ had a few days around Sydney before going on to Japan. Absolutely loved it especially seeing Oz Skylines - you guys are great engineers / car modders (I have a Hooners R33 Skyline here in the UK so have followed may Oz blogs on the club site). I've just taken early retirement from engineering consultancy so once the world reboots if we have enough cash would love to see more of the world including Oz (Melbourne, Tasmania, Ayers Rock etc.). In the early 2000's we took on many Oz civil engineering graduates (Basically they got paid to see europe on budget airlines !! ). They were all bonzer blokes & sheilas. When the recession hit in 2008 a few poms chose jobs, sunshine & surfing on the Gold Coast as Manchester weather is rubbish (especially over winter). I quote an Australian graduate (Hannah) when going home @ the end of the UK winter 'I don't know how you can live here it is so grey, wet & miserable'. Anyhow enough of my ramble. Great project - & I will follow your link. Keep up the good work.


    Question 10 months ago on Introduction

    I was looking at either the Raspberry Pi 3B+ or 4B for the gigabit port. Do you know if these instructions would still apply to those models?


    Answer 9 months ago

    I have never tried it on 3B+ or 4B but I think it should work as well. Of course you would need a larger case ;-).
    If you try it and succeed, please leave a comment - thanks!


    1 year ago

    a project with a oled display and a gigabite cable connection will be fantastic :)


    Reply 1 year ago

    Thank you for your comment! An OLED display would have been an option as well. Since the update frequency is so low (once every half hour) I decided to use an e-ink display because its is more power-saving.


    1 year ago

    very nice project! :) A video would be very apreciated


    Reply 1 year ago

    Thank you! Maybe I can add a video about the general operating concept - will see.