Is ESP-IDF MQTT implementation asynchronous?

gomez9656
Posts: 23
Joined: Mon Mar 14, 2022 7:48 pm

Is ESP-IDF MQTT implementation asynchronous?

Postby gomez9656 » Mon Jan 20, 2025 11:36 pm

I'm working on an ESP32 project that so far works well. I'm using the PubSubClient library to connect to the AWS IoT core but that one has a blocking method that I would prefer to not use.

I found the ESP-IDF MQTT implementation which seems to also work, but I haven't found anything in the documentation that mentions if it is blocking or not.

Can someone with more expertise int he codebase help me solve this question?

Thanks a lot in advance

ves011
Posts: 22
Joined: Fri Oct 07, 2022 2:31 pm

Re: Is ESP-IDF MQTT implementation asynchronous?

Postby ves011 » Fri Jan 24, 2025 5:28 pm

mqtt client implementation in ESP_IDF runs in its own task: esp_mqtt_task.
Messages from subscribed topics, are delivered at the application level via an event handler which you need to implement and register. So, receiving is asynchronous
Published messages looks to by synchronous, and it make sense because you might have other QOSes than 0.
[edit]
You also have the unblocking version of publish

Code: Select all

int esp_mqtt_client_enqueue(esp_mqtt_client_handle_t client, const char *topic, const char *data, int len, int qos, int retain, bool store)
See the details herehttps://docs.espressif.com/projects/esp ... /mqtt.html

egionet
Posts: 7
Joined: Thu Sep 26, 2024 4:34 am

Re: Is ESP-IDF MQTT implementation asynchronous?

Postby egionet » Sat Jan 25, 2025 10:41 am

An ESP-IDF MQTT asynchronous example is available here: https://github.com/K0I05/ESP32-S3_I2C-M ... E_20241030

This application polls BMP280 and SHT40 MEMS sensors over I2C. Samples are queued and transmitted to a MACHBASE instance that resides on a local network. The device connects to the local network over WIFI, synchronizes the system clock through SNTP services, and publishes data to the MACHBASE MQTT broker at a 6-second interval.

Who is online

Users browsing this forum: Google [Bot] and 61 guests