|
| 1 | +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-S2 | ESP32-S3 | |
| 2 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | |
| 3 | + |
| 4 | +# Wi-Fi SoftAP & Station Example |
| 5 | + |
| 6 | +(See the README.md file in the upper level 'examples' directory for more information about examples.) |
| 7 | + |
| 8 | +This example demonstrates how to use the ESP Wi-Fi driver to act as both an Access Point and a Station simultaneously using the SoftAP and Station features. |
| 9 | +With NAPT enabled on the softAP interface and the station interface set as the defaut interface this example can be used as Wifi nat router. |
| 10 | + |
| 11 | +## How to use example |
| 12 | +### Configure the project |
| 13 | + |
| 14 | +Open the project configuration menu (`idf.py menuconfig`). |
| 15 | + |
| 16 | +In the `Example Configuration` menu: |
| 17 | + |
| 18 | +* Set the Wi-Fi SoftAP configuration. |
| 19 | + * Set `WiFi AP SSID`. |
| 20 | + * Set `WiFi AP Password`. |
| 21 | + |
| 22 | +* Set the Wi-Fi STA configuration. |
| 23 | + * Set `WiFi Remote AP SSID`. |
| 24 | + * Set `WiFi Remote AP Password`. |
| 25 | + |
| 26 | +Optional: If necessary, modify the other choices to suit your needs. |
| 27 | + |
| 28 | +### Build and Flash |
| 29 | + |
| 30 | +Build the project and flash it to the board, then run the monitor tool to view the serial output: |
| 31 | + |
| 32 | +Run `idf.py -p PORT flash monitor` to build, flash and monitor the project. |
| 33 | + |
| 34 | +(To exit the serial monitor, type ``Ctrl-]``.) |
| 35 | + |
| 36 | +## Example Output |
| 37 | + |
| 38 | +There is the console output for this example: |
| 39 | + |
| 40 | +``` |
| 41 | +I (680) WiFi SoftAP: ESP_WIFI_MODE_AP |
| 42 | +I (690) WiFi SoftAP: wifi_init_softap finished. SSID:myssid password:mypassword channel:1 |
| 43 | +I (690) WiFi Sta: ESP_WIFI_MODE_STA |
| 44 | +I (690) WiFi Sta: wifi_init_sta finished. |
| 45 | +I (700) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07 |
| 46 | +I (800) wifi:mode : sta (58:bf:25:e0:41:00) + softAP (58:bf:25:e0:41:01) |
| 47 | +I (800) wifi:enable tsf |
| 48 | +I (810) wifi:Total power save buffer number: 16 |
| 49 | +I (810) wifi:Init max length of beacon: 752/752 |
| 50 | +I (810) wifi:Init max length of beacon: 752/752 |
| 51 | +I (820) WiFi Sta: Station started |
| 52 | +I (820) wifi:new:<1,1>, old:<1,1>, ap:<1,1>, sta:<1,1>, prof:1 |
| 53 | +I (820) wifi:state: init -> auth (b0) |
| 54 | +I (830) wifi:state: auth -> assoc (0) |
| 55 | +E (840) wifi:Association refused temporarily, comeback time 1536 mSec |
| 56 | +I (2380) wifi:state: assoc -> assoc (0) |
| 57 | +I (2390) wifi:state: assoc -> run (10) |
| 58 | +I (2400) wifi:connected with myssid_c3, aid = 1, channel 1, 40U, bssid = 84:f7:03:60:86:1d |
| 59 | +I (2400) wifi:security: WPA2-PSK, phy: bgn, rssi: -14 |
| 60 | +I (2410) wifi:pm start, type: 1 |
| 61 | +
|
| 62 | +I (2410) wifi:AP's beacon interval = 102400 us, DTIM period = 2 |
| 63 | +I (3920) WiFi Sta: Got IP:192.168.5.2 |
| 64 | +I (3920) esp_netif_handlers: sta ip: 192.168.5.2, mask: 255.255.255.0, gw: 192.168.5.1 |
| 65 | +I (3920) WiFi Sta: connected to ap SSID:myssid_c3 password:mypassword_c3 |
| 66 | +``` |
| 67 | + |
| 68 | +## Troubleshooting |
| 69 | + |
| 70 | +For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon. |
0 commit comments