Click or drag files to this area to upload. You can upload up to 2 files.

Network Management API

The Network Management API allow applications, as well as network layer code itself, to call defined network routines at any level in the IP stack, or receive notifications on relevant network events. This is the API we will use to connect over Wi-Fi.

Enabling the API

To enable the Network Management API in your application, enable the following Kconfigs

In addition, you need to include the following header files

  • net_mgmt.h: header file for the Network Management API
  • net_event.h: header file for Network Management events
  • wifi_mgmt.h: header file for Wi-Fi specific Network Management API’s

Enabling Wi-Fi

To be able to use the Network Management API to connect to Wi-Fi, we also need to enable Wi-Fi in the application.

This is done by enabling the following Kconfigs

  • CONFIG_WIFI: Enables the general Wi-Fi drivers
  • CONFIG_WIFI_NRF700X: Enables the Nordic Wi-Fi Driver
  • CONFIG_WPA_SUPP: Enables WPA (Wi-Fi Protected Access) supplication support, primarily responsible for implementing the authentication phase of WPA, as well as network scanning, key exchange and roaming support.

Configure the Wi-Fi parameters

When connecting to Wi-Fi, the parameters are passed in the structure struct wifi_connect_req_params, which has the following signature

  • SSID – SSID of your Wi-Fi network
  • PSK – Password of your Wi-Fi network
  • SAE password (sae_password)
  • Band (band) – Wi-Fi band you want to connect to (default is ??)
  • Channel (channel) – Wi-Fi channel to use
  • Security – The security with which you want to connect
  • MFP – Management frame protection options
  • Timeout – Connection timeout

Here is an example of populating the Wi-Fi parameters.

Request the Wi-Fi connection

All network management requests are called using net_mgmt(), which has the following signature

  • mgmt_request: a bitmask to indicate which stack layer is targeted, if a net_if object is implied and the specific management procedure being requested
  • iface: network interface being used, use the helper function net_if_get_default()
  • data: the Wi-Fi configuration parameters, stored in struct wifi_connect_req_params
  • len: the length of data, i.e sizeof(struct wifi_connect_req_params)

Wi-Fi related network management requests


Listening to network events

The callback handler function net_mgmt_event_handler_t must have the following signature

There are many Wi-Fi related network events, defined in wifi_mgmt.h (found in <install_path/include/zephyr/net), but for now we will only focus on NET_EVENT_WIFI_CONNECT_RESULT, to be notified once a Wi-Fi connection is established.

Define the callback function

Define the callback function wifi_connect_handler()

Initialize the callback structure

To initialize the callback structure, we will use the helper function net_mgmt_init_event_callback() which has the following signature

Add the callback structure

Then we need to add the callback structure, using net_mgmt_add_event_callback() which has the following signature

Register an account
Already have an account? Log in
(All fields are required unless specified optional)

Forgot your password?
Enter your email address, and we will send a link to reset your password.