Wi-Fi

The final means of connecting a computer to EV3 is using a Wi-Fi network. This connection mechanism is special because it requires a USB Wi-Fi dongle, which is not supplied with EV3 and must be purchased separately.

This is further complicated by the fact that every Wi-Fi dongle is not supported. An EV3 running LeJOS has driver modules for the Atheros ATH9K and Realtek 8192cu chipsets (to find out which chipset your Wi-Fi dongle is using, insert it in your computer and run lsusb in a terminal). Wi-Fi dongles based on these will work out of the box. A popular choice is EDIMAX EW-7811Un, a cheap and reliable device with the huge bonus of having an extremely small form factor. Once inserted into the USB port on EV3, only a small part juts out, which is approximately equal to a standard Technic piece in width.

Configuring EV3

We will set up EV3 (running LeJOS) to connect to your WPA-secured Wi-Fi network (it is now widely accepted that WEP does not provide enough security to Wi-Fi networks). The first step is to insert the USB Wi-Fi dongle into EV3 and then turn it on. Since we haven't specified which network to use nor provided EV3 with the credentials needed to access it, EV3 will fail to connect to any network.

The lack of means to search for and connect to available wireless networks is a shortcoming of this connection method. To an extent, it is understandable; it is not easy to use just five hardware keys to enter long wireless security passphrases.

Instead of the graphical approach, we have the nature of Linux on our side, where every configuration is guaranteed to be just a text file, editable as such. So, we can change the file directly on the SD card or SSH into EV3 (using the mini USB cable or Bluetooth) and edit it via the shell (terminal). I will showcase the latter as an exercise in how to use SSH to modify remote machines. If you want, you can perform the same actions by plugging the SD card directly into your computer and editing the relevant file there.

Wi-Fi configuration using SSH

Connect your EV3 to your computer using the mini USB cable or set up the Bluetooth PAN network (both described earlier). Once the connection has been established, SSH into EV3 by running ssh ev3 (or ssh [email protected]).

The first thing we do is confirm that the USB Wi-Fi dongle has been recognized by the EV3, by running ifconfig. The output should contain a block related to the wlan0 interface. To allow the EV3 to connect to a WPA-secured Wi-Fi network, we need to create and populate the /etc/wpa_supplicant.conf configuration file.

Linux comes with a utility that generates the configuration for you: wpa_passphrase. To test it out, simply run wpa_passphrase <SSID>, where instead of <SSID>, you need to type in the SSID (name) of your Wi-Fi network surrounded by quotes. For instance, my Wi-Fi network at home is called Dumbledore, so this is what I type in instead of <SSID>.

When you press Enter, the utility will say # reading passphrase from stdin and it will wait for you to type in the passphrase for the network. Type in the passphrase and press Enter. After a few seconds, the utility will spit out the configuration text:

network={
   ssid="Dumbledore"
   #psk="01234567"
   psk=82e6ade8f8319c3a737e89ee125a58178073d66613c9a3af8fb6e7f5e04e1aa7
}

We want this configuration text placed inside /etc/wpa_supplicant.conf. To that end, we run the command again but we modify it slightly:

wpa_passphrase <SSID> > /etc/wpa_supplicant.conf

Remember to replace <SSID> with the name of your Wi-Fi network (surrounded by quotes; for example, at home I use wpa_passphrase "Dumbledore" > /etc/wpa_supplicant.conf). We have used the > redirection operator, an extremely powerful feature of the Linux shell. Basically, what > says is to take the output of the preceding command and place it in the file specified after it (overwriting it in the process). The text # reading passphrase from stdin is also placed in the file; so, when you run the command, you will see nothing, but the lack of the prompt (root@EV3:~#) will indicate that the utility is running, and is in fact waiting for you to enter the passphrase. Type in the passphrase and press Enter. After a few seconds, the prompt will reappear.

To confirm that it worked, run cat /etc/wpa_supplicant.conf. This will print the contents of the file:

# reading passphrase from sdtin
network={
   ssid="Dumbledore"
   #psk="01234567"
   psk=82e6ade8f8319c3a737e89ee125a58178073d66613c9a3af8fb6e7f5e04e1aa7
}

The lines preceded by a # are comments and are ignored by EV3 when setting up the Wi-Fi network. This simple configuration tells EV3 which network to connect to and what security key to use to connect to it.

Simply disconnect EV3 from your computer and restart it. It will automatically connect to the specified Wi-Fi network. The one I have at home hands out IP addresses in the 192.168.1.x range, and my EV3 was given an IP address of 192.168.1.14, which it proudly displays on the home screen (under the 10.0.1.1 address it uses for USB and Bluetooth networks).

To SSH into EV3 over the Wi-Fi network, run ssh root@<wifi ip address> (in my case, I ran ssh [email protected]). You can construct a new block in the ssh config file to connect using the IP address over Wi-Fi.

It is clear that the technique for setting up Wi-Fi connectivity on EV3 is rather painless. For those of you who would rather modify the SD card directly on your computer, plug in your SD card and create the /etc/wpa_supplicant.conf file. You can run the wpa_passphrase command on your Linux computer and place its output in the file. Now restart EV3 and it will work just as well.

Limitations

Wi-Fi is a powerful means to connect devices, but EV3 doesn't support all USB Wi-Fi dongles out of the box. The only other shortcoming of using it with EV3 is that the USB Wi-Fi dongle protrudes out of the brick. This is mitigated by using a smaller dongle (such as the Edimax), but it can still interfere with certain robot designs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.158.47