Skip to content

Commit 38ecf7a

Browse files
authored
Merge pull request #14 from ESP32Async/bugfix/component_upload
Fix IDF component publishing and example
2 parents afc39c1 + 432aa4d commit 38ecf7a

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
lines changed

.github/workflows/upload-idf-component.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
2727
if [[ $branch == refs/tags/* ]]; then
2828
tag="${branch#refs/tags/}"
29-
elif [[ $branch =~ ^[0-9]+\.[0-9]+\.[0-9]+.*$ ]]; then
29+
elif [[ $branch =~ ^[v]*[0-9]+\.[0-9]+\.[0-9]+.*$ ]]; then
3030
tag=$branch
3131
else
3232
echo "Tag not found in $branch. Exiting..."

idf_component.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ files:
1313
- ".clang-format"
1414
- ".gitpod.Dockerfile"
1515
- ".gitpod.yml"
16-
- "arduino-cli.yml"
17-
- "arduino-cli-dev.yml"
16+
- ".codespellrc"
17+
- ".editorconfig"
18+
- ".pre-commit-config.yaml"
19+
- "arduino-cli.yaml"
20+
- "arduino-cli-dev.yaml"
1821
- "CODE_OF_CONDUCT.md"
1922
- "component.mk"
2023
- "library.json"
2124
- "library.properties"
2225
- "platformio.ini"
26+
- "pre-commit.requirements.txt"
2327
dependencies:
2428
espressif/arduino-esp32:
2529
version: "^3.1.1"
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
### Basic example to show how AsyncTCP client works

idf_component_examples/client/main/main.cpp

+12-18
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,32 @@
1515
#define WIFI_SSID "*********"
1616
#define WIFI_PASS "*********"
1717

18-
// 16 slots on esp32 (CONFIG_LWIP_MAX_ACTIVE_TCP)
19-
#define MAX_CLIENTS CONFIG_LWIP_MAX_ACTIVE_TCP
20-
// #define MAX_CLIENTS 1
21-
22-
size_t permits = MAX_CLIENTS;
18+
bool client_running = false;
2319

2420
void makeRequest() {
25-
if (!permits) {
21+
client_running = true;
22+
AsyncClient *client = new AsyncClient;
23+
if (client == nullptr) {
24+
Serial.println("** could not allocate client");
25+
client_running = false;
2626
return;
2727
}
2828

29-
Serial.printf("** permits: %d\n", permits);
30-
31-
AsyncClient *client = new AsyncClient;
32-
3329
client->onError([](void *arg, AsyncClient *client, int8_t error) {
3430
Serial.printf("** error occurred %s \n", client->errorToString(error));
3531
client->close(true);
3632
delete client;
33+
client_running = false;
3734
});
3835

3936
client->onConnect([](void *arg, AsyncClient *client) {
40-
permits--;
4137
Serial.printf("** client has been connected: %" PRIu16 "\n", client->localPort());
4238

4339
client->onDisconnect([](void *arg, AsyncClient *client) {
4440
Serial.printf("** client has been disconnected: %" PRIu16 "\n", client->localPort());
4541
client->close(true);
4642
delete client;
47-
48-
permits++;
49-
makeRequest();
43+
client_running = false;
5044
});
5145

5246
client->onData([](void *arg, AsyncClient *client, void *data, size_t len) {
@@ -58,6 +52,7 @@ void makeRequest() {
5852

5953
if (!client->connect(HOST, PORT)) {
6054
Serial.println("** connection failed");
55+
client_running = false;
6156
}
6257
}
6358

@@ -74,13 +69,12 @@ void setup() {
7469
Serial.println();
7570
Serial.print("Connected to WiFi. IP: ");
7671
Serial.println(WiFi.localIP());
77-
78-
for (size_t i = 0; i < MAX_CLIENTS; i++) {
79-
makeRequest();
80-
}
8172
}
8273

8374
void loop() {
75+
if (!client_running) {
76+
makeRequest();
77+
}
8478
delay(1000);
8579
Serial.printf("** free heap: %" PRIu32 "\n", ESP.getFreeHeap());
8680
}

0 commit comments

Comments
 (0)