Skip to content

Commit 4fbabcf

Browse files
Merge pull request #7 from ESP32Async/feature/isp_idf_component_registry
Add support for ESP-IDF component registry
2 parents 2c379f0 + 6751bae commit 4fbabcf

File tree

7 files changed

+189
-0
lines changed

7 files changed

+189
-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: 'Version to push to the component registry'
8+
required: true
9+
git_ref:
10+
description: 'Git ref with the source to push to the component registry'
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 =~ ^[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: asynctcp
48+
version: ${{ env.RELEASE_TAG }}
49+
namespace: esp32async
50+
api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }}

idf_component.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
description: "Async TCP Library for ESP32 Arduino"
2+
url: "https://github.com/ESP32Async/AsyncTCP"
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+
- "arduino-cli.yml"
17+
- "arduino-cli-dev.yml"
18+
- "CODE_OF_CONDUCT.md"
19+
- "component.mk"
20+
- "library.json"
21+
- "library.properties"
22+
- "platformio.ini"
23+
dependencies:
24+
espressif/arduino-esp32:
25+
version: "^3.1.1"
26+
require: public
27+
examples:
28+
- path: ./idf_component_examples/client
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: 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/asynctcp:
4+
version: "*"
5+
override_path: "../../../"
6+
pre_release: true
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#include "Arduino.h"
2+
#include "AsyncTCP.h"
3+
#include "WiFi.h"
4+
5+
// Run a server at the root of the project with:
6+
// > python3 -m http.server 3333
7+
// Now you can open a browser and test it works by visiting http://192.168.125.122:3333/ or http://192.168.125.122:3333/README.md
8+
#define HOST "192.168.125.122"
9+
#define PORT 3333
10+
11+
// WiFi SSID to connect to
12+
#define WIFI_SSID "*********"
13+
#define WIFI_PASS "*********"
14+
15+
// 16 slots on esp32 (CONFIG_LWIP_MAX_ACTIVE_TCP)
16+
#define MAX_CLIENTS CONFIG_LWIP_MAX_ACTIVE_TCP
17+
// #define MAX_CLIENTS 1
18+
19+
size_t permits = MAX_CLIENTS;
20+
21+
void makeRequest() {
22+
if (!permits) {
23+
return;
24+
}
25+
26+
Serial.printf("** permits: %d\n", permits);
27+
28+
AsyncClient *client = new AsyncClient;
29+
30+
client->onError([](void *arg, AsyncClient *client, int8_t error) {
31+
Serial.printf("** error occurred %s \n", client->errorToString(error));
32+
client->close(true);
33+
delete client;
34+
});
35+
36+
client->onConnect([](void *arg, AsyncClient *client) {
37+
permits--;
38+
Serial.printf("** client has been connected: %" PRIu16 "\n", client->localPort());
39+
40+
client->onDisconnect([](void *arg, AsyncClient *client) {
41+
Serial.printf("** client has been disconnected: %" PRIu16 "\n", client->localPort());
42+
client->close(true);
43+
delete client;
44+
45+
permits++;
46+
makeRequest();
47+
});
48+
49+
client->onData([](void *arg, AsyncClient *client, void *data, size_t len) {
50+
Serial.printf("** data received by client: %" PRIu16 ": len=%u\n", client->localPort(), len);
51+
});
52+
53+
client->write("GET /README.md HTTP/1.1\r\nHost: " HOST "\r\nUser-Agent: ESP\r\nConnection: close\r\n\r\n");
54+
});
55+
56+
if (!client->connect(HOST, PORT)) {
57+
Serial.println("** connection failed");
58+
}
59+
}
60+
61+
void setup() {
62+
Serial.begin(115200);
63+
64+
Serial.print("Connecting to ");
65+
Serial.print(WIFI_SSID);
66+
WiFi.begin(WIFI_SSID, WIFI_PASS);
67+
while (WiFi.status() != WL_CONNECTED) {
68+
delay(500);
69+
Serial.print(".");
70+
}
71+
Serial.println();
72+
Serial.print("Connected to WiFi. IP: ");
73+
Serial.println(WiFi.localIP());
74+
75+
for (size_t i = 0; i < MAX_CLIENTS; i++) {
76+
makeRequest();
77+
}
78+
}
79+
80+
void loop() {
81+
delay(1000);
82+
Serial.printf("** free heap: %" PRIu32 "\n", ESP.getFreeHeap());
83+
}
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

0 commit comments

Comments
 (0)