How to configure Wifi and USB wifi dongles from command-line#

Warning

We do not recommend using the built-in Raspberry Shake 3 Model B’s wifi, but it is available. Be aware that using the built-in Wifi (as opposed to Ethernet or Wifi from a USB adapter) will introduce high amplitude RF noise into the Raspberry Shake, often seriously compromising the seismic signal by introducing high amplitude low-frequency spikes. This appears to be a result of the proximity of the Wifi antenna to the Raspberry Shake board itself. External/ USB wifi solutions are not as problematic because the wifi antenna is further from the Raspberry Shake board.

Note

The Raspberry Pi 3 Model B’s wifi, which we do not recommend using, is limited to 2.4 GHz wifi connections. So “5G” connections, for example, will not work.

For general home or education purposes#

It is possible to configure WiFi from your Raspberry Shake’s internal web configuration page http://rs.local/, although we do recommend reading the warning note above.

  1. After accessing the page above, click on Settings (the gear icon high on the left)

  2. Click on Network, then WiFi Settings

  3. Check the Connect to WiFi box, then click on the refresh button next to Network SSID

  4. The network list will be populated. Select the WiFi Network you want to connect to

  5. Type in the Network password, then click on Test Wifi

  6. Once the test is successful, scroll to the bottom of the page and click Save and Restart

Your Raspberry Shake is now connected via WiFi.

Step-by-step guide for advanced users#

To configure the wifi from the command-line, start by opening a terminal and opening a connection to your Shake Pi:

$ ssh myshake@rs.local

For SSH instructions, see: How to access your Raspberry Shake’s computer via ssh. If you are a Windows user, you would use PuTTY for this step.

First confirm that the WiFi interface is enabled

$ cat /etc/network/interfaces

And verify that the following lines exist

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

If they aren’t there, edit the file, add the lines above, and save

$ sudo nano /etc/network/interfaces

Then edit the wpa_supplicant.conf

$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Paste the following lines at the end of the file and add your WiFi Connection Details (ssid and psk):

network={
        ssid="SSID of your wifi"
        psk="password of your wifi"
        proto=RSN
        key_mgmt=WPA-PSK
        pairwise=CCMP
        auth_alg=OPEN
        }

The ” are necessary. If you want to connect to a WiFi network with no password, use this configuration:

network={
        ssid="SSID of your wifi"
        key_mgmt=NONE
        }

Now reboot your shake:

$ sudo reboot

Advanced topics#

How to encrypt wifi password from command-line#

Execute this commmand:

$ wpa_passphrase <your_wifi_ssid_here> <your_wifi_password_here>

For example,

$ wpa_passphrase mywifi mypasswd

This will generate the following:

network={
        ssid="mywifi"
        #psk="mypasswd"
        psk=175c63e5acd5b9bb66cfe2f89857db9060f2edf3989c89c19e5a54e5044cd2a4
}

Copy this output to /etc/wpa_supplicant/wpa_supplicant.conf and remove the #psk line to make it fully encrypted

How to enable both WiFi and Ethernet Interfaces#

When your Shake Pi boots, if it detects that an Ethernet interface is active, WiFi will be turned off by default. This is how Ethernet and WiFi network connections work with each other:

  1. If an ethernet cable is plugged in, and the setting in the configuration file is off, WiFi drivers will be automatically turned off at system boot to avoid unnecessary spikes in the signal.

  2. If no ethernet cable is plugged in, and if WiFi is properly configured, a connection will be made to the WiFi network; the setting in the WiFi configuration file is ignored.

  3. If an ethernet cable is plugged in, and the end-user wants a dual network connection over a WiFi network, then WiFi must be properly configured and the setting in the WiFi configuration file must be set to ON (see below).

Per #3, if you wish to enable both WiFi and Ethernet interfaces, changing the configuration file at /opt/settings/user/enable-wifi.conf will allow you to do so. By default this file contains the following lines:

# WiFi enablement configuration file
# should contain a single line not beginning with #
# specifying either ON or OFF

OFF

Edit this file

$ sudo nano /opt/settings/user/enable-wifi.conf

Modify the last line from OFF to ON.

Reboot your shake:

$ sudo reboot

How can I set up a USB Wifi Dongle#

First you’ll need to verify if your USB was tested on Raspberry Pi computer (RPi): https://elinux.org/RPi_USB_Wi-Fi_Adapters

Then plug your USB Dongle into your RPi and see if the RPi recognizes the device. For example,

$ sudo dmesg -T | grep usb

If your device was succesfully recognized, the OS will answer with something similar to this:

$...
  [Fri Aug  3 13:45:11 2018] usb 1-1.4: new high-speed USB device number 4 using dwc_otg
  [Fri Aug  3 13:45:11 2018] usb 1-1.4: New USB device found, idVendor=0bda, idProduct=8176
  [Fri Aug  3 13:45:11 2018] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
  [Fri Aug  3 13:45:11 2018] usb 1-1.4: Manufacturer: Realtek
  [Fri Aug  3 13:45:11 2018] usb 1-1.4: SerialNumber: 00e04c000001
  [Fri Aug  3 13:45:12 2018] usbcore: registered new interface driver rtl8192cu

