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.

Want to keep this simple? Just set up two things:
– your Wi-Fi name and password
– a script for Wi-Fi to auto-start every time.

Configuring Wi-Fi

On ARTIK Linux-based systems, Wi-Fi operations go through the Wi-Fi Protected Access (WPA) Supplicant services program wpa_supplicant – it supports authentication and encryption for a wireless LAN. There are basic and advanced network management methods; we'll start with the basic one.

First-time setup

Follow these steps to get your system set up quickly. We provide a more advanced approach, using Connection Manager, later in this article.

  1. Make sure the Wi-Fi antenna is attached as noted here.

  2. Configure the wpa_supplicant.conf file to include your Wi-Fi router settings. You only need to set up the password information once. Use the 'wpa_passphrase' command to write your router SSID and password into the file.
    cd /etc/wpa_supplicant
    wpa_passphrase "SSID" "PASSWORD" >> wpa_supplicant.conf

    For example,
       wpa_passphrase MyAP abcd1234 >> wpa_supplicant.conf

    Connecting to an unsecured Wi-Fi access point? Put in any password here; we'll delete it below.

  3. Use an editor to verify and clean up the file contents.
       vi wpa_supplicant.conf

    1. If using secure Wi-Fi, delete your cleartext personal passphrase (the line that starts with #psk), leaving only the encrypted version.

      If you are connecting to unsecured Wi-Fi, delete both psk lines and use:
         key_mgmt=NONE
         auth_alg=OPEN

    2. Check whether the file contains multiple network login assignments. If it does, you may want 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 lines of the file look like this. If not, add them in.

      ctrl_interface=/var/run/wpa_supplicant
      ctrl_interface_group=group_name
      update_config=1

      Where you replace group_name with
      Ubuntu:netdev
      Fedora:wheel

    4. Save and exit when finished.

  4. Type reboot to write open files and reset your system.

If your connection is through a company proxy server, you have more work to do! Refer to the Proxies article for details.

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

Initialization on each startup

Every time you restart the system, the WPA supplicant service must be called to start the wireless LAN. You will then use the DHCP client services program dhclient to request a WLAN IP address from your DHCP server.

  • systemctl start wpa_supplicant should start automatically.
       – Run systemctl status wpa_supplicant to check
       – Run systemctl start wpa_supplicant if you need to start it.

  • dhclient wlan0 must be run manually or through a start-up script.

After both services are running, you'll want to execute
   ifconfig wlan0
to check whether the previous command succeeded in assigning an IP address. This will be your "localhost" IP address as we refer to it in our articles.

If you don't see a valid IP address, verify that your wpa_supplicant.conf file is correct – it should look very similar to this:

ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=wheel

network={
  ssid="ABC1234"
#psk="VM69D8PRMS"
  psk=27d496e9b...961761af7a78b466 }

If you edit the file, you need to start everything up again.

  1. Kill DHCP (if needed) with dhclient -r
  2. Run systemctl restart wpa_supplicant to restart the WLAN service
  3. Run dhclient wlan0 again.

If it still doesn't work, execute a reboot and try once more.

If successful, you are finished with Wi-Fi setup.

Connect devices to Wi-Fi through the same router

For much of your development work, you will want to set up both your ARTIK board and your development PC to be on the same Wi-Fi network. This configuration is required for the ARTIK IDE, the Arduino IDE, and the Node-RED environment, to name a few.

The ARTIK module must be on the same network as your PC host system to let them communicate with each other. A typical Wi-Fi router will default to allowing this (but may not do so if you have changed its factory settings).

Here we'll discuss setup using a Window host PC. From the terminal emulator console, set up Wi-Fi on the ARTIK board and get its IP address.

  1. Edit the wpa_supplicant.conf file to add your access point, then reset and run dhclient wlan0, as described in First-time setup.

  2. Verify that an IP address has been automatically assigned to the board by the Wi-Fi access point. Run
    ifconfig wlan0
    and make a note of the IP address.

  3. To make sure your PC is on the same network, open a Windows command window and check its IP address too.
       Start » cmd [Enter] (you should see a command window open)
     ipconfig
    Look for the Wireless adapter and verify that all but the last digits match.

The addresses will typically be something like

10.0.0.x or 192.168.10.x

Run dhclient from a script

You can configure your system to automatically reconnect Wi-Fi after each reboot. There are several methods that will work, but you can start with the ones provided here.

Under Ubuntu, simply append these two lines to /etc/network/interfaces

auto wlan0
iface wlan0 inet dhcp

Reboot and verify operation.

For Fedora 22 or later, an init script like the following can re-establish the Wi-Fi connection after each power cycle.

  1. Under your /etc/init.d/ directory, open a file named wlan and paste in these contents. Save and exit.
    #! /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
  2. Change the wlan 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
  3. Reboot and verify operation.

Connection Manager

The Connection Manager (connman) service is a more advanced network manager option with a lot of functionality. To get an idea, type:
connmanctl
and then type technologies at the prompt. You'll see that it even integrates Bluetooth® management, which we use in our related article.

With all its convenient features, Connection Manager is a bit overwhelming and can sometimes interfere with your intended connection configurations. Here we discuss how you can start making use of it; refer to a Web article like this one for more detail.

Overview

For both Ubuntu and Fedora systems, Wi-Fi operations go through wpa_supplicant services. Connection Manager adds automation (and some complexity) on top of wpa_supplicant. Here's how it figures in.

All systems can use /etc/wpa_supplicant/wpa_supplicant.conf to store Wi-Fi access point names and encrypted passwords.

  • You use wpa_passphrase to encrypt your password, and then write it to the configuration file for future use.
  • You have to start wpa_supplicant followed by dhclient to get Wi-Fi access.
  • The boot default is to enable wpa_supplicant but leave dhclient to be run manually or by a startup script.

Ubuntu and Fedora 24 releases are additionally built with Connection Manager. It provides a more structured approach with a registration agent.

  • Connection Manager is enabled by default, but just enough to leave the system backwards-compatible with the older method.

  • It starts wpa_supplicant automatically using wpa_supplicant.conf and leaves it to you to run dhclient wlan0.

  • However, once you choose to use the registration feature of Connection Manager, it takes over control such that wpa_supplicant.conf settings are ignored.

The sections below show you ways you can start using Connection Manager. Using these features is optional; you can stay with the configuration file method if you prefer.

Note that Fedora 22 systems can use only the wpa_supplicant.conf method.

Selecting an Access Point

  1. Attach a Wi-Fi antenna as noted here.
  2. Scan for wireless access points. Enter commands as follows.
    1. connmanctl to get the > prompt.
    2. scan wifi to scan for available access points (wait until finished).
    3. services to list them.
  3. Select an access point. Still within the > prompt, enter commands as follows.
    1. agent on if you want Connection Manager to prompt you for a password.
    2. connect wifi_xxxx to pick the desired access point (you can use the tab key to start, and to auto-complete, your entry).
    3. Respond to the agent query for a password if needed.
    4. quit when finished.

You won't need to repeat this process in the future: Connection happens automatically from now on.

Controlling net interfaces

At the connmanctl> prompt where you typed technologies to get a list of everything available, you can control those interfaces easily. For example, if the Ethernet controller is powered up and you need to turn it off, simply enter
disable ethernet
to take care of it.

Reverting to default operation

If you later need to revert to the default backwards-compatible approach, you can run
   systemctl disable connman
   reboot
   systemctl enable connman
   reboot
to get back where you started.

Problematic operation

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 and see connection errors or timeout errors during transfers.

Troubleshooting Tip. Getting errors within a half-minute or so of booting? Try route -n before and after the failure to see if the routing is being changed by connman. Reconfigure or disable connman if needed.

To block the p2p interface that sometimes is the cause of the problems:

  1. Bring up the /etc/connman/main.conf file for editing.

  2. Search for blacklist (in vi type /blacklist and hit Enter).

  3. To the line starting with NetworkInterfaceBlacklist, add
    p2p
    to the existing list.

  4. Save the file and reboot.

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.

Note that if you have disabled Connection Manager, you can still use wpa_cli scan_results to get a list of available access points after you have started the WPA supplicant services.

To temporarily stop or start Connection Manager once it is enabled, you can use
systemctl stop connman
systemctl start connman

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 the procedure in Troubleshooting to regenerate these mated key pairs.

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

Once again, you can read online for more information on these topics.

ssh Troubleshooting

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

The keys will be regenerated in five formats: basic, RSA, DSA, ECDSA, and its variant ED25519.

Last updated on: