Get Going with Wifi

Everyone born after 1980 knows that you just can’t live without the internet. It’s a simple fact of life. As such, we better get our Edison connected to the world wide web. The following is a simple tutorial to do just that.

For connecting to the web, we’re going to use wpa_supplicant and wpa_cli. A supplicant is a software (or hardware, but in this case software) entity that sits at one end of a point-to-point LAN segment seeking to be authenticated by an authenticator at the other end. wpa_supplicant is a cross-platform supplicant that supports common web authentication, such as WEP, WPA, and WPA2. wpa_cli is really nothing more than an interactive client for wpa_supplicant. It will allow us to configure our connections and get the hang of how our web configuration is handled.

If you want to know more about wpa_supplicant, there’s a nice description on arch linux here and on wikipedia here.

Edison comes with these two packages pre-installed and ready to roll, so let’s get started. Turn on wpa_supplicant by issuing the following command

root@edison:~# wpa_supplicant -B -Dnl80211 -iwlan0 -c/etc/wpa_supplicant/wpa_supplicant.conf

You should see a success response as follows:

Successfully initialized wpa_supplicant

You can use the rfkill command to check on the status of the network:

root@edison:~# rfkill list
0: phy0: wlan
Soft blocked: no
Hard blocked: no
1: brcmfmac-wifi: wlan
Soft blocked: no
Hard blocked: no
2: bcm43xx Bluetooth: bluetooth
Soft blocked: yes
Hard blocked: no 

From the above, you can see that you’re not blocking your wlan. This is good :)

Now we’re going to use wpa_cli to interact with wpa_supplicant on the fly. The basic idea is to open wpa_cli, scan for networks, find yours, add it, load the network params, and then save the configuration. The save will add your network configs to wpa_supplicant.conf. We’ll edit this file later to add additional networks and automatically connect to them. In the meantime, wpa_cli is just issuing a set of commands for a one time connection. The rundown of commands to get on your network are given below, with actual typed commands highlighted in yellow. Everything else is a response from wpa_cli.

root@edison:~# wpa_cli
wpa_cli v2.2
Copyright (c) 2004-2014, Jouni Malinen <j@w1.fi> and contributors

This software may be distributed under the terms of the BSD license.
See README for more details.


Selected interface 'wlan0'

Interactive mode

> scan
OK
CTRL-EVENT-SCAN-STARTED 
CTRL-EVENT-SCAN-RESULTS 
WPS-AP-AVAILABLE 
scan_results
> bssid / frequency / signal level / flags / ssid
40:8b:07:67:f9:34	2412	-53	[WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS]	Dante's Inferno

