Filter results by

Wi-Fi Client

This article explains how to configure and use Wi-Fi as the client of an external Wi-Fi access point (such as a home gateway-router). Setting up your ARTIK system as a Wi-Fi client is prerequisite to most of the development work you will do.

Configuring Wi-Fi

All Wi-Fi operations go through Wi-Fi Protected Access (WPA) Supplicant services wpa_supplicant, which supports authentication and encryption for a wireless LAN.

For now, just follow these steps to get your system set up quickly. You'll eventually want to know more about how to configure these services; we provide a link below for advanced reading.

First Step: Prepare the Board

  1. Attach a Wi-Fi antenna as noted here.
  2. Scan for wireless access points.
    wpa_cli scan_results

Hopefully, your intended access point is listed!

2nd Step: Add Password Information

Configure the wpa_supplicant.conf file to include your Wi-Fi router settings. You only need to set up the password information once.

  1. Change to the WPA supplicant directory.
    cd /etc/wpa_supplicant
  2. Use the wpa_passphrase command to write your router SSID and password into the WPA supplicant configuration file.
    wpa_passphrase "SSID" "PASSWORD" >> wpa_supplicant.conf

    For example,

	wpa_passphrase MyAP abcd1234 >> wpa_supplicant.conf

For more advanced Wi-Fi security settings, you can refer to this page or other online resources.

Final Step: Clean Up the File Contents

Use an editor to check the file contents.

vi wpa_supplicant.conf

  1. For security, delete your personal passphrase (the one that has # in front of it), leaving only the encrypted version.

  2. Make sure the file does not contain multiple network login assignments.
    If it does, you may need to comment out the ones you do not need to prevent them from being selected instead of your chosen network.

  3. Make sure that the first two lines of the file look like this. If not, add them in.

	ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=wheel

Save and exit when finished, then type reboot to write open files and reset your system.

Initialization on Each Startup

Every time you restart the system, the WPA supplicant and DHCP client services must be called to start services and request a wireless LAN IP address from your DHCP server.

  • On firmware from February 2016 and later, this call is made automatically by the Connection Manager (connman) service. It's a convenient feature but can sometimes interfere with your connections – refer below for more information.

  • Otherwise, you will need to make sure both services are running:
    systemctl start wpa_supplicant (automatic in pre-2016 firmware)
    dhclient wlan0 (must be run manually)

After this step, you can run
ifconfig wlan0
to check whether the previous command succeeded in assigning an IP address. This will be your "localhost" IP address.

If you don't see a valid IP address, try running dhclient -r and then run dhclient wlan0 again.

For reference, you can also use this command to restart after making configuration changes.

systemctl restart wpa_supplicant

Refer to the FAQ section if you have any problems. Otherwise, you are finished with Wi-Fi setup.

Extra Credit: Linux scp and ssh

Once you have a network connection between your PC and ARTIK, you can use scp to transfer files. For example, if you're not fond of editing in vi, you can compose a C code file on your local PC editing program and then copy it over to your ARTIK board.

You can read online for the general usage of the command. As a quick example,
scp testfile.c root@192.168.1.15:./.
copies testfile.c from your current PC directory to the root directory of the ARTIK board on the network noted. The system will ask for your login password (default 'root') before completing the transfer.

  • For Mac® and Linux® systems: You can enter the scp command line in the terminal emulator.
  • For Windows® systems: You will need to open a Git bash window (not a DOS command window). You could instead install an scp client for Windows like FileZilla or WinSCP.

You can also run an ssh session for more complex tasks. With SSH, you generate two mated keys, one public and one private. You initially send the public key to any server you'll be transacting business with. Then during authentication, the server verifies that you have the private mate of the public key that it has on file.

Go to the directory at /etc/ssh and you'll see several ssh_host_... files. At any time, you can delete these and use

1
`ssh-keygen -A`

to regenerate these mated key pairs in five formats: basic, RSA, DSA, ECDSA, and its variant ED25519.

SSH keys are a separate topic from the SSL certificate environment described here.

Once again, you can read online for more information on this topic.

Troubleshooting Tip. Running into this error trying to ssh to ARTIK?

ssh: connect to host XXX.XXX.XXX.XXX port 22: Connection timed out 

If so, the SSH keys may have been corrupted. Re-create the host keys by using these two commands.
rm /etc/ssh/ssh_host_*
ssh-keygen -A

Connection Manager

The Connection Manager (connman) package is pre-installed and pre-enabled on firmware image releases from Feb 2016 onwards. Prior to that:

  • wpa_supplicant was executed automatically during the boot sequence
  • dhclient wlan0 had to be run manually or from a startup script.

With connman running, both of these commands are executed automatically.

Troubleshooting Tip. There are times that Connection Manager can get in the way of intended operations by "stealing" connections. You will likely encounter this scenario if you are trying to run through a proxy, where you get connection errors or timeout errors during transfers.

To permanently disable Connection Manager, type:

systemctl disable connman.service

and reboot your system. From that point forward, you will need to manually run:

systemctl start wpa_supplicant followed by dhclient wlan0

on each reboot.

FAQ

When I scan for nearby Wi-Fis, I run into the error message below:

wpa_cli scan_results

Failed to connect to non-global ctrl_ifname: (null) error: No such
file or directory 

Here's how to fix it:

  1. Add ctrl_interface=/var/run/wpa_supplicant to /etc/wpa_supplicant/wpa_supplicant.conf.

    If you already have networks defined in your wpa_supplicant.conf file, it should look something like this:

    1
    2
    3
    4
    5
    6
    7
     ctrl_interface=/var/run/wpa_supplicant
     ctrl_interface_group=wheel
     network={
       ssid="MyAP"
       #psk="password" 
       psk=8b3290c1fc03ce4dda082c21e1a5e264a97a58523a4bd8be61eda65f2a14accd
     }
  2. Restart wpa_supplicant by running

    systemctl restart wpa_supplicant

Running wpa_cli scan_result should work now.

How can I configure ARTIK to automatically reconnect Wi-Fi after each reboot?

One way of doing this is to edit your system init script.

If you are using Fedora 20, in your /etc/rc.d/rc.local file, you can easily find a chunk of code that enables Wi-Fi. Simply adding dhclient wlan0 to the end of the chunk will get your board auto-connected when it reboots.

If you have upgraded to Fedora 22, you can create your own init script for re-establishing the Wi-Fi connection after each power cycle. Under your /etc/init.d/directory, generate a script named wlan. Here is a sample of how wlan looks:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#! /bin/bash
#chkconfig: - 99 10

start()
{
/usr/sbin/dhclient wlan0
}

stop()
{
kill dhclient
}

restart()
{
stop
start
}


case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    restart
    ;;
  *)
    echo "Usage:$0 {start|stop|restart}"
esac

exit 0

Save the script, change its file mode to be executable, and enable it for reboot:

chmod a+x /etc/init.d/wlan

chkconfig --add wlan

chkconfig --level 12345 wlan on

Last updated on: