1# Wi-Fi Station Example 2 3(See the README.md file in the upper level 'examples' directory for more information about examples.) 4 5This example shows how to use the Wi-Fi Station functionality of the Wi-Fi driver of ESP for connecting to an Access Point. 6 7## How to use example 8 9### Configure the project 10 11Open the project configuration menu (`idf.py menuconfig`). 12 13In the `Example Configuration` menu: 14 15* Set the Wi-Fi configuration. 16 * Set `WiFi SSID`. 17 * Set `WiFi Password`. 18 19Optional: If you need, change the other options according to your requirements. 20 21### Build and Flash 22 23Build the project and flash it to the board, then run the monitor tool to view the serial output: 24 25Run `idf.py -p PORT flash monitor` to build, flash and monitor the project. 26 27(To exit the serial monitor, type ``Ctrl-]``.) 28 29See the Getting Started Guide for all the steps to configure and use the ESP-IDF to build projects. 30 31* [ESP-IDF Getting Started Guide on ESP32](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html) 32* [ESP-IDF Getting Started Guide on ESP32-S2](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/get-started/index.html) 33* [ESP-IDF Getting Started Guide on ESP32-C3](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/get-started/index.html) 34 35## Example Output 36Note that the output, in particular the order of the output, may vary depending on the environment. 37 38Console output if station connects to AP successfully: 39``` 40I (589) wifi station: ESP_WIFI_MODE_STA 41I (599) wifi: wifi driver task: 3ffc08b4, prio:23, stack:3584, core=0 42I (599) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE 43I (599) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE 44I (629) wifi: wifi firmware version: 2d94f02 45I (629) wifi: config NVS flash: enabled 46I (629) wifi: config nano formating: disabled 47I (629) wifi: Init dynamic tx buffer num: 32 48I (629) wifi: Init data frame dynamic rx buffer num: 32 49I (639) wifi: Init management frame dynamic rx buffer num: 32 50I (639) wifi: Init management short buffer num: 32 51I (649) wifi: Init static rx buffer size: 1600 52I (649) wifi: Init static rx buffer num: 10 53I (659) wifi: Init dynamic rx buffer num: 32 54I (759) phy: phy_version: 4180, cb3948e, Sep 12 2019, 16:39:13, 0, 0 55I (769) wifi: mode : sta (30:ae:a4:d9:bc:c4) 56I (769) wifi station: wifi_init_sta finished. 57I (889) wifi: new:<6,0>, old:<1,0>, ap:<255,255>, sta:<6,0>, prof:1 58I (889) wifi: state: init -> auth (b0) 59I (899) wifi: state: auth -> assoc (0) 60I (909) wifi: state: assoc -> run (10) 61I (939) wifi: connected with #!/bin/test, aid = 1, channel 6, BW20, bssid = ac:9e:17:7e:31:40 62I (939) wifi: security type: 3, phy: bgn, rssi: -68 63I (949) wifi: pm start, type: 1 64 65I (1029) wifi: AP's beacon interval = 102400 us, DTIM period = 3 66I (2089) esp_netif_handlers: sta ip: 192.168.77.89, mask: 255.255.255.0, gw: 192.168.77.1 67I (2089) wifi station: got ip:192.168.77.89 68I (2089) wifi station: connected to ap SSID:myssid password:mypassword 69``` 70 71Console output if the station failed to connect to AP: 72``` 73I (589) wifi station: ESP_WIFI_MODE_STA 74I (599) wifi: wifi driver task: 3ffc08b4, prio:23, stack:3584, core=0 75I (599) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE 76I (599) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE 77I (629) wifi: wifi firmware version: 2d94f02 78I (629) wifi: config NVS flash: enabled 79I (629) wifi: config nano formating: disabled 80I (629) wifi: Init dynamic tx buffer num: 32 81I (629) wifi: Init data frame dynamic rx buffer num: 32 82I (639) wifi: Init management frame dynamic rx buffer num: 32 83I (639) wifi: Init management short buffer num: 32 84I (649) wifi: Init static rx buffer size: 1600 85I (649) wifi: Init static rx buffer num: 10 86I (659) wifi: Init dynamic rx buffer num: 32 87I (759) phy: phy_version: 4180, cb3948e, Sep 12 2019, 16:39:13, 0, 0 88I (759) wifi: mode : sta (30:ae:a4:d9:bc:c4) 89I (769) wifi station: wifi_init_sta finished. 90I (889) wifi: new:<6,0>, old:<1,0>, ap:<255,255>, sta:<6,0>, prof:1 91I (889) wifi: state: init -> auth (b0) 92I (1889) wifi: state: auth -> init (200) 93I (1889) wifi: new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1 94I (1889) wifi station: retry to connect to the AP 95I (1899) wifi station: connect to the AP fail 96I (3949) wifi station: retry to connect to the AP 97I (3949) wifi station: connect to the AP fail 98I (4069) wifi: new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1 99I (4069) wifi: state: init -> auth (b0) 100I (5069) wifi: state: auth -> init (200) 101I (5069) wifi: new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1 102I (5069) wifi station: retry to connect to the AP 103I (5069) wifi station: connect to the AP fail 104I (7129) wifi station: retry to connect to the AP 105I (7129) wifi station: connect to the AP fail 106I (7249) wifi: new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1 107I (7249) wifi: state: init -> auth (b0) 108I (8249) wifi: state: auth -> init (200) 109I (8249) wifi: new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1 110I (8249) wifi station: retry to connect to the AP 111I (8249) wifi station: connect to the AP fail 112I (10299) wifi station: connect to the AP fail 113I (10299) wifi station: Failed to connect to SSID:myssid, password:mypassword 114``` 115 116## Troubleshooting 117 118For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon. 119