-
Notifications
You must be signed in to change notification settings - Fork 169
Add new slave_wifi_rest_api example: REST Wi-Fi control based on original slave (IDFGH-16209) #860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
glarionenko
wants to merge
6
commits into
espressif:master
Choose a base branch
from
glarionenko:feature/new-eppp-example
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
628283e
Add REST Wi-Fi control example with web UI for eppp_link
glarionenko 12e7015
Update README with links to original and web panel docs
glarionenko 544e1df
Update README links for clarity and accuracy
glarionenko af4e921
Update README links in slave_wifi_rest_api example
glarionenko 1d79dc2
Update README title for clarity
glarionenko 48f4849
Update README.md
glarionenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
components/eppp_link/examples/slave_wifi_rest_api/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# The following five lines of boilerplate have to be in your project's | ||
# CMakeLists in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(pppos_slave) |
105 changes: 105 additions & 0 deletions
105
components/eppp_link/examples/slave_wifi_rest_api/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# ESP32 [eppp\_link/slave](../slave/) based Example – Modifications and REST Wi-Fi Control | ||
|
||
[See the original example here](../slave/) | ||
|
||
This document describes the key modifications and usage instructions for the enhanced [slave](../slave/) example, enabling REST-based Wi-Fi configuration and monitoring. | ||
|
||
--- | ||
|
||
## Overview | ||
|
||
This version extends the original [slave](../slave/) PPP example with a full-featured REST API for Wi-Fi management. All new functionality is backward compatible; Wi-Fi can still be set via Kconfig, but runtime control is now possible from your browser or scripts. | ||
|
||
--- | ||
|
||
## Key Changes | ||
|
||
### 1. REST API for Wi-Fi | ||
|
||
* Added HTTP server (`esp_http_server`) and JSON parsing (`cJSON`). | ||
* REST endpoints: | ||
|
||
* `GET /wifi/status` — current status (connected/disconnected, SSID, RSSI). | ||
* `GET /wifi/scan` — scan available Wi-Fi networks. | ||
* `POST /wifi/connect` — connect to network (JSON: `{ "ssid": ..., "password": ... }`). | ||
* `POST /wifi/disconnect` — disconnect from Wi-Fi. | ||
* `OPTIONS /*` — CORS preflight for all URIs. | ||
|
||
### 2. Dynamic Wi-Fi Reconfiguration | ||
|
||
* Supports runtime change of Wi-Fi credentials without reboot or reflash. | ||
* Connect/disconnect sequence is carefully synchronized using event groups for stability. | ||
* If no default SSID is set, the device waits for configuration via REST. | ||
|
||
### 3. Event Management Improvements | ||
|
||
* Uses EventGroup bits to distinguish connection, failure, and disconnection events. | ||
* Manual reconnect flag to suppress auto-retry logic during REST-initiated reconnects. | ||
|
||
### 4. CORS Support | ||
|
||
* All REST responses include `Access-Control-Allow-Origin: *` for easy browser access. | ||
|
||
--- | ||
|
||
## How to Use | ||
|
||
### Build & Flash | ||
|
||
* Add `esp_http_server` and `cJSON` to your project. | ||
* Build and flash as usual with ESP-IDF. | ||
|
||
### Default Startup | ||
|
||
* If Wi-Fi SSID and password are set in `sdkconfig`, ESP32 tries to connect at startup. | ||
* If no SSID set, device waits for Wi-Fi config from REST client. | ||
|
||
### REST API Usage | ||
|
||
Interact from browser, curl, or your own UI: | ||
|
||
* **Get status:** | ||
|
||
```bash | ||
curl http://<esp32_ip>/wifi/status | ||
``` | ||
* **Scan networks:** | ||
|
||
```bash | ||
curl http://<esp32_ip>/wifi/scan | ||
``` | ||
* **Connect:** | ||
|
||
```bash | ||
curl -X POST http://<esp32_ip>/wifi/connect -H "Content-Type: application/json" -d '{"ssid":"YOUR_SSID","password":"YOUR_PASS"}' | ||
``` | ||
* **Disconnect:** | ||
|
||
```bash | ||
curl -X POST http://<esp32_ip>/wifi/disconnect | ||
``` | ||
|
||
> See [Web panel](webPanel/) for a ready-to-use web UI! | ||
|
||
--- | ||
|
||
## Implementation Notes | ||
|
||
* All Wi-Fi connect/disconnect operations are handled asynchronously and robustly. | ||
* If REST connect/disconnect is called in the middle of another operation, API will wait for proper sequence. | ||
* All actions are CORS-enabled for direct use from web apps. | ||
* Wi-Fi scan returns SSID, RSSI, and auth mode for each visible AP (max 16). | ||
|
||
--- | ||
|
||
## Example: Integrating with Your UI | ||
|
||
You can use the provided web UI ([See documentation for the web panel](webPanel/README.md) | ||
) or integrate these endpoints into any admin dashboard, mobile app, or automation script. | ||
|
||
--- | ||
|
||
## Credits | ||
|
||
* Enhanced by \glarionenko, \2025 | ||
* Based on original code © 2023-2025 Espressif Systems (Shanghai) CO LTD |
10 changes: 10 additions & 0 deletions
10
components/eppp_link/examples/slave_wifi_rest_api/main/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
if(CONFIG_EXAMPLE_WIFI_OVER_EPPP_CHANNEL) | ||
set(wifi_over_channels channel_wifi_station.c) | ||
endif() | ||
|
||
idf_component_register( | ||
SRCS eppp_slave.c | ||
${wifi_over_channels} | ||
INCLUDE_DIRS "." | ||
REQUIRES json esp_wifi nvs_flash esp_http_server | ||
) |
111 changes: 111 additions & 0 deletions
111
components/eppp_link/examples/slave_wifi_rest_api/main/Kconfig.projbuild
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
menu "Example Configuration" | ||
|
||
config ESP_WIFI_SSID | ||
string "WiFi SSID" | ||
default "myssid" | ||
help | ||
SSID (network name) for the example to connect to. | ||
|
||
config ESP_WIFI_PASSWORD | ||
string "WiFi Password" | ||
default "mypassword" | ||
help | ||
WiFi password (WPA or WPA2) for the example to use. | ||
|
||
config ESP_MAXIMUM_RETRY | ||
int "Maximum retry" | ||
default 5 | ||
help | ||
Set the Maximum retry to avoid station reconnecting to the AP unlimited when the AP is really inexistent. | ||
|
||
config EXAMPLE_SPI_HOST | ||
int "SPI Host" | ||
depends on EPPP_LINK_DEVICE_SPI | ||
default 1 | ||
range 0 2 | ||
help | ||
SPI host to use (SPI1_HOST=0, SPI2_HOST=1, SPI3_HOST=2). | ||
|
||
config EXAMPLE_SPI_MOSI_PIN | ||
int "MOSI Pin Number" | ||
depends on EPPP_LINK_DEVICE_SPI | ||
default 23 | ||
range 0 39 | ||
help | ||
Pin number of SPI MOSI. | ||
|
||
config EXAMPLE_SPI_MISO_PIN | ||
int "MISO Pin Number" | ||
depends on EPPP_LINK_DEVICE_SPI | ||
default 19 | ||
range 0 39 | ||
help | ||
Pin number of SPI MISO. | ||
|
||
config EXAMPLE_SPI_SCLK_PIN | ||
int "SCLK Pin Number" | ||
depends on EPPP_LINK_DEVICE_SPI | ||
default 18 | ||
range 0 39 | ||
help | ||
Pin number of SPI SCLK. | ||
|
||
config EXAMPLE_SPI_CS_PIN | ||
int "CS Pin Number" | ||
depends on EPPP_LINK_DEVICE_SPI | ||
default 5 | ||
range 0 39 | ||
help | ||
Pin number of SPI CS. | ||
|
||
config EXAMPLE_SPI_INTR_PIN | ||
int "Interrupt Pin Number" | ||
depends on EPPP_LINK_DEVICE_SPI | ||
default 17 | ||
range 0 39 | ||
help | ||
Pin number of SPI interrupt. | ||
|
||
config EXAMPLE_SPI_FREQUENCY | ||
int "SPI Frequency (Hz)" | ||
depends on EPPP_LINK_DEVICE_SPI | ||
default 1000000 | ||
range 100000 80000000 | ||
help | ||
SPI frequency in Hz. | ||
|
||
config EXAMPLE_UART_TX_PIN | ||
int "TXD Pin Number" | ||
depends on EPPP_LINK_DEVICE_UART | ||
default 18 | ||
range 0 31 | ||
help | ||
Pin number of UART TX. | ||
|
||
config EXAMPLE_UART_RX_PIN | ||
int "RXD Pin Number" | ||
depends on EPPP_LINK_DEVICE_UART | ||
default 17 | ||
range 0 31 | ||
help | ||
Pin number of UART RX. | ||
|
||
config EXAMPLE_UART_BAUDRATE | ||
int "Baudrate" | ||
depends on EPPP_LINK_DEVICE_UART | ||
default 921600 | ||
range 0 4000000 | ||
help | ||
Baudrate used by the PPP over UART | ||
|
||
config EXAMPLE_WIFI_OVER_EPPP_CHANNEL | ||
bool "Use WiFi over EPPP channel" | ||
default n | ||
depends on EPPP_LINK_CHANNELS_SUPPORT | ||
help | ||
Enable this option to use WiFi over EPPP channel. | ||
If this option is enabled, the example will only start the Wi-Fi driver, | ||
but the Wi-Fi netif will reside on client's end and will channel | ||
the Rx and Tx data via EPPP channels. | ||
|
||
endmenu |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest removing this option in this example (just to simplify it and focus on what's important)
channel_wifi_station.c