Use a USB WiFi adapter with your RMSv2 board


Sometimes it may be inconvenient to run an ethernet cable to the location where your RMSv2 board is installed. This is a tutorial on how to setup a USB WiFi adapter so you can access your remote monitoring board over a WPA/WPA2 wireless connection.


We tested with two different USB WiFi adapters, the Linksys AE6000 (MT761003 chipset), and the Panda PAU03 (RT5370 chipset). Both adapters performed well and have decent range for their small size. Many other USB WiFi adapters that use the same chipsets are available and will also work with this tutorial, some of them even come with antennas that give extended range.

LinkSys AE6000 USB WiFi adapter.          Panda Ultra PAU03 USB WiFi adapter.


How to connect to a WPA/WPA2 WiFi network using the Linux command line


This tutorial assumes that:


The pre-installed tools on the RMSv2 board that we need to use are:


The steps for connecting to a WPA/WPA2 network are:

  1. Log into your RMSv2 board with SSH.

  2. Plug in the USB WiFi adapter into your RMSv2 board.

  3. Type out dmesg. You should see output at the end similar to what is shown below.

    [root@RMS-100v2: /# dmesg
    ... snip ...
    ieee80211 phy0: rt2x00_set_rt: Info - RT chipset 5390, rev 0502 detected
    ieee80211 phy0: rt2x00_set_rf: Info - RF chipset 5370 detected
    ieee80211 phy0: Selected rate control algorithm 'minstrel_ht'
    usbcore: registered new interface driver rt2800usb

    This shows that the RMSv2 board has recognized that a new USB device has been plugged in.

  4. Find out the wireless interface name by typing out iw dev as shown below.

    [root@RMS-100v2: /# iw dev
    phy#0
    Interface wlan0
    ifindex 4
    wdev 0x1
    addr 9c:ef:d5:f8:60:bd
    type managed
    txpower 0.00 dBm

    The above output shows that the system has 1 physical WiFi interface, designated as phy#0. The interface name is wlan0. The type specifies the operation mode of the wireless device, managed means the device is a WiFi station or client that connects to an access point.

  5. Next, check that the wireless device is up.

    [root@RMS-100v2: /# ip link show wlan0

    4: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 9c:ef:d5:f8:60:bd brd ff:ff:ff:ff:ff:ff

    Look for the word "UP" inside the < > brackets in the first line of the output.
    In the above example, wlan0 is not UP.
    Execute the following command to bring it up:

    [root@RMS-100v2: /# ip link set wlan0 up

    If you run the show link command again, you can tell that wlan0 is now UP.

    [root@RMS-100v2: /# ip link show wlan0
    4: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000
    link/ether 9c:ef:d5:f8:60:bd brd ff:ff:ff:ff:ff:ff

  6. Scan to find out what WiFi networks are detected. Pipe to the grep command to only search for SSID's.

    [root@RMS-100v2: /# iw wlan0 scan | grep SSID
    SSID: SD-AP
    SSID: sd58wireless
    SSID: WiFiPlus7128-2.4G
    SSID: TELUS0220
    SSID: TELUS2714
    SSID: TELUS5615
    SSID: TELUS6004

    To get more detailed informaion about each access point in range, use the iw command without grep. In our case, the list is quite long, so we will only look at one access point's detailed information.

    [root@RMS-100v2: /# iw wlan0 scan

    BSS 74:4d:28:f6:07:2d(on wlan0)
    freq: 2412
    beacon interval: 100 TUs
    capability: ESS Privacy ShortPreamble ShortSlotTime (0x0431)
    signal: -63.00 dBm
    SSID: SD-AP
    Supported rates: 1.0* 2.0* 5.5* 11.0* 6.0 9.0 12.0 18.0
    DS Parameter set: channel 1
    ERP:
    HT capabilities:
    Capabilities: 0x102c
    HT20
    SM Power Save disabled
    RX HT20 SGI
    No RX STBC
    Max AMSDU length: 3839 bytes
    DSSS/CCK HT40
    Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
    Minimum RX AMPDU time spacing: No restriction (0x00)
    HT RX MCS rate indexes supported: 0-15
    HT TX MCS rate indexes are undefined
    RSN: * Version: 1
    * Group cipher: CCMP
    * Pairwise ciphers: CCMP
    * Authentication suites: PSK
    * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000)

    Some important pieces of information from the above are the SSID and the security protocol (WPA/WPA2 vs WEP). The SSID from the above example is SD-AP, this is the access point that we will attempt to connect to. The security protocol is RSN, also commonly referred to as WPA2. The security protocol is important because it determines what tool you use to connect to the network. The signal strength shown is -63 db which is adequate for decent performance. The channel is shown as 2412 MHz which equates to channel 1.

  7. Connect to the WPA/WPA2 WiFi network.

    This is a 2 step process.

    Step 1: you must generate a configuration file for wpa_supplicant that contains the pre-shared key ("passphrase") for the WiFi network. After you type out the command below and hit enter, the SSH session will pause waiting for you to type out the passphrase for the WiFi network.

    [root@RMS-100v2: /# wpa_passphrase SD-AP >> /etc/wpa_supplicant.conf

    ...type in the passphrase and hit enter...

    The wpa_passphrase program takes the SSID as the single argument, SD-AP in our case. Using that information, the wpa_passphrase program will output the necessary configuration statements to the standard output. Those statements are then appended >> to the wpa_supplicant configuration file located at /etc/wpa_supplicant.conf.

    Next you can optionally check out the wpa_supplicant.conf file to see what the wpa_passphrase program added to it.

    [root@RMS-100v2: /# cat /etc/wpa_supplicant.conf

    network={
    ssid="SD-AP"
    #psk="SuperSecretPassword"
    psk=b214ccd321dae124080f6bdd520473978d0e1e115090b8b6fea45a1c0e67e96b
    }

    Step 2: you must run wpa_supplicant using the new configuration file that you created in step 1.

    [root@RMS-100v2: /# wpa_supplicant -B -D nl80211 -i wlan0 -c /etc/wpa_supplicant.conf

    -B means run wpa_supplicant in the background.
    -D specifies the wireless driver. We are using nl80211.
    -i specifies the interface name discovered in step 4.
    -c specifies the path for the configuration file.

    Once the above command is run, use the iw command to verify that you are indeed connected to the SSID.

    [root@RMS-100v2: /# iw wlan0 link

    Connected to 74:4d:28:f6:07:2d (on wlan0)
    SSID: SD-AP
    freq: 2412
    RX: 77264 bytes (528 packets)
    TX: 1363 bytes (15 packets)
    signal: -63 dBm
    rx bitrate: 1.0 MBit/s
    tx bitrate: 21.7 MBit/s MCS 2 short GI
    bss flags: short-preamble short-slot-time
    dtim period: 1
    beacon int: 100

  8. Obtain IP address by DHCP

    [root@RMS-100v2: /root# udhcpc -i wlan0

    udhcpc: started, v1.35.0
    udhcpc: broadcasting discover
    udhcpc: broadcasting select for 10.0.0.59, server 10.0.0.1
    udhcpc: lease of 10.0.0.59 obtained from 10.0.0.1, lease time 600
    deleting routers
    adding dns 8.8.8.8
    adding dns 1.1.1.1

    Use the ip command to verify the IP address assigned by DHCP. The IP address is 10.0.0.59 from above.

    [root@RMS-100v2: /root# ip addr show wlan0
    4: wlan0: mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 9c:ef:d5:f8:60:bd brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.59/24 brd 10.0.0.255 scope global wlan0
    valid_lft forever preferred_lft forever
    inet6 fe80::9eef:d5ff:fef8:60bd/64 scope link
    valid_lft forever preferred_lft forever

  9. Check the default route.

    [root@RMS-100v2: /root# ip route show
    default via 10.0.0.1 dev wlan0
    default via 10.10.10.1 dev eth0
    10.0.0.0/24 dev wlan0 proto kernel scope link src 10.0.0.59
    10.10.10.0/24 dev eth0 proto kernel scope link src 10.10.10.13

    As you can see from the output above, there are now two default routes, one for the eth0 interface and one for the wlan0 interface.

  10. Connect to the RMSv2 board via WiFi

    Unplug the ethernet cable from the RMSv2 board, and in a new web browser tab try to connect using the ip address obtained by DHCP and confirmed with the ip addr show wlan0 command. In our case we use 10.0.0.59. Success!


The above series of steps is a very verbose explanation of how to connect your RMSv2 board to a WPA/WPA2 WiFi network. Some steps can be skipped if you connect to the same access point for a second time. For instance, if you already know the WiFi device name, and if you know the wpa_supplicant configuration file is already set up for the network. The process needs to be tailored according to your situation.

If the RMSv2 board is rebooted or power cycled, it will not automatically connect to the access point again. In the next section we will discuss how to make the RMSv2 board automatically connect to the access point on boot.


Automatically enable WiFi settings when the RMSv2 board boots


In order to make the RMSv2 board boot up with the wireless settings intact so it will automatically connect to the access point that was configured in the wpa_supplicant.conf file, you must edit two files on the RMSv2 board.

FOR DHCP IP

From the RMSv2 web interface, use the built-in file explorer to edit the /etc/startup.sh file.
Add the two lines marked in red and then save the file.


#!/bin/sh
. /etc/functions.sh
########### Insert you own stuff for bootup here ###############
#information "Starting my App 1" #edit this with your app name
wpa_supplicant -B -D nl80211 -i wlan0 -c /etc/wpa_supplicant.conf
ifup -i /etc/network/wireless wlan0
################################################################
exit 0

The second file to edit is the /etc/network/wireless file.

The lines that are preceeded with a pound sign (#) are only comments, the important lines are colored red. When you are finished editing the file, save it.


# Configure Wireless
# Configure wlan0
auto wlan0
iface wlan0 inet dhcp

It is now time to reboot or power cycle the RMSv2 board. If you entered everything correctly the RMSv2 board will automatically connect to your WPA/WPA2 WiFi network and use DHCP to obtain an ip address and DNS from your router on every boot.

NOTE:
There is good and sometimes not so good about using DHCP to obtain an IP address automatically. The good is that there is virtually no network configuration. The DHCP client on the RMSv2 board will grab a free ip address that is offered from the router's DHCP pool. The DHCP client on the RMSv2 board will also add the default route and will use the DNS numbers obtained from the router.

The possibly not so good part is if the router gets rebooted or power cycled, there is no guarantee that the router will offer the same ip address as it did before, they usually do, but not always. The RMSv2 board may get offered a different ip address so that you have to look in the router's DHCP leases table to determine what ip address the RMSv2 board obtained. Some routers circumvent this by allowing you to statically assign the same ip address from the DHCP pool to make sure that the RMSv2 board always gets the same ip address even over router reboots.

FOR STATIC IP

From the RMSv2 web interface, use the built-in file explorer to edit the /etc/startup.sh file.
Add the three lines marked in red and make sure to edit the third line marked in red to match your wireless gateway ip and then save the file.


#!/bin/sh
. /etc/functions.sh
########### Insert you own stuff for bootup here ###############
#information "Starting my App 1" #edit this with your app name
wpa_supplicant -B -D nl80211 -i wlan0 -c /etc/wpa_supplicant.conf
ifup -i /etc/network/wireless wlan0
route add default gw 10.10.11.1
################################################################
exit 0

The second file to edit is the /etc/network/wireless file.

The lines that are preceeded with a pound sign (#) are only comments, the important lines are colored red. Change the iface wlan0 inet line to have static at the end instead of dhcp. Edit the address line to have the ip address you want the RMSv2 board to have. You must also put correct information in the network, netmask, broadcast, and gateway lines. If you need help to determine what the network and broadcast ip addresses should be, you can use our online broadcast address calculator.
Broadcast Address Calculator.
The broadcast address calculator will also compute the network address.
When you are finished editing the file, save it.


# Configure Wireless
# Configure wlan0
auto wlan0
iface wlan0 inet static
address 10.10.11.11
network 10.10.11.0
netmask 255.255.255.0
broadcast 10.10.11.255
gateway 10.10.11.1

It is now time to reboot or power cycle the RMSv2 board. If you entered everything correctly the RMSv2 board will automatically connect to your WPA/WPA2 WiFi network and use the statically assigned ip address on every boot.


This concludes the WiFi project. We can now access our RMSv2 remote voltage monitoring board via WiFi and leave the network cables unplugged. "In a wireless world, there sure are a lot of wires."


Our Story

EtherTek Circuits started its business in 2001. Ever since we have provided remote monitoring and control solutions for Remote Tower Sites, the Oil & Gas industry, Telemetry systems for Agriculture, Municipalities, Mines, Solar Farms, Hydro Plants, and the Military.

Our Contacts

19131 33rd Avenue,
Surrey, B.C. V3Z-1A1 CANADA

+1 (604) 576-8333