Connecting Bela to Wifi
Bela systems are full Linux computers so can be connected to wifi in a couple of different ways. Using a USB wifi dongle you can connect your board to the internet or a local wireless network. It is also possible to share your computer’s internet connection with your Bela board via USB.
This article details how to get your board connected to the internet or local network.
Table of contents
Using a Wifi dongle
Compatable Wifi dongles
We tested Bela with these Wifi dongles:
- Ralink RT5370
- Ralink MT7601U 148f:7601
Most Linux-compatible dongles should work, provided that their drivers are included in the 4.4.113 Linux kernel running on Bela. If the drivers are not included, you will have to compile the drivers for this kernel to get the dongle to work.
Setting up your network connection with Wifi
1. ssh
into your Bela system
From a terminal on your computer, connect to your Bela board by running:
$ ssh root@bela.local
You’ll know you’ve connected to your Bela board when you see this prompt:
root@bela:~#
2. Make sure your dongle is visible on your board
Run this command to list your devices:
root@bela:~# lsusb
If your dongle does not show up, double check it is plugged in properly or try rebooting your board.
3. Get the name of your wifi device
Run this command:
root@bela:~# ip a
One of the devices that is listed will be called wlanX
, where X is a number - this is the name of your network device.
If no wlan
device shows up, you need to install drivers for it.
4. Edit your interface list
In this example we use wlan0
as the name of your interface. Replace this with the device name you found in the previous step.
Here you’ll edit the /etc/network/interfaces
file. Open it in the command line text editor with this command:
root@bela:~# nano /etc/network/interfaces
Instructions on how to configure the file are included as comments at the bottom of the file. Make sure you set the settings using the interface name of your device that you found in the previous step.
When you’re ready to exit, click CTRL + X
to edit, and Y
to save any changes you made.
If you make any changes to /etc/network/interfaces
, make sure you reboot your board for those to take effect.
5. Set your network name and password
Run the following command, replacing YourNetworkName
with the name of your Wifi network and YourNetworkPassword
with the Wifi network’s password:
root@bela:~# wpa_passphrase YourNetworkName YourNetworkPassword >>/etc/wpa_supplicant/wpa_supplicant.conf
Then, reset your device for these changes to take effect (don’t forget to replace wlan0
with your device name):
root@bela:~# ifdown wlan0; ifup wlan0;
6. Verify your settings
Make sure your settings are correct by running the following:
root@bela:~# ip a
If your network is configured correctly you’ll see your device name listed with an IP address.
Using Bela as a wi-fi hotspot
Here are instructions on how to set up your Bela as a wireless access point which means you will be able to connect to your board and bring up the IDE – very useful for reprogramming boards which are mounted in projects. This assumes you have an image v0.3.3 or above and that you have a Linux-compatible wifi dongle plugged into Bela (see above for discussion of suitable dongles).
- Edit the file
/etc/default/hostapd
(e.g.: usingnano /etc/default/hostapd
), find the line that starts withDAEMON_CONF
, uncomment it and change it so it looks like this:DAEMON_CONF="/etc/hostapd/hostapd.conf"
Save and close the file.
- The above edit told
hostapd
to look for a configuration file, so now we need to create it:nano /etc/hostapd/hostapd.conf
- Put the following into this file:
interface=wlan0 hw_mode=g channel=1 wmm_enabled=1 ssid=MyBelaAccessPoint auth_algs=1 wpa=2 wpa_passphrase=bela1234 wpa_key_mgmt=WPA-PSK rsn_pairwise=CCMP ieee80211d=1 country_code=DK ieee80211n=1
Note: you may want to change the
ssid=
(network name) andwpa_passphrase=
(password) lines. Ensure your passphrase is at least 8 characters long. Save and close the file. - Next we need to change the network configuration so that Bela advertises its network instead of trying to connect to one. To do that, edit
/etc/network/interfaces
and replace thewlan0
configuration section, by default:allow-hotplug wlan0 iface wlan0 inet dhcp wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
with the following:
allow-hotplug wlan0 iface wlan0 inet static hostapd /etc/hostapd/hostapd.conf address 192.168.30.1 netmask 255.255.255.0
Again, you may want to change the
address
to suit your taste. This is the IP address of your board on this network.
If you make any changes to /etc/network/interfaces
, make sure you reboot your board for those to take effect.
- We then want to ensure the board acts as a DHCP server, assigning suitable IP addresses to the devices that connect to it. To do this, first edit
/etc/default/isc-dhcp-server
and change this line fromINTERFACESv4="usb0 usb1"
to
INTERFACESv4="usb0 usb1 wlan0"
then edit
/etc/dhcp/dhcpd.conf
and add in these extra lines:subnet 192.168.30.0 netmask 255.255.255.0 { range 192.168.30.2 192.168.30.254; }
Ensure that the range here (the range of IP addresses that are assigned to connected devices) is compatible with the address and netmask values set in
/etc/network/interfaces
above.
Testing the hotspot
Now you can test that the network can be successfully started:
ifdown wlan0; ifup wlan0 --verbose
The output of the above command should give something like:
ifup: configuring interface wlan0=wlan0 (inet)
/bin/run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
run-parts: executing /etc/network/if-pre-up.d/hostapd
hostapd: /usr/sbin/hostapd -B -P /run/hostapd.wlan0.pid /etc/hostapd/hostapd.conf
Configuration file: /etc/hostapd/hostapd.conf
wlan0: interface state UNINITIALIZED->COUNTRY_UPDATE
run-parts: executing /etc/network/if-pre-up.d/wireless-tools
run-parts: executing /etc/network/if-pre-up.d/wpasupplicant
/bin/ip addr add 192.168.30.1/255.255.255.0 broadcast 192.168.30.255 dev wlan0 label wlan0
/bin/ip link set dev wlan0 up
/bin/run-parts --exit-on-error --verbose /etc/network/if-up.d
run-parts: executing /etc/network/if-up.d/avahi-daemon
run-parts: executing /etc/network/if-up.d/openssh-server
run-parts: executing /etc/network/if-up.d/upstart
run-parts: executing /etc/network/if-up.d/wpasupplicant
If you had any errors in your files, they would hopefully show up here.
Now you should be able to connect to the MyBelaAccessPoint
network (or whatever you called it) with the password bela1234
(or whatever you set it to above). Once connected, your device should be assigned an address in the range 192.168.30.2
to 192.168.30.254
(or whatever range specified above), and you should be able to access the board on 192.168.30.1
(or whatever you set it to above).
A few tests:
- open the address
192.168.30.1
in the browser: does the Bela IDE show up? - open a terminal, run
ssh root@192.168.30.1
thenecho $SSH_CLIENT
. To me it shows192.168.30.2 62879 22
. In your case it will be slightly different, but the important part to check is that the IP address displayed there is of the range you specified indhcpd.conf
. If it is something else (e.g.: a completely different subnetwork, such as192.168.6.x
or192.168.7.x
, then something went wrong). - power off the board and reboot it. Verify that the wireless networks still comes up, and you can still connect to it.
- power the board from an external power source (i.e.: do not connect it to your computer over USB). Verify that the wireless network still comes up, and you can still connect to it. In this configuration, depending on your system, you may also be able to access the Bela board at
bela.local/
(try that in a browser and/or via ssh:ssh root@bela.local
).
Sharing internet over USB with Bela (Mac OS X)
This is a way of connecting your Bela system to the internet via the USB connection with your laptop. Not that no dongle is required for this approach but your host computer must be connected to the internet.
1. Enable Internet Sharing
Go to System Preferences > Sharing
, and enable Internet sharing
:
Enabling Internet Sharing will interrupt the IPv4 connection between your laptop and your Bela system. This means you won't be able to reach the Bela IDE or the Bela command line using its IP address. However, bela.local is still advertising its IPv6 address, so you can access the IDE and the command line using bela.local.
2. Edit the interfaces config file
Run the following command:
root@bela:~# pico /etc/network/interfaces
This will open the file in the Pico editor.
Comment out the usb0
static config IP from /etc/network/interfaces
by adding a #
at the beginning of the line.
Then add these lines:
iface usb0 inet dhcp
iface usb1 inet dhcp
The interface file should then look like this:
auto usb0
iface usb0 inet dhcp
#iface usb0 inet static
# address 192.168.6.2
# netmask 255.255.255.0
# network 192.168.6.0
# USB ECM gadget (macOS / Linux compatible)
auto usb1
iface usb1 inet dhcp
#iface usb1 inet static
# address 192.168.7.2
# netmask 255.255.255.0
# network 192.168.7.0
Save and exit Pico when you’re done with Ctrl + X
.
3. Restart the network service
To restart the networking service, run:
root@bela:~# systemctl restart networking.service