> add_network
1
> set_network 1 ssid "Dante's Inferno"
OK
> set_network 1 key_mgmt WPA-PSK
OK
> set_network 1 psk "InTheoryThisWouldBeMyPassword"
OK
> save
OK
> enable_network 1
OK
CTRL-EVENT-SCAN-STARTED 
CTRL-EVENT-SCAN-RESULTS 
WPS-AP-AVAILABLE 
Trying to associate with 40:8b:07:67:f9:34 (SSID='Dante's Inferno' freq=2412 MHz)
Associated with 40:8b:07:67:f9:34
WPA: Key negotiation completed with 40:8b:07:67:f9:34 [PTK=CCMP GTK=TKIP]
CTRL-EVENT-CONNECTED - Connection to 40:8b:07:67:f9:34 completed [id=1 id_str=]
> select_network 1
OK
> quit

A couple notes on the above:

  1. If this is your first time using wpa_cli, the add_network command will return a 0 and you should use this number for all set_network, enable_network, and select_network commands. The add_network command simply auto-increments upon already saved networks, and since I already had another network setup it gave me a 1.
  2. These commands will work for most at-home and other out of box networks, but will not work for all configurations. Different set_network commands are required for different network configuarations – enterprise networks are a bitch and so are the really high security ones. For a pretty comprehensive list of the different configurations, see this website
  3. Nothing is going to explode if you try configs that aren’t compatible, you just won’t be getting online. wpa_cli will tell you if this is happening. If you happen to try a network config that doesn’t work, the set_network command will simply return an error message as opposed to the standard “OK” response.

Now we’re connected to the network via wpa_cli, but we’re unfortunately left without a working IP address. In order to get one automatically, we’re going to start a DHCP client on the wlan interface that will grab an IP address as allocated by our DHCP server on the other end. To do this, issue the following and you should see the response below if it’s successful:

root@edison:~# busybox udhcpc -i wlan0
udhcpc (v1.22.1) started
Sending discover...
Sending select for 192.168.0.34...
Lease of 192.168.0.34 obtained, lease time 86400
/etc/udhcpc.d/50default: Adding DNS 192.168.0.1
/etc/udhcpc.d/50default: Adding DNS 205.171.2.25

 

Sweet! So, now for the fun part…test your connection!!

root@edison:~# ping google.com
PING google.com (74.125.224.40): 56 data bytes
64 bytes from 74.125.224.40: seq=0 ttl=57 time=44.226 ms
64 bytes from 74.125.224.40: seq=1 ttl=57 time=57.004 ms
64 bytes from 74.125.224.40: seq=2 ttl=57 time=61.138 ms
^C
--- google.com ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 44.226/54.122/61.138 ms

 

BAM! Connecting to google means we’re now the smartest person alive.

If you’re like me, then you’re probably already thinking that this process is a little bit cumbersome. Fortunately, we can automate a whole bunch of this with very little effort (and all of it in a later post here).

The first thing we have to do is edit our wpa_supplicant.conf file. The wpa_supplicant.conf file is the configuration file that wpa_supplicant references on start-up (the first command in this tutorial calls it). So, use your favorite text editor to open it:

root@edison:~# vi /etc/wpa_supplicant/wpa_supplicant.conf

Using vi is arbitrary, it’s just a nice lightweight editor already installed on Edison.

The file should contain a few lines that describe the network you just added using wpa_cli. For me, this would be:

network={
        ssid="Dante's Inferno"
        psk="InTheoryThisWouldBeMyPassword"
        key_mgmt=WPA-PSK
        disabled=1
}

 

This config was automatically saved to wpa_supplicant.conf when the save command was issued in wpa_cli. All network properties that you set before initiating the save are stored here. However, the disabled = 1 line is added by default and tell’s wpa_supplicant not to automatically connect to this network. We’re definitely going to delete that line and make our .conf look like:

network={
        ssid="Dante's Inferno"
        psk="InTheoryThisWouldBeMyPassword"
        key_mgmt=WPA-PSK
        }

 

Save this modified file and exit your text editor.

It’s as easy as that. Now every time you’re in range of this network and you reboot Edison, you’ll only have to issue two commands to access the internet:

root@edison:~# wpa_supplicant -B -Dnl80211 -iwlan0 -c/etc/wpa_supplicant/wpa_supplicant.conf
root@edison:~# busybox udhcpc -i wlan0

 

Everything else is taken care of by your configuration file. Oh, and it’s definitely worth mentioning that you can add any number of networks directly to your wpa_supplicant.conf file without going through wpa_cli. As long as the configuration is correct and there’s no disabling, wpa_supplicant will try to connect to them (in order!) as soon as the supplicant is started.

If typing these two commands every time Edison boots is too much for you (and it’s definitely too much for me), see this post here about how to add scripts automatically to your boot process.

 

SSH-ing wirelessly

There’s an awesome side-effect of having Edison on the interwebs. We no longer need to tether to ssh in to our device (and hence can stop letting HoRNDiS spawn more multifunction gadgets in our network config). After connecting to the internet, look up your ifconfig file and make a note of the wlan0 IP address that’s highlighted below.

root@edison:~# /sbin/ifconfig

lo        Link encap:Local Loopback

          inet addr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:65536  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

usb0      Link encap:Ethernet  HWaddr 52:be:12:cb:77:26

          inet addr:192.168.2.15  Bcast:192.168.2.255  Mask:255.255.255.0

          inet6 addr: fe80::50be:12ff:fecb:7726/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:323 errors:0 dropped:0 overruns:0 frame:0

          TX packets:248 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:25693 (25.0 KiB)  TX bytes:54801 (53.5 KiB)

wlan0     Link encap:Ethernet  HWaddr fc:c2:de:3c:1b:f6

          inet addr:192.168.0.26  Bcast:0.0.0.0  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:13 errors:0 dropped:0 overruns:0 frame:0

          TX packets:40 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:1752 (1.7 KiB)  TX bytes:6785 (6.6 KiB)

No, to ssh in wirelessly, just use root@that address

kmwitt-mobl2:~ smoyerma$ ssh root@192.168.0.26

root@edison:~#

BOOM!

Posted in Edison, Tech
One comment on “Get Going with Wifi
  1. Wolle says:

    helped me a lot, too. My Edison is now wireless :-)

Leave a Reply

Your email address will not be published. Required fields are marked *

*