Wi-Fi Open / WPA / Enterprise WPA2

Note: The code snippets in this article are intended for Mita version 1a1ed7881e2220895ec60ce4f657972538c43195 and XDK-Workbench versions 3.4.0 and higher.

The Wi-Fi API provides several interfaces to manage the Wi-Fi functionality on the XDK. XDK applications can implement this API to communicate over the Simplelink stack with surrounding Wi-Fi networks. XDK-Live offers an abstraction that solely focuses on establishing a connection to a Wi-Fi access point. This allows for simple and easily understandable implementations of Wi-Fi connections.

  1. General Information
    1. SSID
    2. IP Settings
  2. API Overview
  3. Setting up a WiFi resource
    1. WPA with DHCP
    2. WPA with static IP
    3. Enterprise WPA2
  4. Limitations and Caveats

General Information

SSID

The SSID (Service Set Identifier) describes the name of a Wi-Fi network. It is a case-sensitive string with a byte length up to 32 bytes. Devices are able to identify different access points (AP) after boot up and establish a Wi-Fi connection to them. Similar to this, the SSID can be used to search for a specific network.

IP Settings

To better understand IP settings, some explanations are important first. If the IP is set to static, it is important to adapt the parameters to the respective access point configuration.

DNS Stands for Domain Name System. Domain names serve as memorizable names for websites and other services on the Internet. However, computers access Internet devices by their IP addresses. DNS translates domain names into IP addresses, allowing you to access an Internet location by its domain name.

Gateway A gateway is a hardware device that acts as a gate between two networks. It may be a router, firewall, server, or other device that enables traffic to flow in and out of the network. While a gateway protects the nodes within the network, it is also a node itself. The gateway node is considered to be on the “edge” of the network as all data must flow through it before coming in or going out of the network. It may also translate data received from outside networks into a format or protocol recognized by devices within the internal network. A router is a common type of gateway used in home networks.

Subnet mask A subnet mask is a number that defines a range of IP addresses that can be used in a network. Subnet masks are used to designate subnetworks, or subnets, which are typically local network LANs that are connected to the Internet. Systems within the same subnet can communicate directly with each other, while systems on different subnets must communicate through a router. Therefore, subnetworks can be used to partition multiple networks and limit the traffic between them.

DHCP

The Dynamic Host Configuration Protocol (DHCP) is a standardized network protocol for dynamically assigning network configuration parameters like IP addresses. With the XDK, it is possible to implement a connection based on DHCP, too. It is possible to turn DHCP off and set the network parameters manually.

The possible IP modes are

  • static IP
  • DHCP IP

Per default, the Mita implementation uses DHCP.

API Overview

Mita provides the possibility to create a Wi-Fi resource. If the configuration and implementation provided by the Mita implementation are insufficient for a certain purpose, it is recommended to make adapting changes in the generated C code.

The image below illustrates the software API layers for Wi-Fi on the XDK.

Image

This section will demonstrate the Mita Wi-Fi API. In Mita, WLAN is defined as a named singleton resource. That means, there can only be one instance of the WLAN resource set up, and the name can be specified by the developer. All possible configuration items for the WLAN resource are listed below. The use of some of the configuration items will be explained in subsequent chapters.

connectivity named-singleton WLAN {
    generator "org.eclipse.mita.platform.xdk110.connectivity.WlanGenerator"
    validator "org.eclipse.mita.platform.xdk110.connectivity.WlanValidator"

    /**
     * Choose personal WPA connection or Enterprise WPA connection
     */
    required configuration-item authentication : authentication

    /**
     * The SSID of the WLAN network we want to connect to
     */
    required configuration-item ssid : string

    /**
     * If true server certificate will be uploaded to the WiFi chip CC3100.
     * Make sure to update service pack of the WiFi and then upload the certificate.
     * Certificate must placed under XDK110/common/certs/XDKDummy.
     */
    configuration-item isHostPgmEnabled : bool = false

    /**
     * Configure IP address and network via DHCP or static
     */
    configuration-item ipConfiguration : IpConfiguration = Dhcp()
}

Setting up a WiFi resource

WPA with DHCP

As mentioned before, the Mita implementation uses DHCP per default. As such, only the connection type, the SSID, and the PSK have to be set explicitly. The connection type Personal represents WPA. All three parameters shown in the code below are required.

NOTE: Between version 3.4 and 3.5 the syntax spelling has been corrected from authentification to authentication

setup myWifiResource : WLAN {
    authentication = Personal(psk = "myPassword");
    ssid = "mySSID";
}

Now, the WLAN resource can be attached to other resources that require a WLAN resource via the name myWifiResource.

WPA with static IP

To create a WLAN Resource, the configuration item useDHCP must be set to false and the configuration items for static IP settings staticDNS, staticGW, staticIP and staticMask become mandatory. That aside, the connection type, the SSID, and the PSK must be set as well. The connection type Personal represents WPA.

NOTE: Between version 3.4 and 3.5 the syntax spelling has been corrected from authentification to authentication

setup myWifiResource : WLAN {
  authentication = Personal(psk = "myPassword");
    ssid = "mySSID";
  ipConfiguration = Static(
     ip = "192.168.1.2",
     dns = "192.168.1.2",
     gateway = "192.168.1.1",
     subnetMask ="255.255.255.0"
   );
}

Now, the WLAN resource can be attached to other resources that require a WLAN resource via the name myWifiResource.

Enterprise WPA2

Additional to the normal WPA encrypted Wi-Fi connection, Mita also supports connecting to Enterprise WPA2 Wi-Fi networks. For that, only the connection type, the SSID and the PSK have to be set explicitly.

All three parameters shown in the code below are required.

NOTE: Between version 3.4 and 3.5 the syntax spelling has been corrected from authentification to authentication

setup wifi : WLAN {
    authentication = Enterprise(username = "myUsername", password = "myPassword");
    ssid = "mySSID";
}

Furthermore, DHCP or static IP configuration can be applied as shown in the previous two chapters.

Limitations and Caveats

The Mita Wi-Fi implementation does not yet offer functionality for scanning for networks, disconnecting and automatic reconnecting. It only connects once to the specified single Wi-Fi network.

Any further implementation can be done using the generated code, using the programming language C.

Additionally, do note that the WLAN resource will not be included in the generated code, unless another resource requires the WLAN resource. As such, standalone code that sets up a WLAN resource will not generate code, unless it is used by a resource such as HTTP or MQTT.