Connect Azure Sphere to Wi-Fi

You can configure an Azure Sphere device to connect to the Internet through Wi-Fi using the the CLI or the Azure Sphere SDK Application Libraries (Applibs).

Authentication methods

The following authentication methods are supported:

Configure Azure Sphere for Wi-Fi

You can configure your Azure Sphere device to connect to a Wi-Fi network from the command line (CLI) or from your application using the Azure Sphere SDK Application Libraries (Applibs).

Wi-Fi configuration using the CLI

To manage Wi-Fi configuration from the command line, use the az sphere device wifi CLI commands. For example, the device wifi add command adds the details of a wireless network to the device.


az sphere device wifi add --ssid "New SSID" --psk "key \'value\' with quotes"

To use the configured Wi-Fi network, the network interface (wlan0) must be active. Use the device network list-interfaces command to determine if the interface is active.


az sphere device network list-interfaces

Use the device network enable command to activate it if necessary.


az sphere device network enable --interface wlan0

To enable the configured Wi-Fi network use the device wifi enable command.


az sphere device wifi enable --id <network id>

The Quickstart topic Set up Wi-Fi on your Azure Sphere device describes how to configure Wi-Fi on your Azure Sphere device from the command line.

Alternatively, if you are using EAP-TLS authentication see Set up EAP-TLS network from CLI.

Wi-Fi configuration using Applibs

To configure Wi-Fi, your application must use the applibs wificonfig API.

Include this header file in your application:

#include <applibs/wificonfig.h>

The application manifest must include the WifiConfig capability.

 "Capabilities": {
  "WifiConfig" : true
}

To determine if the network interface is active use the Networking_GetInterfaceConnectionStatus function.

Networking_GetInterfaceConnectionStatus("wlan0", &currentInterfaceStatus);

To activate the network interface, use the Networking_SetInterfaceState function.

Networking_SetInterfaceState("wlan0", true);

Note

If both network interfaces (wlan0 and eth0) are active and connected, the specific interface the device will use for communication is non-deterministic. If you want to control which network interface is used at any given time your application must use the Networking_SetInterfaceState() function to explicitly turn the desired interface on and the other interface off. The DHCP client high-level app sample demonstrates among other things, how to switch between interfaces by assigning a value representing one of the two interfaces to a global variable.

To enable a configured Wi-Fi network from your application, use the WifiConfig_SetNetworkEnabled function.

WifiConfig_SetNetworkEnabled(<network id>, true);

See Configure Wi-Fi in the field for suggestions for using the Applibs wificonfig API to enable your customers to configure Wi-Fi for your products that incorporate Azure Sphere.

The topic Set up EAP-TLS network in an app describes how to configure an EAP-TLS network in a high-level Azure Sphere application.

Samples

This section contains links to sample applications that demonstrate use of Wi-Fi functionality on the Azure Sphere platform.

The WiFi_HighLevelApp sample demonstrates configuring Wi-Fi networks in a high-level application.

The DHCP client high-level app demonstrates how to renew or release the current IP address that the network's DHCP server has assigned to the MT3620 device.

Note

The following samples are from the Azure Sphere Gallery, which is a collection of unmaintained software and hardware samples from Microsoft. For more information, see Azure Sphere Gallery.

The WifiConfigurationViaAppResource sample demonstrates how to configure device Wi-Fi settings using an embedded JSON resource file.

The WifiConfigurationViaNfc sample demonstrates how to configure device Wi-Fi settings using NFC.

The WifiConfigurationViaUart sample demonstrates how to configure device Wi-Fi settings using UART.