Page 1 of 2

Recommendations for MQTT Library with ESPIDF

Posted: Thu Oct 26, 2017 7:05 pm
by rwel59
Seems there are a number of choices for mqtt client libraries. Can anyone give their input on one versus the other. I'm using Eclipse with ESPIDF (for ESP32) in c++. The libraries I was looking at include Paho Mqtt C, ESPMQTT (Tuanpmt), ESP-MQTT (base on lwmqtt) and the aws-iot.

Starting off with simple connection to local mosquitto broker.

thanks for the input/opinions.

Re: Recommendations for MQTT Library with ESPIDF

Posted: Tue Nov 13, 2018 7:18 am
by ozanhan
Hello rwel59,

Which library did you choose? Are you happy with your choice? What is your opinion about libraries other then you choose? :)

Thanks for reply...

Ozanhan Anac

Re: Recommendations for MQTT Library with ESPIDF

Posted: Tue Nov 13, 2018 11:21 pm
by ESP_Angus
Hi Ozanhan,

Since this post was originally made last year, the esp-mqtt library has been integrated into ESP-IDF.

There is some documentation here:
https://docs.espressif.com/projects/esp ... /mqtt.html

And some examples here:
https://github.com/espressif/esp-idf/tr ... ocols/mqtt

This is the officially recommended and supported MQTT library for ESP-IDF.

Re: Recommendations for MQTT Library with ESPIDF

Posted: Mon Nov 26, 2018 5:19 am
by axellin
ESP_Angus wrote:
Tue Nov 13, 2018 11:21 pm
Since this post was originally made last year, the esp-mqtt library has been integrated into ESP-IDF.
Is the esp-mqtt library thread safe?
I don't find locking mechanism in the esp-mqtt library code.
So I'm wondering if it is ok to call esp_mqtt_client_publish() in another task?
The example code calls esp_mqtt_client_publish() in mqtt_event_handler() when got MQTT_EVENT_CONNECTED, that is fine because it's executed by mqtt_task.
However, it's very common a user application need to create another task to regularly (or with some customized logic) send publish data.

Re: Recommendations for MQTT Library with ESPIDF

Posted: Mon Nov 26, 2018 8:56 am
by ESP_tuanpm
axellin wrote:
Mon Nov 26, 2018 5:19 am
ESP_Angus wrote:
Tue Nov 13, 2018 11:21 pm
Since this post was originally made last year, the esp-mqtt library has been integrated into ESP-IDF.
Is the esp-mqtt library thread safe?
I don't find locking mechanism in the esp-mqtt library code.
So I'm wondering if it is ok to call esp_mqtt_client_publish() in another task?
The example code calls esp_mqtt_client_publish() in mqtt_event_handler() when got MQTT_EVENT_CONNECTED, that is fine because it's executed by mqtt_task.
However, it's very common a user application need to create another task to regularly (or with some customized logic) send publish data.
Hi @axellin,

The outbox for MQTT needs to be implemented to re-send the failed packet. Currently esp-mqtt directly writes data to the socket without reading from the outbox. Then, there are no semaphore needed to protect the outbox (read/write from difference threads). I think the next release, the MQTT client will support outbox storage.

Thanks.,

Re: Recommendations for MQTT Library with ESPIDF

Posted: Tue Nov 27, 2018 3:20 am
by axellin
ESP_tuanpm wrote:
Mon Nov 26, 2018 8:56 am

Hi @axellin,

The outbox for MQTT needs to be implemented to re-send the failed packet. Currently esp-mqtt directly writes data to the socket without reading from the outbox. Then, there are no semaphore needed to protect the outbox (read/write from difference threads). I think the next release, the MQTT client will support outbox storage.

Thanks.,
Hi @ESP_tuanpm
I think it's not about re-send the failed packet.
The esp-mqtt library is *not* thread safe at all.
Just think about 2 tasks calling any of esp_mqtt_client_subscribe()/esp_mqtt_client_unsubscribe()/esp_mqtt_client_ping()/ esp_mqtt_client_publish() APIs at the same time on differnct CPU, All the client->mqtt_state.* fields can be racy.
This needs fix.

Re: Recommendations for MQTT Library with ESPIDF

Posted: Tue Nov 27, 2018 3:50 am
by ESP_tuanpm
axellin wrote:
Tue Nov 27, 2018 3:20 am

Hi @ESP_tuanpm
I think it's not about re-send the failed packet.
The esp-mqtt library is *not* thread safe at all.
Just think about 2 tasks calling any of esp_mqtt_client_subscribe()/esp_mqtt_client_unsubscribe()/esp_mqtt_client_ping()/ esp_mqtt_client_publish() APIs at the same time on differnct CPU, All the client->mqtt_state.* fields can be racy.
This needs fix.
Thank @axellin to correct me the right problem. Yes, these need to fix asap

Re: Recommendations for MQTT Library with ESPIDF

Posted: Wed Dec 05, 2018 9:31 pm
by rwel59
Is the mqtt library now included with espidf usable with AWS mqtt? If so, are there any examples available?

Re: Recommendations for MQTT Library with ESPIDF

Posted: Wed Dec 19, 2018 10:17 pm
by rwel59
Does anyone have any input for this. Trying to figure what the best route is for using espidf with aws iot...

Re: Recommendations for MQTT Library with ESPIDF

Posted: Wed Dec 19, 2018 11:25 pm
by chegewara
https://github.com/espressif/esp-idf/tr ... ls/aws_iot

I am working on some project curently and I can tell that it's good base to start with AWS IoT.