Feedback
Feedback

If you are having issues with the exercises, please create a ticket on DevZone: devzone.nordicsemi.com
Click or drag files to this area to upload. You can upload up to 2 files.

Exercise 1

Enabling power save modes

In this exercise, we will use Wi-Fi power save mode to reduce the power consumption of the device and inspect how different power save wake-up modes affect the power consumption using a Power Profiler Kit II (PPK2). The exercise will focus on two different power save wake-up modes: DTIM wakeup mode and listen interval wakeup mode.

To compare the power consumption of power save modes with when the radio is active, we will also connect to the HTTP server from Lesson 5 and send HTTP PUT and GET requests.

Pressing button 1 on the board will enable or disable power save mode. Pressing button 2, will alternate sending a PUT or GET request.

We will practice using the Wi-Fi Management library to:

  • Enable and disable Wi-Fi power save mode
  • Configure Wi-Fi power save wake-up mode

Exercise steps

In the GitHub repository for this course, go to the base code for this exercise, found in lesson6/wififund_less6_exer1.

1. Create two variables to keep track of the power save status and PUT/GET request.

bool nrf_wifi_ps_enabled = 1;
bool http_put = 1;

2. Configure Wi-Fi power save parameters for the power save request

2.1 Define the Wi-Fi power save parameters struct wifi_ps_params.

struct wifi_ps_params params = { 0 };

2.2 Create an if statement to check if power saving is currently enabled.

If it is not currently enabled, set the wifi_ps_params enabled parameter to WIFI_PS_ENABLED to enable power saving.
If it is enabled, set enabled to WIFI_PS_DISABLED to disable power saving.

if (!nrf_wifi_ps_enabled) {
	params.enabled = WIFI_PS_ENABLED;
}
else {
	params.enabled = WIFI_PS_DISABLED;
}

2.3 Send the power save request with net_mgmt.

if (net_mgmt(NET_REQUEST_WIFI_PS, iface, &params, sizeof(params))) {
	LOG_ERR("Power save %s failed. Reason %s", params.enabled ? "enable" : "disable", wifi_ps_get_config_err_code_str(params.fail_reason));
	return -1;
}

2.4 Toggle the value of nrf_wifi_ps_enabled to indicate the new power save status.

nrf_wifi_ps_enabled = nrf_wifi_ps_enabled ? 0 : 1;

3. Modify the button handler.

3.1 Call wifi_set_power_state() when button 1 is pressed.

wifi_set_power_state();

3.2 When button 2 is pressed, if http_put is true, call client_http_put() and increase the counter variable with 1. If http_put is false, call client_http_get() instead.

if (http_put) {
	if (server_connect() >= 0) {
		client_http_put();
		counter++;
	}
} else {
	if (server_connect() >= 0) {
		client_http_get();
	}
}

3.3 Toggle the value of http_put.

http_put = http_put ? 0 : 1;

4. Test the power saving with PPK2.

4.1 Build and flash the application to your device.

This exercise uses the PSA backend for storing the Wi-Fi credentials. Therefore, you must build with TF-M.

BoardBuild with TF-M
nRF7002 DKnrf7002dk_nrf5340_cpuapp_ns
nRF5340 DK + nRF7002 EKnrf5340dk_nrf5340_cpuapp_ns

If necessary, input the commands to connect to Wi-Fi, as we have done in previous exercises.

4.2 Start the power measurement.

4.2.1 Connect the PPK2 to the device as shown below

PPK2DK
VOUTP23 VBAT
GNDP21

Note

The current is measured over only the nRF7002 IC in this exercise, not including the nRF5340 SoC. Guides for how to measure the total current or measuring the nRF7002 IC and nRF5340 SoC separately can be found at nRF7002 DK – Measuring current.

4.2.2 Open the Power Profiler app in nRF Connect for Desktop and select the PPK2 in the drop-down menu.

4.2.3 Select source meter mode, set the supply voltage to 3.6 volts, and enable power output.

4.2.4 Press ‘Start’ in the Power Profiler app to start the measurement and press the ‘RESET’ button on the DK.

4.2.5 Test how sending packets and enabling or disabling power saving affects power consumption.

Look at the power measurement in the Power Profiler app and test by pressing the buttons to see changes in the measurement.

When the device connects to the network, the normal power save mode, which is DTIM-based power save, will be enabled by default. This will look like the start of the image below, where the device is in sleep mode with approximately 15μA power consumption before it wakes up to receive the DTIM beacon and any packets sent to it.

When pressing button 2 to send an HTTP request, there will be a spike in the power measurement since sending packets increases the power consumption.

Disabling power saving with button one will make the device always be awake and listening for packets. The power consumption will then be at a constant high level, similar to the level when the device wakes up for DTIM during power saving.

This log shows sending an HTTP PUT request, disabling power save mode, sending an HTTP GET request, and then enabling power save mode again.

5. Modify the example to test power save wakeup mode.

To decrease the power consumption we can use the extended power save mode called listen interval-based power save mode.

5.1 Create a variables to keep track of the power save wakeup mode.

bool nrf_wifi_ps_wakeup_mode = 0;

5.2 Define a new wifi_ps_params struct for the wakeup mode request.

struct wifi_ps_params params = { 0 };

5.2 Create an if statement to check the wakeup mode.

If nrf_wifi_ps_wakeup_mode is true, the wakeup mode is listen interval and we want to change it to DTIM.
If nrf_wifi_ps_wakeup_mode is false, the wakeup mode is DTIM and we want to change it to listen interval.

if (nrf_wifi_ps_wakeup_mode) {
	params.wakeup_mode = WIFI_PS_WAKEUP_MODE_DTIM;
}
else {
	params.wakeup_mode = WIFI_PS_WAKEUP_MODE_LISTEN_INTERVAL;
}

5.4 Set the request type to wakeup mode.

params.type = WIFI_PS_PARAM_WAKEUP_MODE;

5.5 Send the wakeup mode request with net_mgmt like we did in step 2.

if (net_mgmt(NET_REQUEST_WIFI_PS, iface, &params, sizeof(params))) {
	LOG_ERR("Setting wakeup mode failed. Reason %s", wifi_ps_get_config_err_code_str(params.fail_reason));
	return -1;
}

5.6 Toggle the value of nrf_wifi_ps_wakeup_mode to indicate the wakeup mode.

5.6 Modify button_handler to call wifi_set_ps_wakeup_mode() instead of wifi_set_power_state() when button 1 is pressed.

if (button & DK_BTN1_MSK) {
	wifi_set_ps_wakeup_mode();
}

6. Test the power save wakeup mode with PPK2.

6.1 Build and test the example with the PPK2 and Power Profiler app as in step 5.

As before, DTIM power save mode is by default enabled when connected to a network. When pressing button 1, the device will change to listen interval-based power save. This enables the device to sleep longer than the DTIM period, and since this increases the time the device spends in sleep mode it will decrease the average power consumption.

Wakeup mode power saving.
Average power consumption for DTIM.
Average power consumption for listen interval.

The log shows the wakeup mode being changed to listen interval and then back to DTIM again.

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

  • 8 or more characters
  • Upper and lower case letters
  • At least one number or special character

Forgot your password?
Enter the email associated with your account, and we will send you a link to reset your password.