Your Robot Wants Multi-Network Connectivity!
Raspberry Pi is a great low cost single board computer for versatile and intelligent robots. As an added bonus, most of the Raspberry Pi product range can connect to the internet via WiFi, opening a plethora of possibilities for remote control, data collection, and more. But, what do you do when your robotic creations need to roam beyond the reach of a single WiFi network? Good news: you can set up your Raspberry Pi-based robot with the capability to access multiple wireless networks. Keep reading to learn how to keep your robot connected by adding multiple networks to its Network Configuration file! (In fact, you can do this with any single board computer that uses a wpa_supplicant.conf file!) Our Orange Pi 5 Plus that runs a small local LLM is set up to work at home or on a friend’s home wifi network! Please note that we had to add a USB wifi dongle to the Orange Pi 5 Plus, but otherwise the process was the same as the one below.
Why Add Multi-Network Connectivity to Your Robot?
Before diving into the “how,” let’s briefly discuss the “why.” Multi-network connectivity can significantly enhance the functionality and reliability of your Raspberry Pi robot. Whether it’s transitioning between home and school, participating in competitions, or exploring outdoor environments, the ability to switch seamlessly between different WiFi networks ensures your robot can always communicate, receive updates, and perform its tasks without interruption.
The Robot Besties Viam Rover (Raspberry Pi 4 Based) has access to the wifi network at home, via a phone’s hotspot, at the makerspace, and at our favorite local coffeehouse (where it impressed everyone with some fancy spins and turns a few weekends ago!)
So, if you want to take your robot with you to develop or demo, you can give it the wifi SSID and passwords if you know them ahead of time! This can definitely make your demos more delightful since you won’t have to fidget around with wifi access if your robot needs it.
Step 1: Access Your Raspberry Pi
The first step is to access your Raspberry Pi. You can do this directly using a monitor, keyboard, and mouse connected to the Pi, or remotely via SSH if it’s already connected to a network. For beginners, the direct method might be more straightforward, especially if you are not sure if SSH access is enabled on your Pi or not!
Step 2: Edit the Network Configuration File
Once you have access to your Raspberry Pi’s terminal, the next step involves editing the network configuration file. This file tells your Raspberry Pi how to connect to different WiFi networks. You can find this file at `/etc/wpa_supplicant/wpa_supplicant.conf`.
To edit the file, use the command:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
This opens the file in the nano text editor, a simple, user-friendly editor that’s perfect for quick edits like the one we’re doing today. Nano usually comes pre-installed on most Linux distros as well as on Mac! It’s super useful and convenient. You can learn more about this editor on the very retro looking GNU nano homepage – it’s not our fault if fall into a rabbit hole however! BTW, the “sudo” part means you are running nano to edit the wpa_supplicant.conf file as a superuser. Once in nano, be sure to take a moment to examine the keystrokes across the bottom of the screen so that you know how to exit and save when we’re done editing the file.
Step 3: Add Multiple WiFi Networks
In the wpa_supplicant.conf file, you’ll see the configuration for your current WiFi network. To add a second network, you simply need to append additional network blocks to the file. Each block should look something like this:
network={ ssid="YourNetworkSSID" psk="YourNetworkPassword" }
Replace `”YourNetworkSSID”` and `”YourNetworkPassword”` with the SSID and password of the additional WiFi network you want to connect to. You can add as many networks as you need by repeating this block for each one!
Step 4: Save and Reboot
After adding the additional networks, press `CTRL+X` to exit nano, then `Y` to save your changes, and `Enter` to confirm. To apply the changes, reboot your Raspberry Pi with the command :
sudo reboot
If you’d rather not reboot your Pi for whatever reason, you can just reboot the networking by typing sudo systemctl restart networking Once your Raspberry Pi (or just the networking) restarts, it will automatically attempt to connect to the available WiFi networks in the order they are listed in the `wpa_supplicant.conf` file.
All the Networks All the Time!
By following these steps, you’ve just expanded the horizons for your robot, giving it the freedom to navigate and operate across multiple WiFi networks. This enhancement not only increases the versatility of your robotic projects but also ensures that your creations stay connected and functional, no matter where they are. Taking these simple steps can open up new possibilities for innovation and exploration in the fascinating world of robotics.
This post was inspired by an article about adding a second network to a digital photo frame! While this is a totally different application, the process is essentially the same.