Connect your Raspberry Pi4 with your router turn on the Pi and join your new configurable WiFi network named humble
. Access your Raspberry Pi4 through HTTP and choose the WiFi speed like this:
- Background
- Prerequisite
- Install using the pre-made image
- Install from scratch
- Change throttling using the API
- Take a copy of your SD card
Inspired by Sam Smiths PiNC I wanted to make a easy way for everyone (not just developers) to try out different internet speeds.
You need a Raspberry Pi 4 with a Ethernet cable that you can connect to your router.
- Download the pre-made image from releases.
- Burn the image on a SD card using Raspberry Pi Imager.
- Insert the SD card into the Raspberry Pi 4.
- Connect your Raspberry Pi with your router through a Ethernet cable and turn on your Raspberry Pi.
- Join your new configurable
humble
WiFi network on desktop or mobile phone with the passwordgoslowtogoFAST
. - Access your Raspberry Pi through HTTP and chose the WiFi speed. On Mac access
http://raspberrypi.local:3001
from your web browser. On other OS you can usenmap
to find your Raspberry IP address. Access that IP using port 3001 in your browser. - Choose the WiFi speed.
When you checked that everything works you should change the WiFi password and the SSH password!
Use the user pi
and password myloveisyourloveforever
to log into the device using SSH.
Edit the file /etc/wpa_supplicant/wpa_supplicant.conf
and change the password to your new password.
sudo nano /etc/hostapd/hostapd.conf
Reboot by sudo reboot
.
Login to the device and change the password to your new password using passwd
.
If you want to use your humble installation for performance testing you probably want to use a USB WiFi antenna that is better than the default one that comes with the Raspberry Pi.
The new WiFi will probably be wan1
on your Raspberry and that means you need to reconfigure your Pi so its used:
- Edit /etc/dhcpcd.conf with
sudo nano /etc/dhcpcd.conf
and changewan0
towan1
. - Edit /etc/dnsmasq.conf with
sudo nano /etc/dnsmasq.conf
and changewan0
towan1
. - Edit /etc/hostapd/hostapd.conf with
sudo nano /etc/hostapd/hostapd.conf
and changewan0
towan1
. - Reboot by
sudo reboot
.
If you use another antenna you need to make sure that the WiFI do not go to sleep mode. You can check your setup with iwcofig
and look for the power option for you WiFi.
To turnoff sleeping mode you can run:
sudo iw wlan1 set power_save off
And for turning it off for startup you need to edit:
sudo nano /etc/rc.local
Then before exit 0 add the following line:
/sbin/iwconfig wlan1 power off
The image (based on Raspberry Pi OS Lite) has the following extra setup:
- It runs unattended-upgrades to keep the image up to date.
- It runs fail2ban
- It starts the web version of throttle on startup using systemd.
The WiFi setup in the images has Sweden as geographical setup and you probably want to change that. Use https://en.wikipedia.org/wiki/ISO_3166-1 to find your country code. I'm located in Sweden so I use SE
.
You need to change in two different places. First run:
sudo raspi-config nonint do_wifi_country SE
And then edit the file /etc/hostapd/hostapd.conf
and change the current country code to yours.
sudo nano /etc/hostapd/hostapd.conf
And change the row:
country_code=SE
Then reboot by sudo reboot
.
You can make sure user interface is automatically updated by adding the following in the crontab.
First open the crontab:
crontab -e
And then add the following lines:
0 6 * * * bash -lc /home/pi/update.sh 2>&1 | logger -t humble-updates
Thank you SpaceRex for your tutorial Turn your Raspberry Pi into a WiFi Router!, that helped me a lot to set this up! Checkout the video for more details.
- Download and install the latest Raspberry Pi OS Lite image to a SD card using Raspberry Pi Imager.
- Add an empty file named
SSH
to root section of the SD card so you more easily can access the Raspberry Pi. - Insert the SD card into the Raspberry Pi, connect your Raspberry Pi with your router through a Ethernet cable and turn on your Raspberry Pi.
- Find the IP number of your Raspberry Pi, use
nmap
to find your Raspberry IP address or on Mac just useraspberrypi.local
. - Login to your Raspberry using SSH (this example if for Mac):
SSH pi@raspberrypi.local
with passwordraspberry
. - Once you logged in, change the password for the pi user using
passwd
to set a new password.
Now you are ready to turn your Raspberry Pi into a WiFi router.
- By default the WiFI on the Raspberry Pi is disabled (you will get a message like Wi-Fi is currently blocked by rfkill. when you login to the device). Enable the WiFi by setting your geographical location. Use https://en.wikipedia.org/wiki/ISO_3166-1 to find the country code. I'm located in Sweden so I use
SE
.
First run:
sudo raspi-config nonint do_wifi_country SE
Then reboot the device:
sudo reboot
- First make sure to update:
sudo apt update
- Install the following so your Raspberry Pi can act as a router:
sudo DEBIAN_FRONTEND=noninteractive apt install -y hostapd dnsmasq netfilter-persistent iptables-persistent
- Make sure it starts on boot:
sudo systemctl unmask hostapd.service
sudo systemctl enable hostapd.service
- Edit
etc/dhcpcd.conf
and make sure to add the interface at the bottom of the file and set the subnet that is gonna be used (make sure you don't use that IP before on your network). This makes sure that when wlan0 is used (our WiFi) the Raspberry Pi get IP 10.2.1.1:
sudo nano /etc/dhcpcd.conf
Then add at the bottom of the file:
interface wlan0
static ip_address=10.20.1.1/24
nohook wpa_supplicant
- Then edit
/etc/sysctl.d/routed-ap.conf
to forward ipv4 adresses.
Open the file:
sudo nano /etc/sysctl.d/routed-ap.conf
and add net.ipv4.ip_forward=1
in that file.
- Tell the traffic where to go. In the terminal run:
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo netfilter-persistent save
- The step prepare your Raspberry to be a router and setup which IP addresses devices will have when they connect. That happens on
/etc/dnsmasq.conf
.
As a first step, move the old version so we have a backup:
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.old
Then open (a new) file:
sudo nano /etc/dnsmasq.conf
And add the following lines:
interface=wlan0
dhcp-range=10.20.1.5,10.20.1.100,255.255.255.0,72h
domain=wlan
address=/rt.wlan/10.20.1.1
- Setup your host access point file. Edit
/etc/hostapd/hostapd.conf
Here you need to add your country code again (https://en.wikipedia.org/wiki/ISO_3166-1) and set a password (wpa_passphrase
) and a namessid
of your WiFi network.
Open the file:
sudo nano /etc/hostapd/hostapd.conf
And then add:
country_code=SE
interface=wlan0
ssid=humble
hw_mode=a
channel=36
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=goslowtogoFAST
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
Change the country_code
to your country code.
It's also in this configuration file you choose what frequency your WiFi network will be on.
hw_mode
can be either a = 5GHz, b = 2.4Ghz or g =2.4 GHz.
- Make sure your WiFI has power save turned off (Power Management:off). First check that power saving is turned on by running
iwcofig
. If it's on, you can make sure that is turned off on startup by:
sudo nano /etc/rc.local
Then before exit 0 add the following line:
/sbin/iwconfig wlan0 power off
- The WiFI setup is done. Reboot your Pi
sudo reboot
and try to connect to your WiFi network on your desktop or mobile.
To be able to run the frontend you need to install NodeJS. Install latest LTS, when I write this that version is 16.13.1.
wget https://nodejs.org/dist/v16.13.1/node-v16.13.1-linux-armv7l.tar.xz
tar xf node-v16.13.1-linux-armv7l.tar.xz
cd node-v16.13.1-linux-armv7l/
sudo cp -R * /usr/local/
Then you can verify that it worked by running:
node --version
As the last step you need to install the frontend.
sudo apt install -y git
git clone https://github.com/sitespeedio/throttle-frontend.git
cd throttle-frontend
npm install --production
Start the frontend with:
node lib/app.js
And open your browser and access http://<raspberrypiip>:3001
Instead of using the graphical frontend, you can use the API to change the throttling. Call the API with the profile you want to use.
Set throttling to cable:
curl http://raspberrypi.local:3001/api/cable -H "Accept: application/json"
Set throttling to 3g:
curl http://raspberrypi.local:3001/api/3g -H "Accept: application/json"
Stop throttling:
curl http://raspberrypi.local:3001/api/stop -H "Accept: application/json"
This is how I do it on my Mac. First make sure you have your SD card inserted. Then use diskutil list
to find the disk. On my computer it's mounted as /dev/disk2. Then to copy and compress it I use:
sudo dd if=/dev/rdisk2 bs=1m | xz -T 0 -9 -e > /Users/peter/Desktop/humble-version.xz
Note that I've changed /dev/disk2 to /dev/rdisk2 to make it read only.