Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ jobs:

strategy:
matrix:
idf-version: ["4.4.3"]
idf-version: ["4.4.3", "5.1.2"]
otp: ["24"]
elixir_version: ["1.11"]
soc: ["esp32", "esp32c3", "esp32s2", "esp32s3"]
soc: ["esp32", "esp32c3", "esp32c6", "esp32s2", "esp32s3"]
exclude:
- idf-version: "4.4.3"
soc: "esp32c6"

env:
ImageOS: "ubuntu20"
Expand All @@ -41,7 +44,7 @@ jobs:
run: apt update -y

- name: "Install deps"
run: DEBIAN_FRONTEND=noninteractive apt install -y git cmake
run: DEBIAN_FRONTEND=noninteractive apt install -y git cmake gperf zlib1g-dev libmbedtls-dev

- name: "System info"
run: |
Expand Down
21 changes: 16 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -22,13 +22,24 @@ set(ATOMVM_MQTT_CLIENT_COMPONENT_SRCS
"ports/atomvm_mqtt_client.c"
)

# WHOLE_ARCHIVE option is supported only with esp-idf 5.x
# A link option will be used with esp-idf 4.x
if(IDF_VERSION_MAJOR EQUAL 5)
set(OPTIONAL_WHOLE_ARCHIVE WHOLE_ARCHIVE)
else()
set(OPTIONAL_WHOLE_ARCHIVE "")
endif()

idf_component_register(
SRCS ${ATOMVM_MQTT_CLIENT_COMPONENT_SRCS}
INCLUDE_DIRS "ports/include"
PRIV_REQUIRES "libatomvm" "avm_sys" "mqtt"
${OPTIONAL_WHOLE_ARCHIVE}
)

idf_build_set_property(
LINK_OPTIONS "-Wl,--whole-archive ${CMAKE_CURRENT_BINARY_DIR}/lib${COMPONENT_NAME}.a -Wl,--no-whole-archive"
APPEND
)
if(IDF_VERSION_MAJOR EQUAL 4)
idf_build_set_property(
LINK_OPTIONS "-Wl,--whole-archive ${CMAKE_CURRENT_BINARY_DIR}/lib${COMPONENT_NAME}.a -Wl,--no-whole-archive"
APPEND
)
endif()
19 changes: 15 additions & 4 deletions ports/atomvm_mqtt_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
// #define ENABLE_TRACE
#include <trace.h>

#include <inttypes.h>

#define TAG "atomvm_mqtt"

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

#if ESP_IDF_VERSION_MAJOR >= 5
Context *ctx = (Context *) handler_args;
#else
Context *ctx = (Context *) event->user_context;
#endif
GlobalContext *global = ctx->global;

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

int topic_size = term_binary_data_size_in_terms(event->topic_len) + BINARY_HEADER_SIZE;
int data_size = term_binary_data_size_in_terms(event->data_len) + BINARY_HEADER_SIZE;
int topic_size = term_binary_heap_size(event->topic_len);
int data_size = term_binary_heap_size(event->data_len);

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

case MQTT_EVENT_BEFORE_CONNECT: {
ESP_LOGI(TAG, "MQTT_EVENT_BEFORE_CONNECT event_id: %d", event_id);
ESP_LOGI(TAG, "MQTT_EVENT_BEFORE_CONNECT event_id: %" PRIu32, event_id);
break;
}

default:
ESP_LOGW(TAG, "Other event. event_id: %d", event_id);
ESP_LOGW(TAG, "Other event. event_id: %" PRIu32, event_id);
break;
}

Expand Down Expand Up @@ -778,9 +784,14 @@ Context *atomvm_mqtt_client_create_port(GlobalContext *global, term opts)
// Note that char * values passed into this struct are copied into the MQTT state
const char *client_id = get_default_client_id();
esp_mqtt_client_config_t mqtt_cfg = {
#if ESP_IDF_VERSION_MAJOR >= 5
.broker.address.uri = url_str,
.credentials.client_id = client_id
#else
.uri = url_str,
.client_id = client_id,
.user_context = (void *) ctx
#endif
};
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);

Expand Down