Now try this command and see if the RPi mounts the Dongle as wlan

$ iwconfig

   eth0      no wireless extensions.

   docker0   no wireless extensions.

   vethba76434  no wireless extensions.

   wlan0     unassociated  Nickname:"<WIFI@REALTEK>"
             Mode:Auto  Frequency=2.412 GHz  Access Point: Not-Associated
             Sensitivity:0/0
             Retry:off   RTS thr:off   Fragment thr:off
             Power Management:off
             Link Quality:0  Signal level:0  Noise level:0
             Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
             Tx excessive retries:0  Invalid misc:0   Missed beacon:0

   lo        no wireless extensions.

   vetheb6d057  no wireless extensions.

As you can see, the RPi’s OS sees our Dongle as wlan0. But why wlan0 if RpiZw and Rpi3 have their own wifi module inside? This is because, by default, wlan0 is disabled on Raspberry Shake.

The next step will be to adjust your config file to match your wifi parameters and reboot your RPi.

What to do if the Shake doesn’t recognize your device#

If you are having trouble with your WiFi dongle, the Shake may have the wrong driver (or no driver at all) for your dongle. This used to be a very frustrating problem until we discovered a bash script that downloads and installs the correct driver for your device automatically based on its USB code. The script is at http://fars-robotics.net/, clicking on Wifi Drivers. Although it is generally not a good idea to run code directly from the web, this process has never failed us when all else does. To run the script, you need to save it somewhere on your path. Follow these instructions to download and make it executable:

$ sudo wget http://downloads.fars-robotics.net/wifi-drivers/install-wifi -O /usr/bin/install-wifi
$ sudo chmod +x /usr/bin/install-wifi
$ sudo install-wifi

Essentially this script checks the lsusb codes of USB devices against a compiled list, then downloads and installs the correct driver for any devices it recognizes as a WiFi dongle.

What to do if there are two wlan devices#

Sometimes the USB dongle activation process will result in both the internal and USB wifi modules on at the same time. This will look similar to the following:

$ iwconfig

   eth0      no wireless extensions.

   docker0   no wireless extensions.

   vethba76434  no wireless extensions.

   wlan0     IEEE 802.11  ESSID:off/any
             Mode:Managed  Access Point: Not-Associated   Tx-Power=31 dBm
             Retry short limit:7   RTS thr:off   Fragment thr:off
             Power Management:on

   wlan1     unassociated  Nickname:"<WIFI@REALTEK>"
             Mode:Auto  Frequency=2.412 GHz  Access Point: Not-Associated
             Sensitivity:0/0
             Retry:off   RTS thr:off   Fragment thr:off
             Power Management:off
             Link Quality:0  Signal level:0  Noise level:0
             Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
             Tx excessive retries:0  Invalid misc:0   Missed beacon:0

   lo        no wireless extensions.

   vetheb6d057  no wireless extensions.

In this case, wlan0 is the internal device and wlan1 is the USB dongle. This could be switched based on your setup, and may change after a restart.

This defeats the purpose of using the USB WiFi, because the internal module will generate radiofrequency noise that will affect the data, which is what we are trying to avoid by using the dongle in the first place.

To disable internal WiFi:

  1. Disable the internal module in the boot config:

    $ sudo nano /boot/config.txt
    

Then paste the following line into the file, save, and exit:

dtoverlay=pi3-disable-wifi
  1. Add the internal module to the modprobe blacklist:

    $ sudo nano /etc/modprobe.d/raspi-blacklist.conf
    

Then paste the following lines into the file, save, and exit:

blacklist brcmfmac
blacklist brcmutil

Now, restart the Shake, run iwconfig, and check to make sure that only the wlan0 device appears.

How can I check if my USB Wifi Dongle sees the wifi networks#

You can use the following command

$ sudo iwlist wlan0 scanning

The OS will reply

$ wlan0     Scan completed :
            Cell 01 - Address: 00:15:6D:9E:D7:01
            ESSID:"thediscoverwifi"
            Protocol:IEEE 802.11bg
            Mode:Master
            Frequency:2.412 GHz (Channel 1)
            Encryption key:on
            Bit Rates:54 Mb/s
            Extra:rsn_ie=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(you will see a numer/character string)
            IE: IEEE 802.11i/WPA2 Version 1
                Group Cipher : TKIP
                Pairwise Ciphers (2) : CCMP TKIP
                Authentication Suites (1) : PSK
            Quality=97/100  Signal level=49/100

The results will be different acording to your wifi network.

How can I configure my USB Wifi Dongle if my Wifi is “hidden”#

You will need to specify an extra option in your wpa_supplicant.conf file

$ network={
        ssid="yourHiddenSSID"
        scan_ssid=1
        psk="Your_wifi_password"
  }