Wi-Fi: Bluetooth LE based provision
This sample demonstrates how to provision a Wi-Fi® device over a Bluetooth® Low Energy link.
Requirements
The sample supports the following development kits:
Hardware platforms |
PCA |
Board name |
Shields |
|
|---|---|---|---|---|
PCA20053 |
|
|
||
PCA10143 |
|
|||
PCA10143 |
|
|||
PCA10184 |
|
|
||
PCA10156 |
|
|
||
PCA10175 |
|
|
||
PCA10095 |
|
|
The sample requires a smartphone (configurator) with Nordic Semiconductor’s nRF Wi-Fi Provisioner app installed in one of the following versions:
Overview
With this sample, you can provision a Wi-Fi device that lacks input or output capability, using the Wi-Fi provisioning Bluetooth LE transport library. The sample is divided into three parts:
Task and event handling component: Handles provisioning-related tasks and events.
Transport layer: Based on Bluetooth Low Energy and exchanges information between the device and the nRF Wi-Fi Provisioner app.
Configuration management component: Manages the provisioning data (in RAM and flash) accessed by multiple threads.
Configuration
See Configuring and building for information about how to permanently or temporarily change the configuration.
Configuration options
The following sample-specific Kconfig options are used in this sample (located in samples/wifi/provisioning/ble/Kconfig):
- CONFIG_WIFI_PROV_ADV_DATA_UPDATE
This option enables periodic updates of advertisement data.
- CONFIG_WIFI_PROV_ADV_DATA_UPDATE_INTERVAL
This option specifies the update interval of the advertisement data.
To get live update of the Wi-Fi status without setting up a Bluetooth connection, enable the CONFIG_WIFI_PROV_ADV_DATA_UPDATE Kconfig option. Set the CONFIG_WIFI_PROV_ADV_DATA_UPDATE_INTERVAL Kconfig option, to control the update interval.
Features
The sample implements advertising over Bluetooth LE.
After powerup, the device checks whether it is provisioned. If it is, it loads saved credentials and tries to connect to the specified access point.
The device advertises over Bluetooth LE.
The advertising data contains several fields to facilitate provisioning. It contains the UUID of the Wi-Fi Provisioning Service and four bytes of service data, as described in the following table.
Byte 1 |
Byte 2 |
Byte 3 |
Byte 4 |
|---|---|---|---|
Version |
Flag(LSB) |
Flag(MSB) |
RSSI |
Version: 8-bit unsigned integer. The value is the version of the Wi-Fi Provisioning Service sample.
Flag: 16-bit little endian field. Byte 2 (first byte on air) is LSB, and Byte 3 (second byte on air) is MSB.
Bit 0: Provisioning status. The value is
1if the device is provisioned, otherwise it is0.Bit 1: Connection status. The value is
1if Wi-Fi is connected, otherwise it is0.Bit 2 - 15: RFU
RSSI: 8-bit signed integer. The value is the signal strength. It is valid only if the Wi-Fi is connected.
The advertising interval depends on the provisioning status. If the device is not provisioned, the interval is 100 ms. If it is provisioned, the interval is one second.
Building and running
This sample can be found under samples/wifi/provisioning/ble in the nRF Connect SDK folder structure.
To build the sample, follow the instructions in Building an application for your preferred building environment. See also Programming an application for programming steps and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.
Note
When building repository applications in the SDK repositories, building with sysbuild is enabled by default.
If you work with out-of-tree freestanding applications, you need to manually pass the --sysbuild parameter to every build command or configure west to always use it.
When building this sample with Sysbuild for an SoC that has a network core, the IPC radio firmware is automatically applied to the build.
The IPC radio is one of the companion components in the nRF Connect SDK and allows to use the radio peripheral from another core in a multicore device.
If needed, you can modify the IPC radio configuration in the prj.conf source file in the sample’s sysbuild/ipc_radio directory.
The sample generates header and source files based on protocol buffer definitions in .proto files during the build process.
You must install a protocol buffer compiler to generate the files.
See the Nanopb in the Zephyr documentation for more information.
Refer to the sample.yaml file for a complete list of supported boards and their corresponding build command options.
Testing
After programming the sample to your development kit, complete the following steps to test it:
Connect the kit to the computer using a USB cable. The kit is assigned a serial port. Serial ports are referred to as COM ports on Windows, /dev/ttyACM devices on Linux, and /dev/tty devices on macOS. To list Nordic Semiconductor devices connected to your computer together with their serial ports, open a terminal and run the
nrfutil device listcommand. Alternatively, check your operating system’s device manager or its equivalent.Connect to the kit with a terminal emulator (for example, the Serial Terminal app). See Testing and optimization for the required settings and steps.
Observe the following output:
wifi_prov: BT Advertising successfully startedOpen the nRF Wi-Fi Provisioner app.
Enable Bluetooth if it is disabled.
Search and connect to the device you want to provision. If the connection and pairing are established, observe the following output:
wifi_prov: BT Connected: <configurator BT address> wifi_prov: BT pairing completed: <configurator BT address>, bonded: 0
Start an access point scan.
Enter the password, if required.
Establish a Wi-Fi connection.
Observe the following output, if the connection is successful:
wpa_supp: wlan0: CTRL-EVENT-CONNECTED - Connection to <AP MAC Address> completed [id=0 id_str=]
Dependencies
This sample uses the following nRF Connect SDK libraries:
This sample also uses a module that can be found in the following location in the nRF Connect SDK folder structure:
modules/lib/nanopb
In addition, it uses the following Zephyr libraries:
API:
include/bluetooth/bluetooth.hinclude/bluetooth/conn.hinclude/bluetooth/uuid.hinclude/bluetooth/gatt.hinclude/net/wifi.hinclude/net/wifi_mgmt.h