Skip to content

Commit 64387a7

Browse files
committed
Add support for IDF SDK 5.x
1 parent 97f0d32 commit 64387a7

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

.github/workflows/build.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ jobs:
2020

2121
strategy:
2222
matrix:
23-
idf-version: ["4.4.3"]
23+
idf-version: ["4.4.3", "5.1.2"]
2424
otp: ["24"]
2525
elixir_version: ["1.11"]
26-
soc: ["esp32", "esp32c3", "esp32s2", "esp32s3"]
26+
soc: ["esp32", "esp32c3", "esp32c6", "esp32s2", "esp32s3"]
27+
exclude:
28+
- idf-version: "4.4.3"
29+
soc: "esp32c6"
2730

2831
env:
2932
ImageOS: "ubuntu20"
@@ -41,7 +44,7 @@ jobs:
4144
run: apt update -y
4245

4346
- name: "Install deps"
44-
run: DEBIAN_FRONTEND=noninteractive apt install -y git cmake
47+
run: DEBIAN_FRONTEND=noninteractive apt install -y git cmake gperf zlib1g-dev libmbedtls-dev
4548

4649
- name: "System info"
4750
run: |

CMakeLists.txt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# you may not use this file except in compliance with the License.
88
# You may obtain a copy of the License at
99
#
10-
# http://www.apache.org/licenses/LICENSE-2.0
10+
# http://www.apache.org/licenses/LICENSE-2.0
1111
#
1212
# Unless required by applicable law or agreed to in writing, software
1313
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -22,13 +22,24 @@ set(ATOMVM_MQTT_CLIENT_COMPONENT_SRCS
2222
"ports/atomvm_mqtt_client.c"
2323
)
2424

25+
# WHOLE_ARCHIVE option is supported only with esp-idf 5.x
26+
# A link option will be used with esp-idf 4.x
27+
if(IDF_VERSION_MAJOR EQUAL 5)
28+
set(OPTIONAL_WHOLE_ARCHIVE WHOLE_ARCHIVE)
29+
else()
30+
set(OPTIONAL_WHOLE_ARCHIVE "")
31+
endif()
32+
2533
idf_component_register(
2634
SRCS ${ATOMVM_MQTT_CLIENT_COMPONENT_SRCS}
2735
INCLUDE_DIRS "ports/include"
2836
PRIV_REQUIRES "libatomvm" "avm_sys" "mqtt"
37+
${OPTIONAL_WHOLE_ARCHIVE}
2938
)
3039

31-
idf_build_set_property(
32-
LINK_OPTIONS "-Wl,--whole-archive ${CMAKE_CURRENT_BINARY_DIR}/lib${COMPONENT_NAME}.a -Wl,--no-whole-archive"
33-
APPEND
34-
)
40+
if(IDF_VERSION_MAJOR EQUAL 4)
41+
idf_build_set_property(
42+
LINK_OPTIONS "-Wl,--whole-archive ${CMAKE_CURRENT_BINARY_DIR}/lib${COMPONENT_NAME}.a -Wl,--no-whole-archive"
43+
APPEND
44+
)
45+
endif()

ports/atomvm_mqtt_client.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
// #define ENABLE_TRACE
4040
#include <trace.h>
4141

42+
#include <inttypes.h>
43+
4244
#define TAG "atomvm_mqtt"
4345

4446
// static const char *const cert_atom = ATOM_STR("\x4", "cert");
@@ -435,7 +437,11 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
435437
TRACE(TAG ": mqtt_event_handler\n");
436438
esp_mqtt_event_handle_t event = event_data;
437439

440+
#if ESP_IDF_VERSION_MAJOR >= 5
441+
Context *ctx = (Context *) handler_args;
442+
#else
438443
Context *ctx = (Context *) event->user_context;
444+
#endif
439445
GlobalContext *global = ctx->global;
440446

441447
struct platform_data *plfdat = (struct platform_data *) ctx->platform_data;
@@ -529,8 +535,8 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
529535
TRACE(TAG ": TOPIC=%.*s\n", event->topic_len, event->topic);
530536
TRACE(TAG ": DATA=%.*s\n", event->data_len, event->data);
531537

532-
int topic_size = term_binary_data_size_in_terms(event->topic_len) + BINARY_HEADER_SIZE;
533-
int data_size = term_binary_data_size_in_terms(event->data_len) + BINARY_HEADER_SIZE;
538+
int topic_size = term_binary_heap_size(event->topic_len);
539+
int data_size = term_binary_heap_size(event->data_len);
534540

535541
size_t requested_size = TUPLE_SIZE(4) + topic_size + data_size;
536542
Heap heap;
@@ -585,12 +591,12 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
585591
}
586592

587593
case MQTT_EVENT_BEFORE_CONNECT: {
588-
ESP_LOGI(TAG, "MQTT_EVENT_BEFORE_CONNECT event_id: %d", event_id);
594+
ESP_LOGI(TAG, "MQTT_EVENT_BEFORE_CONNECT event_id: %" PRIu32, event_id);
589595
break;
590596
}
591597

592598
default:
593-
ESP_LOGW(TAG, "Other event. event_id: %d", event_id);
599+
ESP_LOGW(TAG, "Other event. event_id: %" PRIu32, event_id);
594600
break;
595601
}
596602

@@ -778,9 +784,14 @@ Context *atomvm_mqtt_client_create_port(GlobalContext *global, term opts)
778784
// Note that char * values passed into this struct are copied into the MQTT state
779785
const char *client_id = get_default_client_id();
780786
esp_mqtt_client_config_t mqtt_cfg = {
787+
#if ESP_IDF_VERSION_MAJOR >= 5
788+
.broker.address.uri = url_str,
789+
.credentials.client_id = client_id
790+
#else
781791
.uri = url_str,
782792
.client_id = client_id,
783793
.user_context = (void *) ctx
794+
#endif
784795
};
785796
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
786797

0 commit comments

Comments
 (0)