Quick links :
Part 1 - Mesh Networks
In this part of the workshop you will build your own mesh network over WiFi using Raspberry Pi computers. You need a minimum of 2 Raspberry Pi computers, but can optionally add as many Pis as you want to make a larger mesh network.
To create the mesh network on the Raspberry Pi we are using batman-adv, which is part of the standard linux kernel. We are going to configure the batman-adv kernel module to take control of the WiFi interface wlan0 and create a mesh network over WiFi. Batman-adv will then create a new interface bat0 to allow the Pi to send network traffic over the mesh network. This will be explored more in the section on network access
You need to complete the following steps on all the Raspberry Pis that you want to be part of the mesh network. You can choose to use headerless setup or a keyboard, mouse and monitor to access the Pi command line.
Create the SD card and perform initial setup
Download the latest Raspbian image from https://www.raspberrypi.org/downloads/raspbian/. Choose the Raspbian Stretch Lite version.
Flash the image to an SD card suitable for your Raspberry Pi. Instructions are available here if needed.
If you are doing a headerless setup insert the SD card back into your computer. Open a command line or terminal on your computer and change to the directory where the SD card boot partition is mounted and create an empty file in the boot partition called ssh:
- Linux :
- MacOS :
- Windows command prompt :
type NUL >> ssh
- Windows PowerShell :
echo $null >> ssh
optionally, create the wpa_supplicant.conf file or modify the cmdline.txt and config.txt files if you need OTG mode or WiFi connectivity
Eject the SD card from your operating system and remove the card from your computer.
- Linux :
Insert the SD card into the Raspberry Pi and then power on the Raspberry Pi.
Login to the pi with user pi and password raspberry. If using headerless setup then connect via ssh. The hostname on first boot is raspberrypi.local.
On the Raspberry Pi command line issue the command
sudo raspi-configand then go through and change the following settings:
- Change the user password (don't forget it, as you will need it everytime you remotely connect to the Pi)
- Network Options - Hostname
- Localisation Options - set Locale, Timezone and WiFi country to match your location
- Network Option - WiFi. If your pi is not connected to the internet already, use this option to setup WiFi connectivity to ensure your Pi has access to the internet
- interfacing Options - SSH, ensure SSH server is enabled
Exit raspi-config, don't reboot yet.
sudo apt-get update && sudo apt-get upgrade -y
Reboot the Raspberry Pi with command
sudo reboot -n
Once the Pi has rebooted, get to the command line (remember your pi now has a new hostname and the pi user has a new password that you set in the previous section). If connecting via ssh, the ssh command line command is
ssh firstname.lastname@example.org, replacing hostname with the name you specified.
Perform the following on the pi command line:
To manage the mesh network, a utility called batctl needs to be installed. This can be done using command
sudo apt-get install -y batctl
Using your preferred editor create a file ~/start-batman-adv.sh
the file should contain the following:
#!/bin/bash # batman-adv interface to use sudo batctl if add wlan0 sudo ifconfig bat0 mtu 1468 # Tell batman-adv this is a gateway client sudo batctl gw_mode client # Activates batman-adv interfaces sudo ifconfig wlan0 up sudo ifconfig bat0 up
Make the start-batman-adv.sh file executable with command :
chmod +x ~/start-batman-adv.sh
Create the network interface definition for the wlan0 interface by creating a file as root user e.g.
sudo vi /etc/network/interfaces.d/wlan0
sudo nano /etc/network/interfaces.d/wlan0
then add the following content:
auto wlan0 iface wlan0 inet manual wireless-channel 1 wireless-essid call-code-mesh wireless-mode ad-hoc
You can replace:
- the channel number with a valid 2.4 GHz WiFi channel number for your region (most regions support channels 1 to 11)
- the essid with a network name of your choosing
However, these values must be the same on ALL devices that will form your mesh network.
Ensure the batman-adv kernel module is loaded at boot time by issuing the following command :
echo 'batman-adv' | sudo tee --append /etc/modules
Stop the DHCP process from trying to manage the wireless lan interface by issuing the following command :
echo 'denyinterfaces wlan0' | sudo tee --append /etc/dhcpcd.conf
Make sure the startup script gets called by editing file /etc/rc.local as root user, e.g.
sudo vi /etc/rc.local
sudo nano /etc/rc.local
before the last line: exit 0
If this pi will not be a bridge or gateway node then shut it down using command :
sudo shutdown -h now
You now have all the raspberry pi systems configured to join the mesh, so proceed to the next section to setup access to the Internet and also enable a bridge.
Quick links :