Recommendations for MQTT Library with ESPIDF

rwel59
Posts: 97
Joined: Thu Oct 12, 2017 3:32 pm

Recommendations for MQTT Library with ESPIDF

Postby rwel59 » Thu Oct 26, 2017 7:05 pm

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.

ozanhan
Posts: 1
Joined: Tue Oct 30, 2018 8:53 am

Re: Recommendations for MQTT Library with ESPIDF

Postby ozanhan » Tue Nov 13, 2018 7:18 am

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

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Recommendations for MQTT Library with ESPIDF

Postby ESP_Angus » Tue Nov 13, 2018 11:21 pm

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.

axellin
Posts: 200
Joined: Mon Sep 17, 2018 9:09 am

Re: Recommendations for MQTT Library with ESPIDF

Postby axellin » 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.

ESP_tuanpm
Posts: 14
Joined: Sat Dec 05, 2015 7:59 am

Re: Recommendations for MQTT Library with ESPIDF

Postby ESP_tuanpm » Mon Nov 26, 2018 8:56 am

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.,

axellin
Posts: 200
Joined: Mon Sep 17, 2018 9:09 am

Re: Recommendations for MQTT Library with ESPIDF

Postby axellin » Tue Nov 27, 2018 3:20 am

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.

ESP_tuanpm
Posts: 14
Joined: Sat Dec 05, 2015 7:59 am

Re: Recommendations for MQTT Library with ESPIDF

Postby ESP_tuanpm » Tue Nov 27, 2018 3:50 am

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

rwel59
Posts: 97
Joined: Thu Oct 12, 2017 3:32 pm

Re: Recommendations for MQTT Library with ESPIDF

Postby rwel59 » Wed Dec 05, 2018 9:31 pm

Is the mqtt library now included with espidf usable with AWS mqtt? If so, are there any examples available?

rwel59
Posts: 97
Joined: Thu Oct 12, 2017 3:32 pm

Re: Recommendations for MQTT Library with ESPIDF

Postby rwel59 » Wed Dec 19, 2018 10:17 pm

Does anyone have any input for this. Trying to figure what the best route is for using espidf with aws iot...

chegewara
Posts: 2378
Joined: Wed Jun 14, 2017 9:00 pm

Re: Recommendations for MQTT Library with ESPIDF

Postby chegewara » Wed Dec 19, 2018 11:25 pm

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.

Who is online

Users browsing this forum: No registered users and 154 guests