Skip to content

Commit 76374a8

Browse files
authored
Merge pull request #508 from espressif/basic_http_server
Sync Merge: basic_http_server
2 parents 5b223bd + dc00d6a commit 76374a8

File tree

7 files changed

+325
-30
lines changed

7 files changed

+325
-30
lines changed

content/blog/2025/04/soft-ap-tutorial/index.md

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ showAuthor: false
55
authors:
66
- francesco-bez
77
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."
99
---
1010

1111
### Introduction
@@ -35,18 +35,24 @@ For real-world applications, it is better to use a __robust__ provisioning solu
3535
{{< /alert >}}
3636

3737

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.
3939

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
4148

4249
- **menuconfig** - The tool which handles the configuration in ESP-IDF projects
43-
- **Logs** - A neat way to handle useful information during development
4450
- **Event loops** – A design pattern used throughout the Espressif ESP-IDF framework to simplify the management of complex applications.
4551
- **[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.
4652
- **[Non-volatile storage (NVS)](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/api-reference/storage/nvs_flash.html)** – For saving credentials
47-
<!--
48-
{{< alert icon="circle-info" cardColor="#b3e0f2" iconColor="#04a5e5" >}}
49-
The shortcuts mentioned below refer to VS Code, but you can use any IDE or any editor if compiling through the command line.
53+
54+
<!-- {{< alert icon="circle-info" cardColor="#b3e0f2" iconColor="#04a5e5" >}}
55+
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 `>` .
5056
{{< /alert >}} -->
5157

5258

@@ -57,11 +63,12 @@ Before starting this tutorial, ensure that you
5763
- 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.
5864
- 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.
5965
- 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.
6067

6168
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.
6269

6370

64-
## Create a new project
71+
## Starting a new project from `hello_world`
6572

6673
To start a new project and prepare for the following steps, we will perform these actions:
6774
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.
7683

7784
{{% tab name="VS Code extension" %}}
7885

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 `>`.
8087

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`
8697

8798

8899
{{% /tab %}}
@@ -98,7 +109,10 @@ If everything runs smoothly, we should see the compilation finish successfully,
98109

99110
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.
100111

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:
102116

103117
```c
104118
#include <stdio.h>
@@ -122,7 +136,7 @@ idf_component_register(SRCS "basic_http_server.c"
122136
123137
After making these changes:
124138
125-
- 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`
126140
- Build, flash and open a monitor again.
127141
128142
<!-- > [!WARNING]
@@ -132,14 +146,18 @@ After making these changes:
132146
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).
133147
{{< /alert >}}
134148
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.
136152
137153
By default, some configuration variables have NVS enabled, which may cause warnings or errors. To avoid this, we need to disable them in `menuconfig`.
138154
139155
140156
{{< tabs groupId="devtool" >}}
141157
{{% 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
143161
{{< figure
144162
default=true
145163
src="img/disable_nvs.webp"
@@ -153,15 +171,13 @@ To access `menuconfig`, call `idf.py menuconfig`
153171
{{% /tab %}}
154172
{{< /tabs >}}
155173
156-
157-
158174
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.
159175
160176
{{< github repo="FBEZ-docs-and-templates/devrel-tutorials-code" >}}
161177
162-
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
165181
166182
While not strictly necessary for this tutorial, logs are extremely useful when developing applications.
167183
@@ -190,7 +206,7 @@ In this tutorial, only `ESP_LOGI` (informational logs) will be used, but there a
190206
- `ESP_LOGD(TAG, "...")` – Debug logs
191207
- `ESP_LOGV(TAG, "...")` – Verbose logs
192208
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). -->
194210
195211
196212
## Starting the soft-AP
@@ -205,10 +221,9 @@ To set up a soft-AP, we will need to:
205221
We'll call `esp_event_loop_create_default()` to initialize the standard event loop.
206222
3. **Register handlers for soft-AP:**
207223
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.
210224
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.
212227
213228
For most applications, creating a default network with the default event loop is sufficient -- this is the approach used in this tutorial.
214229
@@ -308,7 +323,9 @@ void wifi_init_softap()
308323
}
309324
```
310325

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
312329

313330
At this point, the function handling Wi-Fi events is as follows:
314331

@@ -322,7 +339,7 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base,
322339
Now compile, flash, start a monitor and run the project. We should start seeing several event numbers appearing on the terminal.
323340
324341
325-
### Connect to the soft-AP with a Smartphone
342+
## Testing the Connection with a Smartphone
326343
327344
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!`.
328345
@@ -368,4 +385,8 @@ In this tutorial, you learned how to:
368385
4. Configure and launch a soft-AP, allowing devices to connect via Wi-Fi.
369386
5. Verify event handling by monitoring the terminal for connection events.
370387
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/)
507 KB
Loading
5.63 KB
Loading
6.53 KB
Loading
118 KB
Loading

0 commit comments

Comments
 (0)