You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/blog/2025/04/soft-ap-tutorial/index.md
+51-30Lines changed: 51 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ showAuthor: false
5
5
authors:
6
6
- francesco-bez
7
7
tags: [soft-AP, ESP32-C3, ESP-IDF]
8
-
summary: "This tutorial guides you through setting up a soft-AP using an Espressif module and ESP-IDF. It covers the process of creating a project, configuring Wi-Fi, and handling connection events through event loops and logging. Upon completion, you’ll be able to establish a soft-AP and manage Wi-Fi connections. It is the first step to building more advanced networking applications."
8
+
summary: "This tutorial guides you through setting up a soft-AP using an Espressif module and ESP-IDF. It covers the process of creating a project, configuring Wi-Fi, and handling connection events through event loops. Upon completion, you’ll be able to establish a soft-AP and manage Wi-Fi connections. It is the first step to building more advanced networking applications."
9
9
---
10
10
11
11
### Introduction
@@ -35,18 +35,24 @@ For real-world applications, it is better to use a __robust__ provisioning solu
35
35
{{< /alert >}}
36
36
37
37
38
-
This tutorial serves as a foundation for other Wi-Fi connectivity applications, ensuring a smooth and reliable connection setup.
38
+
This tutorial lays the groundwork for building more advanced Wi-Fi connectivity applications by ensuring a smooth and reliable connection setup.
39
39
40
-
We will first create a new project, include the necessary libraries, and catch the Wi-Fi events. Here we will also encounter
40
+
In the steps that follow, we will:
41
+
42
+
1. Create a new project based on the `hello_world` example.
43
+
2. Rename the project and remove any unnecessary libraries and configurations.
44
+
3. Start the Soft-AP and set up handlers to manage Wi-Fi events.
45
+
4. Verify the connection using your smartphone
46
+
47
+
In this tutorial, we will also encounter
41
48
42
49
-**menuconfig** - The tool which handles the configuration in ESP-IDF projects
43
-
-**Logs** - A neat way to handle useful information during development
44
50
-**Event loops** – A design pattern used throughout the Espressif ESP-IDF framework to simplify the management of complex applications.
45
51
-**[esp-netif](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/api-reference/network/esp_netif.html)** – Espressif's abstraction layer for TCP/IP networking.
46
52
-**[Non-volatile storage (NVS)](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/api-reference/storage/nvs_flash.html)** – For saving credentials
Most commands in VSCode are executed through the Command Palette, which you can open by pressing `CTRL+SHIFT+P` (or `CMD+SHIFT+P` if you’re on mac-os). In this guide, commands to enter in the Command Palette are marked with the symbol `>` .
50
56
{{< /alert >}} -->
51
57
52
58
@@ -57,11 +63,12 @@ Before starting this tutorial, ensure that you
57
63
- Can compile and flash the [`hello_world`](https://github.com/espressif/esp-idf/tree/master/examples/get-started/hello_world) example. Two main methods followed below are using `idf.py` directly (CLI approach) or using the VS Code ESP-IDF Extension. If required, you can follow the instructions in the [ESP-IDF Getting Started](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/get-started/index.html) guide.
58
64
- Have an Espressif evaluation board or another compatible board for flashing the code. In this tutorial we will use the [ESP32-C3-DevkitM-1](https://docs.espressif.com/projects/esp-dev-kits/en/latest/esp32c3/esp32-c3-devkitm-1/user_guide.html) but any Espressif evaluation board will work just as well. If you built your own board, you might need an [ESP-PROG](https://docs.espressif.com/projects/esp-iot-solution/en/latest/hw-reference/ESP-Prog_guide.html) programmer.
59
65
- Understand the difference between a Wi-Fi access point and a Wi-Fi station.
66
+
- (Optional) Have a basic knowledge of the [logging system](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/log.html#how-to-use-logging-library) in Espressif.
60
67
61
68
If you're not quite comfortable with any of the above steps yet, consider checking out the [ESP-IDF with ESP32-C6 Workshop](https://preview-developer.espressif.com/pr404/workshops/esp-idf-with-esp32-c6/). These resources can help you get hands-on experience with setup, flashing, and basic debugging before diving into this tutorial.
62
69
63
70
64
-
## Create a new project
71
+
## Starting a new project from `hello_world`
65
72
66
73
To start a new project and prepare for the following steps, we will perform these actions:
67
74
1. Create a new project using the [`hello_world`](https://github.com/espressif/esp-idf/tree/master/examples/get-started/hello_world) example as a starting point.
@@ -76,13 +83,17 @@ Below you can find a refresher for VS Code and using the CLI.
76
83
77
84
{{% tab name="VS Code extension" %}}
78
85
79
-
Open VS Code, press `CTRL+SHIFT+P`and start typing `ESP-IDF: New Project`. Follow the instructions to create a new project using the `hello_world` as a template.
86
+
Most commands in VSCode are executed through the Command Palette, which you can open by pressing `CTRL+SHIFT+P` (or `CMD+SHIFT+P` if you’re on mac-os). In the following, commands to enter in the Command Palette are marked with the symbol `>`.
80
87
81
-
Next, we need to set the target and port for the flashing stage. In this tutorial, we're using an `ESP32-C3-DevKitM-1`.
82
-
Start typing `ESP-IDF: Set Espressif Device Target` and select `esp32c3`. If you are using an evaluation board or a USB-UART bridge, select `The ESP32-C3 Chip via builtin USB-JTAG`. If you're using one of the `ESP-PROG` programmers, choose the most appropriate option.
83
-
84
-
Next, select the correct port by typing `ESP-IDF: Select Port to Use (COM, tty, usbserial)`.
85
-
At this point, we can run the command `ESP-IDF: Build, Flash and start a Monitor on your device`.
88
+
*`> ESP-IDF: New Project`
89
+
_Follow the instructions to create a new project using the `hello_world` as a template_
90
+
*`> ESP-IDF: Set Espressif Device Target`
91
+
_Choose your SoC. In this tutorial we use `esp32c3`_
92
+
*_If you are using an evaluation board or a USB-UART bridge, select `The ESP32-C3 Chip via builtin USB-JTAG`_
93
+
*_If you're using one of the `ESP-PROG` programmers, choose the most appropriate option._
94
+
*`> ESP-IDF: Select Port to Use (COM, tty, usbserial)`
95
+
_Choose the port assigned to the board. Check with your os device manager if unsure_
96
+
*`> ESP-IDF: Build, Flash and start a Monitor on your device`
86
97
87
98
88
99
{{% /tab %}}
@@ -98,7 +109,10 @@ If everything runs smoothly, we should see the compilation finish successfully,
98
109
99
110
We have just compiled the code and flashed it onto the internal flash memory of the Espressif module. On boot, the module now runs the `hello_world` example, sending a 'Hello, World' message to the serial port (connected to the programmer), along with a countdown until the module restarts. This step ensures that the entire process is working correctly. Now, we can begin modifying the code to implement the soft-AP.
100
111
101
-
Now, update the content of `hello_world_main.c` to the following code:
112
+
## Renaming the Project and Cleaning Up
113
+
114
+
Now, we will rename the project and remove all the necessary commands and library.
115
+
Update the content of `hello_world_main.c` to the following code:
- Perform a full clean: Run `ESP-IDF: Full Clean Project`
139
+
- Perform a full clean: Run in the command palette `ESP-IDF: Full Clean Project`
126
140
- Build, flash and open a monitor again.
127
141
128
142
<!-- > [!WARNING]
@@ -132,14 +146,18 @@ After making these changes:
132
146
Every time you change the CMakeLists.txt, you need to perform a full clean to see the changes take effect. To learn more about the build system, consult the document [Build System](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/build-system.html#minimal-component-cmakelists).
133
147
{{< /alert >}}
134
148
135
-
Now we need to complete the final step before moving on. To keep things as simple as possible, in this tutorial we will not use Non-Volatile Storage (NVS), which is commonly used with Wi-Fi to store credentials and access calibration data.
149
+
### Disable NVS
150
+
151
+
To keep things as simple as possible, in this tutorial we will not use Non-Volatile Storage (NVS), which is commonly used with Wi-Fi to store credentials and access calibration data under the hood.
136
152
137
153
By default, some configuration variables have NVS enabled, which may cause warnings or errors. To avoid this, we need to disable them in `menuconfig`.
138
154
139
155
140
156
{{< tabs groupId="devtool" >}}
141
157
{{% tab name="VS Code extension" %}}
142
-
To access `menuconfig`, press `CTRL+SHIFT+P`, type `ESP-IDF: SDK Configuration Editor` and select it. In the search bar type `NVS` then uncheck the following options
158
+
To access `menuconfig`, type `ESP-IDF: SDK Configuration Editor` in the command palette and hit <kbd>Enter</kbd>.
159
+
160
+
In the `menuconfig` search bar type `NVS` then uncheck the following options
143
161
{{< figure
144
162
default=true
145
163
src="img/disable_nvs.webp"
@@ -153,15 +171,13 @@ To access `menuconfig`, call `idf.py menuconfig`
153
171
{{% /tab %}}
154
172
{{< /tabs >}}
155
173
156
-
157
-
158
174
Now your project should resemble the [bare-minimum example](https://github.com/FBEZ-docs-and-templates/devrel-tutorials-code/tree/main/tutorial-basic-project) in the repository below.
After a quick look at how logs are managed in Espressif, we can start with the soft-AP.
163
-
164
-
## A short detour: Logs
178
+
<!-- After a quick look at how logs are managed in Espressif, we can start with the soft-AP. -->
179
+
180
+
<!-- ## A short detour: Logs
165
181
166
182
While not strictly necessary for this tutorial, logs are extremely useful when developing applications.
167
183
@@ -190,7 +206,7 @@ In this tutorial, only `ESP_LOGI` (informational logs) will be used, but there a
190
206
- `ESP_LOGD(TAG, "...")` – Debug logs
191
207
- `ESP_LOGV(TAG, "...")` – Verbose logs
192
208
193
-
For a detailed explanation of logging functions, refer to the [official documentation](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/log.html).
209
+
For a detailed explanation of logging functions, refer to the [official documentation](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/log.html). -->
194
210
195
211
196
212
## Starting the soft-AP
@@ -205,10 +221,9 @@ To set up a soft-AP, we will need to:
205
221
We'll call `esp_event_loop_create_default()` to initialize the standard event loop.
206
222
3. **Register handlers for soft-AP:**
207
223
We'll register the event handlers needed for a soft-AP application.
208
-
4. **Connect to the soft-AP with a Smartphone:**
209
-
We'll check the connection using a smartphone and connecting to the soft-AP.
210
224
211
-
Espressif IP stack is managed through an unified interface called [`esp_netif`](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/network/esp_netif.html#esp-netif). This interface was designed to provide an agnostic abstraction for different IP stacks. Currently, the only TCP/IP stack available through this interface is lwIP.
225
+
226
+
Espressif IP stack is managed through the unified interface called [`esp_netif`](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/network/esp_netif.html#esp-netif). This interface was designed to provide an agnostic abstraction for different IP stacks. Currently, the only TCP/IP stack available through this interface is lwIP.
212
227
213
228
For most applications, creating a default network with the default event loop is sufficient -- this is the approach used in this tutorial.
214
229
@@ -308,7 +323,9 @@ void wifi_init_softap()
308
323
}
309
324
```
310
325
311
-
### Register handlers for soft-AP
326
+
`ESP_LOGI` is a logging command which prints an information message on the terminal. If you're unsure about it, check the [logging library documentation](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/log.html#how-to-use-logging-library).
327
+
328
+
### Handle Wi-Fi Events
312
329
313
330
At this point, the function handling Wi-Fi events is as follows:
Now compile, flash, start a monitor and run the project. We should start seeing several event numbers appearing on the terminal.
323
340
324
341
325
-
### Connect to the soft-AP with a Smartphone
342
+
## Testing the Connection with a Smartphone
326
343
327
344
At this point, take your smartphone, open the Wi-Fi list, and select the SSID `esp_tutorial`. When we do so, we should see on the terminal `Event nr: 14!`.
328
345
@@ -368,4 +385,8 @@ In this tutorial, you learned how to:
368
385
4. Configure and launch a soft-AP, allowing devices to connect via Wi-Fi.
369
386
5. Verify event handling by monitoring the terminal for connection events.
370
387
371
-
This serves as a foundation for building more advanced Wi-Fi applications, such as MQTT clients, HTTP servers, or other networked solutions.
388
+
This serves as a foundation for building more advanced Wi-Fi applications, such as MQTT clients, HTTP servers, or other networked solutions.
389
+
390
+
### Next step
391
+
392
+
> _Next Step_: Check the [basic http tutorial](/blog/2025/06/basic_http_server/)
0 commit comments