.. _wifi_station_sample: Wi-Fi: Station ############## .. contents:: :local: :depth: 2 The Station sample demonstrates how to connect the Wi-Fi station to a specified access point using Dynamic Host Configuration Protocol (DHCP). Requirements ************ The sample supports the following development kit: .. table-from-sample-yaml:: Overview ******** This sample can perform Wi-Fi operations such as connect and disconnect in the 2.4GHz and 5GHz bands depending on the capabilities of an access point. The sample also adds LED support to map with connection and disconnection events: * **LED1** starts blinking when the sample is connected to the access point. * **LED1** stops blinking when the sample is disconnected from the access point. Using this sample, the development kit can connect to the specified access point in :abbr:`STA (Station)` mode. Quad Serial Peripheral Interface (QSPI) encryption ************************************************** This sample demonstrates QSPI encryption API usage, the key can be set by the :kconfig:option:`CONFIG_NRF700X_QSPI_ENCRYPTION_KEY` Kconfig option. If encryption of the QSPI traffic is required for the production devices, then matching keys must be programmed in both the nRF7002 OTP and non-volatile storage associated with the host. The key from non-volatile storage must be set as the encryption key using the APIs. Power management **************** This sample also enables Zephyr's power management policy by default, which puts the nRF5340 :term:`System on Chip (SoC)` into low-power mode whenever it is idle. See :ref:`zephyr:pm-guide` in the Zephyr documentation for more information on power management. IP addressing ************* The sample uses DHCP to obtain an IP address for the Wi-Fi interface. It starts with a default static IP address to handle networks without DHCP servers, or if the DHCP server is not available. Successful DHCP handshake will override the default static IP configuration. The following static configuration is by default and can be changed in the ``prj.conf`` file: .. code-block:: console CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.168.1.98" CONFIG_NET_CONFIG_MY_IPV4_NETMASK="255.255.255.0" CONFIG_NET_CONFIG_MY_IPV4_GW="192.168.1.1" Building and running ******************** .. |sample path| replace:: :file:`samples/wifi/sta` .. include:: /includes/build_and_run_ns.txt Currently, the following board(s) are supported: * nRF7002 DK You must configure the following Wi-Fi credentials in ``prj.conf``: * Network name (SSID) * Key management * Password .. note:: You can also use ``menuconfig`` to enable ``Key management`` option. See :ref:`zephyr:menuconfig` in the Zephyr documentation for instructions on how to run ``menuconfig``. To build for the nRF7002 DK, use the ``nrf7002dk_nrf5340_cpuapp`` build target. The following is an example of the CLI command: .. code-block:: console west build -b nrf7002dk_nrf5340_cpuapp Testing ======= |test_sample| #. |connect_kit| #. |connect_terminal| The sample shows the following output: .. code-block:: console [00:00:02.016,235] sta: Connection requested [00:00:02.316,314] sta: ================== [00:00:02.316,314] sta: State: SCANNING [00:00:02.616,424] sta: ================== [00:00:02.616,424] sta: State: SCANNING [00:00:02.916,534] sta: ================== [00:00:02.916,534] sta: State: SCANNING [00:00:03.216,613] sta: ================== [00:00:03.216,613] sta: State: SCANNING [00:00:03.516,723] sta: ================== [00:00:03.516,723] sta: State: SCANNING [00:00:03.816,802] sta: ================== [00:00:03.816,802] sta: State: SCANNING [00:00:04.116,882] sta: ================== [00:00:04.116,882] sta: State: SCANNING [00:00:04.416,961] sta: ================== [00:00:04.416,961] sta: State: SCANNING [00:00:04.717,071] sta: ================== [00:00:04.717,071] sta: State: SCANNING [00:00:05.017,150] sta: ================== [00:00:05.017,150] sta: State: SCANNING [00:00:05.317,230] sta: ================== [00:00:05.317,230] sta: State: SCANNING [00:00:05.617,309] sta: ================== [00:00:05.617,309] sta: State: SCANNING [00:00:05.917,419] sta: ================== [00:00:05.917,419] sta: State: SCANNING [00:00:06.217,529] sta: ================== [00:00:06.217,529] sta: State: SCANNING [00:00:06.517,639] sta: ================== [00:00:06.517,639] sta: State: SCANNING [00:00:06.817,749] sta: ================== [00:00:06.817,749] sta: State: SCANNING [00:00:07.117,858] sta: ================== [00:00:07.117,858] sta: State: SCANNING [00:00:07.336,730] wpa_supp: wlan0: SME: Trying to authenticate with aa:bb:cc:dd:ee:ff (SSID='' freq=5785 MHz) [00:00:07.353,027] wifi_nrf: wifi_nrf_wpa_supp_authenticate:Authentication request sent successfully [00:00:07.417,938] sta: ================== [00:00:07.417,938] sta: State: AUTHENTICATING [00:00:07.606,628] wpa_supp: wlan0: Trying to associate with aa:bb:cc:dd:ee:ff (SSID='' freq=5785 MHz) [00:00:07.609,680] wifi_nrf: wifi_nrf_wpa_supp_associate: Association request sent successfully [00:00:07.621,978] wpa_supp: wpa_drv_zep_get_ssid: SSID size: 5 [00:00:07.622,070] wpa_supp: wlan0: Associated with aa:bb:cc:dd:ee:ff [00:00:07.622,192] wpa_supp: wlan0: CTRL-EVENT-CONNECTED - Connection to aa:bb:cc:dd:ee:ff completed [id=0 id_str=] [00:00:07.622,192] sta: Connected [00:00:07.623,779] wpa_supp: wlan0: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0 [00:00:07.648,406] net_dhcpv4: Received: 192.168.119.6 [00:00:07.648,468] net_config: IPv4 address: 192.168.119.6 [00:00:07.648,498] net_config: Lease time: 3599 seconds [00:00:07.648,498] net_config: Subnet: 255.255.255.0 [00:00:07.648,529] net_config: Router: 192.168.119.147 [00:00:07.648,559] sta: DHCP IP address: 192.168.119.6 [00:00:07.720,153] sta: ================== [00:00:07.720,153] sta: State: COMPLETED [00:00:07.720,153] sta: Interface Mode: STATION [00:00:07.720,184] sta: Link Mode: WIFI 6 (802.11ax/HE) [00:00:07.720,184] sta: SSID: [00:00:07.720,214] sta: BSSID: aa:bb:cc:dd:ee:ff [00:00:07.720,214] sta: Band: 5GHz [00:00:07.720,214] sta: Channel: 157 [00:00:07.720,245] sta: Security: OPEN [00:00:07.720,245] sta: MFP: UNKNOWN [00:00:07.720,245] sta: RSSI: -57 [00:00:07.720,245] sta: Static IP address: Power management testing ************************ This sample can be used to measure current consumption of both the nRF5340 SoC and nRF7002 device independently by using two separate Power Profiler Kit II's (PPK2's). The nRF5340 SoC is connected to the first PPK2 and the nRF7002 DK is connected to the second PPK2. Hardware modifications ====================== To measure the current consumption of the nRF5340 SoC in the nRF7002 DK, complete the following steps: * Remove jumper on **P22** (VDD jumper). * Cut solder bridge **SB16**. * Make a short on solder bridge **SB17**. * Connect **GND** on PPK2 kit to **GND** on the nRF7002 DK. You can use **P4** pin **7** mentioned as **GND** for ground. Note that this connection requires a berg pin connector. * Connect the **Vout** on PPK2 to **P22** pin **1** on the nRF7002 DK. To measure the current consumption of the nRF7002 device in the nRF7002 DK, complete the following steps: * Remove jumper on **P23** (VBAT jumper). * Connect **GND** on PPK2 kit to **GND** on the nRF7002 DK. You can use **P21** pin **1** mentioned as **-** (**MINUS**) for ground. * Connect the **Vout** on PPK2 to **P23** pin **1** on the nRF7002 DK. The following diagram illustrates a typical configuration for measuring current on the nRF7002 DK for both the nRF5340 SoC and the nRF7002 device: .. figure:: ../../../../../../nrf/images/nrf7002_nrf5340_current_measurements.svg :alt: Typical configuration for measuring current on the nRF7002 DK for both the nRF5340 SoC and the nRF7002 device. Typical configuration for measuring current on the nRF7002 DK for both the nRF5340 SoC and the nRF7002 device. PPK2 usage and measurement ========================== To measure the current consumption of the nRF5340 SoC and the nRF7002 device, complete the following steps: * Configure PPK2 connected to the nRF5340 SoC as a source meter with 1.8 volts. * Configure PPK2 connected to the nRF7002 device as a source meter with 3.6 volts. See :ref:`app_power_opt` for more information on power management testing and usage of the PPK2. The average current consumption in an idle case can be around ~1-2 mA in the nRF5340 SoC and ~20 µA in the nRF7002 device. Dependencies ************ This sample uses the following `sdk-nrfxlib`_ library: * :ref:`nrfxlib:nrf_security`