lördag 1 oktober 2016

Wi-Fi Protected Setup, WPS, on raspberry pi

There are many tutorials that explain how to connect a raspberry to a wifi hotspot, but I haven't seen this before.

You have a wi-fi dongle and want to configure your (headless) raspberry to connect to a wifi hotspot. I assume that you can use ssh to log into your rpi and that you can execute as sudo. I also assume that your router has a wps button.

As you probably know, wifi settings are stored in the file /etc/wpa_supplicant/wpa_supplicant.conf. If not previously configured, the content of this file might look like this:

>sudo cat /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB

Check that the wifi dongle is recognized by the system:

>iwconfig
wlan0     IEEE 802.11bgn  ESSID:off/any  
          Mode:Managed  Access Point: Not-Associated   Tx-Power=20 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:off
(device attached to wlan0)

Now, to set up wifi, you execute the following command (install wpa_cli if not already on the system):

>sudo wpa_cli wps_pbc
Selected interface 'wlan0'
OK

...and press the wps button on your router (within 2 minutes).

Check connection status with iwconfig or wpa_cli. On my system:

>sudo wpa_cli status
Selected interface 'wlan0'
bssid=e0:3f:49:09:a9:78
freq=2437
ssid=ASUS
id=0
mode=station
pairwise_cipher=CCMP
group_cipher=CCMP
key_mgmt=WPA2-PSK
wpa_state=COMPLETED
address=40:a5:ef:05:50:f5
uuid=de509928-92bf-5eda-8b02-83a0641a95ca

The important parameter is wpa_state, and that it's state is COMPLETED.

IP-address can be checked with;

> hostname -I
192.168.1.93 192.168.1.21

Two addresses, one for eth0, and the other is for the wlan0.

Check that wpa_supplicant.conf file has been updated and verify that rpi reconnects to the hotspot after reboot.

Refs:

Inga kommentarer:

Skicka en kommentar