1.. zephyr:code-sample:: wifi-ap-sta-mode
2   :name: Wi-Fi AP-STA mode
3   :relevant-api: wifi_mgmt dhcpv4_server
4
5   Configure a Wi-Fi board to operate as both an Access Point (AP) and a Station (STA).
6
7Overview
8********
9
10The Wi-Fi AP-STA mode of a Wi-Fi board allows it to function as both
11an Access Point (AP) and a Station (STA) simultaneously.
12This sample demonstrates how to configure and utilize AP-STA mode.
13
14Configuration and usage of following interfaces is shown in sample.
15
161. ``AP mode``: AP mode is configured and enabled. DHCPv4 server is also
17   configured to assign IP addresses to the joining station.
182. ``STA mode``: Provide the SSID and PSK of you router
19
20In this demo, AP-STA mode is enabled using :kconfig:option:`CONFIG_ESP32_WIFI_AP_STA_MODE`.
21An additional Wi-Fi node is added in the ``.overlay`` file. The ``net_if``.
22In the sample code, initially, the AP mode is enabled, followed by enabling the STA mode.
23The driver checks if AP mode was previously enabled. If so, it transitions
24the board into AP-STA mode to support both modes and attempts to connect to the
25AP specified by the provided SSID and PSK.
26
27Requirements
28************
29
30This example should be able to run on any commonly available
31:zephyr:board:`esp32_devkitc_wroom` development board without any extra hardware.
32
33To enable or disable ``AP-STA`` mode, modify the :kconfig:option:`CONFIG_ESP32_WIFI_AP_STA_MODE`
34parameter in the ``boards/esp32_devkitc_wroom_procpu.conf`` file of the demo. Moreover, an
35extra Wi-Fi node is included in ``boards/esp32_devkitc_wroom_procpu.overlay``.
36
37By default, AP-STA mode is disabled.
38
39Building, Flashing and Running
40******************************
41
42.. zephyr-app-commands::
43   :zephyr-app: samples/boards/espressif/deep_sleep
44   :board: esp32_devkitc_wroom/esp32/procpu
45   :goals: build flash
46   :compact:
47
48Sample Output
49=================
50
51.. code-block:: console
52
53   *** Booting Zephyr OS build v3.7.0-rc3-104-gd1e5c5b3f9b7 ***
54   [00:00:05.171,000] <inf> MAIN: Turning on AP Mode
55   [00:00:05.172,000] <dbg> net_dhcpv4_server: net_dhcpv4_server_start: Started DHCPv4 server, address pool:
56   [00:00:05.172,000] <dbg> net_dhcpv4_server: net_dhcpv4_server_start:     0: 192.168.4.11
57   [00:00:05.172,000] <dbg> net_dhcpv4_server: net_dhcpv4_server_start:     1: 192.168.4.12
58   [00:00:05.172,000] <dbg> net_dhcpv4_server: net_dhcpv4_server_start:     2: 192.168.4.13
59   [00:00:05.172,000] <dbg> net_dhcpv4_server: net_dhcpv4_server_start:     3: 192.168.4.14
60   [00:00:05.172,000] <inf> MAIN: DHCPv4 server started...
61
62   [00:00:05.350,000] <inf> MAIN: AP Mode is enabled. Waiting for sta to connect ESP32-AP
63   [00:00:05.350,000] <inf> MAIN: Connecting to SSID: ZIN-Dummy
64
65   [00:00:09.498,000] <inf> net_dhcpv4: Received: 192.168.43.44
66   [00:00:09.499,000] <inf> MAIN: Connected to ZIN-Dummy
67   [00:00:32.739,000] <inf> MAIN: station: 7C:50:79:17:89:19 joined
68   [00:00:32.832,000] <dbg> net_dhcpv4_server: dhcpv4_handle_discover: DHCPv4 processing Discover - reserved 192.168.4.11
69   [00:00:33.839,000] <dbg> net_dhcpv4_server: dhcpv4_handle_request: DHCPv4 processing Request - allocated 192.168.4.11
70