Skip to content

Commit f2a2a4c

Browse files
me-no-devmathieucarbou
authored andcommitted
Add integration for IDF Component Manager
1 parent cd3194d commit f2a2a4c

20 files changed

+491
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Publish ESP-IDF Component
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: 'Component version (1.2.3, 1.2.3-rc1 or 1.2.3.4)'
8+
required: true
9+
git_ref:
10+
description: 'Git ref with the source (branch, tag or commit)'
11+
required: true
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
upload_components:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Get the release tag
21+
env:
22+
head_branch: ${{ inputs.tag || github.event.workflow_run.head_branch }}
23+
run: |
24+
# Read and sanitize the branch/tag name
25+
branch=$(echo "$head_branch" | tr -cd '[:alnum:]/_.-')
26+
27+
if [[ $branch == refs/tags/* ]]; then
28+
tag="${branch#refs/tags/}"
29+
elif [[ $branch =~ ^[v]*[0-9]+\.[0-9]+\.[0-9]+.*$ ]]; then
30+
tag=$branch
31+
else
32+
echo "Tag not found in $branch. Exiting..."
33+
exit 1
34+
fi
35+
36+
echo "Tag: $tag"
37+
echo "RELEASE_TAG=$tag" >> $GITHUB_ENV
38+
39+
- uses: actions/checkout@v4
40+
with:
41+
ref: ${{ inputs.git_ref || env.RELEASE_TAG }}
42+
submodules: "recursive"
43+
44+
- name: Upload components to the component registry
45+
uses: espressif/upload-components-ci-action@v1
46+
with:
47+
name: espasyncwebserver
48+
version: ${{ env.RELEASE_TAG }}
49+
namespace: esp32async
50+
api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }}

idf_component.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
description: "Async Web Server for ESP32 Arduino"
2+
url: "https://github.com/ESP32Async/ESPAsyncWebServer"
3+
license: "LGPL-3.0-or-later"
4+
tags:
5+
- arduino
6+
files:
7+
exclude:
8+
- "idf_component_examples/"
9+
- "idf_component_examples/**/*"
10+
- "examples/"
11+
- "examples/**/*"
12+
- ".gitignore"
13+
- ".clang-format"
14+
- ".gitpod.Dockerfile"
15+
- ".gitpod.yml"
16+
- ".codespellrc"
17+
- ".editorconfig"
18+
- ".pre-commit-config.yaml"
19+
- "CODE_OF_CONDUCT.md"
20+
- "library.json"
21+
- "library.properties"
22+
- "partitions-4MB.csv"
23+
- "platformio.ini"
24+
- "pre-commit.requirements.txt"
25+
dependencies:
26+
esp32async/asynctcp:
27+
version: "^3.3.5"
28+
require: public
29+
examples:
30+
- path: ./idf_component_examples/catchall
31+
- path: ./idf_component_examples/serversentevents
32+
- path: ./idf_component_examples/websocket
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# For more information about build system see
2+
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
3+
# The following five lines of boilerplate have to be in your project's
4+
# CMakeLists in this exact order for cmake to work correctly
5+
cmake_minimum_required(VERSION 3.16)
6+
7+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
8+
project(main)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
### Basic example to show how to catch all requests and send a 404 Not Found response
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
idf_component_register(SRCS "main.cpp"
2+
INCLUDE_DIRS ".")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## IDF Component Manager Manifest File
2+
dependencies:
3+
esp32async/espasyncwebserver:
4+
version: "*"
5+
override_path: "../../../"
6+
pre_release: true
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// SPDX-License-Identifier: LGPL-3.0-or-later
2+
// Copyright 2016-2025 Hristo Gochkov, Mathieu Carbou, Emil Muratov
3+
4+
//
5+
// Shows how to catch all requests and send a 404 Not Found response
6+
//
7+
8+
#include <Arduino.h>
9+
#include <AsyncTCP.h>
10+
#include <WiFi.h>
11+
12+
#include <ESPAsyncWebServer.h>
13+
14+
static AsyncWebServer server(80);
15+
16+
static const char *htmlContent PROGMEM = R"(
17+
<!DOCTYPE html>
18+
<html>
19+
<head>
20+
<title>Sample HTML</title>
21+
</head>
22+
<body>
23+
<h1>Hello, World!</h1>
24+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin euismod, purus a euismod
25+
rhoncus, urna ipsum cursus massa, eu dictum tellus justo ac justo. Quisque ullamcorper
26+
arcu nec tortor ullamcorper, vel fermentum justo fermentum. Vivamus sed velit ut elit
27+
accumsan congue ut ut enim. Ut eu justo eu lacus varius gravida ut a tellus. Nulla facilisi.
28+
Integer auctor consectetur ultricies. Fusce feugiat, mi sit amet bibendum viverra, orci leo
29+
dapibus elit, id varius sem dui id lacus.</p>
30+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin euismod, purus a euismod
31+
rhoncus, urna ipsum cursus massa, eu dictum tellus justo ac justo. Quisque ullamcorper
32+
arcu nec tortor ullamcorper, vel fermentum justo fermentum. Vivamus sed velit ut elit
33+
accumsan congue ut ut enim. Ut eu justo eu lacus varius gravida ut a tellus. Nulla facilisi.
34+
Integer auctor consectetur ultricies. Fusce feugiat, mi sit amet bibendum viverra, orci leo
35+
dapibus elit, id varius sem dui id lacus.</p>
36+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin euismod, purus a euismod
37+
rhoncus, urna ipsum cursus massa, eu dictum tellus justo ac justo. Quisque ullamcorper
38+
arcu nec tortor ullamcorper, vel fermentum justo fermentum. Vivamus sed velit ut elit
39+
accumsan congue ut ut enim. Ut eu justo eu lacus varius gravida ut a tellus. Nulla facilisi.
40+
Integer auctor consectetur ultricies. Fusce feugiat, mi sit amet bibendum viverra, orci leo
41+
dapibus elit, id varius sem dui id lacus.</p>
42+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin euismod, purus a euismod
43+
rhoncus, urna ipsum cursus massa, eu dictum tellus justo ac justo. Quisque ullamcorper
44+
arcu nec tortor ullamcorper, vel fermentum justo fermentum. Vivamus sed velit ut elit
45+
accumsan congue ut ut enim. Ut eu justo eu lacus varius gravida ut a tellus. Nulla facilisi.
46+
Integer auctor consectetur ultricies. Fusce feugiat, mi sit amet bibendum viverra, orci leo
47+
dapibus elit, id varius sem dui id lacus.</p>
48+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin euismod, purus a euismod
49+
rhoncus, urna ipsum cursus massa, eu dictum tellus justo ac justo. Quisque ullamcorper
50+
arcu nec tortor ullamcorper, vel fermentum justo fermentum. Vivamus sed velit ut elit
51+
accumsan congue ut ut enim. Ut eu justo eu lacus varius gravida ut a tellus. Nulla facilisi.
52+
Integer auctor consectetur ultricies. Fusce feugiat, mi sit amet bibendum viverra, orci leo
53+
dapibus elit, id varius sem dui id lacus.</p>
54+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin euismod, purus a euismod
55+
rhoncus, urna ipsum cursus massa, eu dictum tellus justo ac justo. Quisque ullamcorper
56+
arcu nec tortor ullamcorper, vel fermentum justo fermentum. Vivamus sed velit ut elit
57+
accumsan congue ut ut enim. Ut eu justo eu lacus varius gravida ut a tellus. Nulla facilisi.
58+
Integer auctor consectetur ultricies. Fusce feugiat, mi sit amet bibendum viverra, orci leo
59+
dapibus elit, id varius sem dui id lacus.</p>
60+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin euismod, purus a euismod
61+
rhoncus, urna ipsum cursus massa, eu dictum tellus justo ac justo. Quisque ullamcorper
62+
arcu nec tortor ullamcorper, vel fermentum justo fermentum. Vivamus sed velit ut elit
63+
accumsan congue ut ut enim. Ut eu justo eu lacus varius gravida ut a tellus. Nulla facilisi.
64+
Integer auctor consectetur ultricies. Fusce feugiat, mi sit amet bibendum viverra, orci leo
65+
dapibus elit, id varius sem dui id lacus.</p>
66+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin euismod, purus a euismod
67+
rhoncus, urna ipsum cursus massa, eu dictum tellus justo ac justo. Quisque ullamcorper
68+
arcu nec tortor ullamcorper, vel fermentum justo fermentum. Vivamus sed velit ut elit
69+
accumsan congue ut ut enim. Ut eu justo eu lacus varius gravida ut a tellus. Nulla facilisi.
70+
Integer auctor consectetur ultricies. Fusce feugiat, mi sit amet bibendum viverra, orci leo
71+
dapibus elit, id varius sem dui id lacus.</p>
72+
</body>
73+
</html>
74+
)";
75+
76+
static const size_t htmlContentLength = strlen_P(htmlContent);
77+
78+
void setup() {
79+
Serial.begin(115200);
80+
81+
#ifndef CONFIG_IDF_TARGET_ESP32H2
82+
WiFi.mode(WIFI_AP);
83+
WiFi.softAP("esp-captive");
84+
#endif
85+
86+
// curl -v http://192.168.4.1/
87+
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
88+
// need to cast to uint8_t*
89+
// if you do not, the const char* will be copied in a temporary String buffer
90+
request->send(200, "text/html", (uint8_t *)htmlContent, htmlContentLength);
91+
});
92+
93+
// catch any request, and send a 404 Not Found response
94+
// except for /game_log which is handled by onRequestBody
95+
//
96+
// curl -v http://192.168.4.1/foo
97+
//
98+
server.onNotFound([](AsyncWebServerRequest *request) {
99+
if (request->url() == "/game_log") {
100+
return; // response object already created by onRequestBody
101+
}
102+
103+
request->send(404, "text/plain", "Not found");
104+
});
105+
106+
// See: https://github.com/ESP32Async/ESPAsyncWebServer/issues/6
107+
// catch any POST request and send a 200 OK response
108+
//
109+
// curl -v -X POST http://192.168.4.1/game_log -H "Content-Type: application/json" -d '{"game": "test"}'
110+
//
111+
server.onRequestBody([](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) {
112+
if (request->url() == "/game_log") {
113+
request->send(200, "application/json", "{\"status\":\"OK\"}");
114+
}
115+
// note that there is no else here: the goal is only to prepare a response based on some body content
116+
// onNotFound will always be called after this, and will not override the response object if `/game_log` is requested
117+
});
118+
119+
server.begin();
120+
}
121+
122+
// not needed
123+
void loop() {
124+
delay(100);
125+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Arduino ESP32
3+
#
4+
CONFIG_AUTOSTART_ARDUINO=y
5+
# end of Arduino ESP32
6+
7+
#
8+
# FREERTOS
9+
#
10+
CONFIG_FREERTOS_HZ=1000
11+
# end of FREERTOS
12+
# end of Component config
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# For more information about build system see
2+
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
3+
# The following five lines of boilerplate have to be in your project's
4+
# CMakeLists in this exact order for cmake to work correctly
5+
cmake_minimum_required(VERSION 3.16)
6+
7+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
8+
project(main)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
### Basic example to show how to use ServerSentEvents

0 commit comments

Comments
 (0)