Wi-Fi: SoftAP
The SoftAP sample demonstrates how to start an nRF70 Series device in Software-enabled Access Point (SoftAP or SAP) mode.
Requirements
The sample supports the following development kits:
Hardware platforms |
PCA |
Board name |
Board target |
Shields |
---|---|---|---|---|
PCA10143 |
|
|||
PCA10143 |
|
|||
PCA10095 |
|
|
Overview
The sample enables SoftAP mode and allows the devices to connect to it. It starts a Dynamic Host Configuration Protocol (DHCP) server to assign the automatic IP address to the connected devices. Then, the sample lists the connected devices.
You can enable the SoftAP mode by setting the below configuration options in the sample project configuration file:
CONFIG_NRF700X_AP_MODE
: Enables access point mode support.CONFIG_WPA_SUPP_AP
: Enables access point support.
The sample uses the Wi-Fi ready library to check Wi-Fi readiness.
To use the Wi-Fi ready library, enable the CONFIG_WIFI_READY_LIB
Kconfig option.
Note
The SoftAP mode operation is dictated by regulatory requirements. It is mandatory to set the regulatory domain to a specific country when operating in the 5 GHz frequency band.
You can set the regulatory domain using the below configuration option:
CONFIG_SOFTAP_SAMPLE_REG_DOMAIN
: Sets the ISO/IEC alpha2 country code.
For more information, see the SoftAP mode documentation.
Configuration
See Configuring and building for information about how to permanently or temporarily change the configuration.
Configuration options
The following Kconfig options are used in this sample (located in samples/wifi/softap/Kconfig
):
- CONFIG_SOFTAP_SAMPLE_DHCPV4_SERVER
DHCPv4 server
Enable this to configure DHCPV4 server settings.
- CONFIG_SOFTAP_SAMPLE_DHCPV4_POOL_START
Start address of DHCPv4 pool
Set the start IP address of DHCPv4 pool.
- CONFIG_SOFTAP_SAMPLE_REG_DOMAIN
The ISO/IEC alpha2 country code
Set the ISO/IEC alpha2 country code for the country in which the device is currently operating. For world regulatory, use “00”.
- CONFIG_SOFTAP_SAMPLE_2_4GHz
2.4 GHz band
Enable this option if the SoftAP should operate in the 2.4 GHz band.
- CONFIG_SOFTAP_SAMPLE_5GHz
5 GHz band
Enable this option if the SoftAP should operate in the 5 GHz band. Ensure that you have the appropriate regulatory settings configured.
- CONFIG_SOFTAP_SAMPLE_CHANNEL
SoftAP channel
Set the Wi-Fi channel on which the SoftAP will operate.
- CONFIG_SOFTAP_SAMPLE_SSID
SoftAP SSID
Set the SSID (Service Set Identifier) for the SoftAP. This is the name that will be broadcasted for client(s) to connect.
- CONFIG_SOFTAP_SAMPLE_KEY_MGMT_NONE
Open security
Enable for open security
- CONFIG_SOFTAP_SAMPLE_KEY_MGMT_WPA2
WPA2 security
Enable for WPA2 security
- CONFIG_SOFTAP_SAMPLE_KEY_MGMT_WPA2_256
WPA2 SHA 256 security
Enable for WPA2-PSK-256 security.
- CONFIG_SOFTAP_SAMPLE_KEY_MGMT_WPA3
WPA3 security
Enable for WPA3 security.
- CONFIG_SOFTAP_SAMPLE_PASSWORD
Passphrase (WPA2) or password (WPA3)
Set the password for SoftAP.
- CONFIG_SOFTAP_SAMPLE_MAX_STATIONS
Maximum number of stations
Set the maximum number of stations allowed to connect to the SoftAP.
- CONFIG_SOFTAP_SAMPLE_START_WIFI_THREAD_STACK_SIZE
Stack size for Wi-Fi start thread
Set the stack size for the Wi-Fi start thread.
IP addressing
The sample starts the DHCP server on the SoftAP interface. The station devices should use DHCP to get an IP address from the virtual router.
To specify the DHCP pool start address, you can edit the CONFIG_SOFTAP_SAMPLE_DHCPV4_POOL_START
Kconfig option in the prj.conf
file.
Building and running
This sample can be found under samples/wifi/softap
in the nRF Connect SDK folder structure.
When built as firmware image for a board target with the */ns
variant, the sample has Cortex-M Security Extensions (CMSE) enabled and separates the firmware between Non-Secure Processing Environment (NSPE) and Secure Processing Environment (SPE).
Because of this, it automatically includes the Trusted Firmware-M (TF-M).
To read more about CMSE, see Processing environments.
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.
To build for the nRF7002 DK, use the nrf7002dk/nrf5340/cpuapp
board target.
The following is an example of the CLI command:
west build -b nrf7002dk/nrf5340/cpuapp
To build for the nRF7002 EK with nRF5340 DK, use the nrf5340dk/nrf5340/cpuapp
board target with the SHIELD
CMake option set to nrf7002ek
.
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 COM port (Windows) or ttyACM device (Linux), which is visible in the Device Manager.
Connect to the kit with a terminal emulator (for example, nRF Connect Serial Terminal). See Testing and optimization for the required settings and steps.
The sample shows the following output:
*** Booting nRF Connect SDK v3.4.99-ncs1-4797-g7c3e830729b7 *** [00:00:00.580,596] <inf> net_config: Initializing network [00:00:00.580,596] <inf> net_config: Waiting interface 1 (0x200014e4) to be up... [00:00:00.580,718] <inf> net_config: IPv4 address: 192.168.1.1 [00:00:00.581,268] <inf> wpa_supp: Successfully initialized wpa_supplicant [00:00:00.582,122] <inf> softap: Regulatory domain set to IN [00:00:00.602,508] <inf> softap: DHCPv4 server started and pool address start from 192.168.1.2 [00:00:01.250,000] <inf> wpa_supp: wlan0: interface state UNINITIALIZED->ENABLED [00:00:01.250,061] <inf> wpa_supp: wlan0: AP-ENABLED [00:00:01.250,335] <inf> wpa_supp: wlan0: CTRL-EVENT-CONNECTED - Connection to nn:oo:rr:dd:ii:cc completed [id=0 id_str=] [00:00:01.254,608] <inf> softap: AP enable requested [00:00:01.256,225] <inf> softap: AP mode enabled [00:00:01.257,873] <inf> softap: Status: successful [00:00:01.257,904] <inf> softap: ================== [00:00:01.257,904] <inf> softap: State: COMPLETED [00:00:01.257,934] <inf> softap: Interface Mode: ACCESS POINT [00:00:01.257,965] <inf> softap: Link Mode: UNKNOWN [00:00:01.257,995] <inf> softap: SSID: MySoftAP [00:00:01.258,026] <inf> softap: BSSID: NN:OO:RR:DD:II:CC [00:00:01.258,026] <inf> softap: Band: 2.4GHz [00:00:01.258,056] <inf> softap: Channel: 6 [00:00:01.258,056] <inf> softap: Security: OPEN [00:00:01.258,087] <inf> softap: MFP: Disable [00:00:01.258,087] <inf> softap: Beacon Interval: 100 [00:00:01.258,087] <inf> softap: DTIM: 2 [00:00:01.258,117] <inf> softap: TWT: Not supported [00:00:01.341,674] <inf> net_config: IPv6 address: fe80::f6ce:36ff:fe00:10d4 [00:00:15.270,446] <inf> wpa_supp: HT: Forty MHz Intolerant is set by STA aa:bb:cc:dd:ee:ff in Association Request [00:00:15.286,376] <inf> wpa_supp: wlan0: AP-STA-CONNECTED aa:bb:cc:dd:ee:ff [00:00:15.286,529] <inf> softap: Station connected: AA:BB:CC:DD:EE:FF [00:00:15.286,529] <inf> softap: AP stations: [00:00:15.286,529] <inf> softap: ============ [00:00:15.286,560] <inf> softap: Station 1: [00:00:15.286,560] <inf> softap: ========== [00:00:15.286,590] <inf> softap: MAC: AA:BB:CC:DD:EE:FF [00:00:15.286,590] <inf> softap: Link mode: WIFI 4 (802.11n/HT) [00:00:15.286,621] <inf> softap: TWT: Not supported
Dependencies
This sample uses the following nRF Connect SDK libraries: