Giter Site home page Giter Site logo

esp-mqtt's Introduction

Twitter Follow GitHub contributors

ESP32 MQTT Library

Features

  • Based on: https://github.com/tuanpmt/esp_mqtt
  • Support MQTT over TCP, SSL with mbedtls, MQTT over Websocket, MQTT over Websocket Secure
  • Easy to setup with URI
  • Multiple instances (Multiple clients in one application)
  • Support subscribing, publishing, authentication, will messages, keep alive pings and all 3 QoS levels (it should be a fully functional client).

How to use

ESP-MQTT is a standard ESP-IDF component. Please refer to instructions in ESP-IDF

Documentation

License

Older IDF verisons

For ESP-IDF versions prior to IDFv3.2, please clone as a component of ESP-IDF:

git submodule add https://github.com/espressif/esp-mqtt.git components/espmqtt

and checkout the ESP-MQTT_FOR_IDF_3.1 tag

esp-mqtt's People

Contributors

0xjakob avatar adityahpatwardhan avatar antmak avatar axellin avatar david-cermak avatar dazza0 avatar dobairoland avatar esp-marius avatar esp-yjm avatar euripedesrocha avatar ginkgm avatar gregjesl avatar igrr avatar jsafka avatar laukik-hase avatar laurentlouf avatar lhespress avatar liuzfesp avatar projectgus avatar rbino avatar renzbagaporo avatar shahpiyushv avatar suda-morris avatar sudeep-mohanty avatar suren-gabrielyan-espressif avatar tijnkooijmans avatar tomassebestik avatar tuanpmt avatar umer-ilyas avatar vtunr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp-mqtt's Issues

Connection refused, Unknow reason

Hi,

I am trying to use espmqtt via TCP (no SSL) on my ESP32 with a broker hosted on a Android phone.
When I try espmqtt with HBMQTT on a Windows machine (python MQTT broker) it works fine but when I try to use it with the broker on a Android application I made it says Connection refused, Unkow reason.

The MQTT broker on my Android application is made with Xamarin Android and MQTTNet as a MQTT broker. It works great with many MQTT clients, just not with espmqtt :

I tried with another MQTT client for esp32, which is Nkolban PubSubClient which works with my Android phone broker and ESP32. But I want to use espmqtt, which seems way better from my point of view.

I am using the espmqtt tcp sample from the repo. I only changed WIFI configuration and the URI.
Here is the ESP32 serial output :

I (5050) event: sta ip: 192.168.43.160, mask: 255.255.255.0, gw: 192.168.43.1
I (5050) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (5060) MQTT_CLIENT: Sending MQTT CONNECT message, type: 1, id: 0000
W (5080) MQTT_CLIENT: Connection refused, Unknow reason
I (5080) MQTT_CLIENT: Error MQTT Connected
I (5080) MQTT_CLIENT: Reconnect after 10000 ms
I (5090) MQTT_SAMPLE: MQTT_EVENT_DISCONNECTED

I tried :

  • In make menuconfig ->Component config -> ESPMQTT Configurations , to disable Enable MQTT protocol 3.1.1

  • Instead of using URI from esp_mqtt_config_t, to use host and other parameters to set up MQTT configuration

  • Tried to use different topic names (just in case)

It's possible it's an incompatibility from the Android Broker I am using and espmqtt, but all clients i have tested work on my Android MQTT broker very fine and I don't know why just espmqtt wouldn't work on my Android Application.

Do you have any ideas on how I could proceed or debug?

Thanks,
ogensyts

Interference when using with Mongoose

I'm using this library in conjunction with Cesanta's Mongoose library in order to serve html and connect to an MQTT broker at the same time. Both libraries work independently, but together they don't.

I'm getting this error:

I (61964) MQTT_CLIENT: Sending MQTT CONNECT message, type: 1, id: 0000
E (61965) MQTT_CLIENT: Writing failed, errno= 4
I (61966) MQTT_CLIENT: Error MQTT Connected
I (61972) MQTT_CLIENT: Reconnect after 10000 ms
I (61976) MQTT_SAMPLE: MQTT_EVENT_DISCONNECTED

In this case the HTTP server works, but after a while the MQTT client connects and the HTTP server stops working.
I've tried numerous things but nothing seems to work.
Stopping the mg_mgr_poll, which polls for HTTP request, works but then of course the HTTP server doesn't respond.
I think the 2 sockets are interfering.
Thanks in advance

Not connecting to Local Mosca SSL Broker

Mosca SSL Broker is working fine with mqtt client.But ESP32 not connecting to it.
const esp_mqtt_client_config_t mqtt_cfg = {
.uri = "mqtts://192.168.43.187",
.port = "8883",
.event_handle = mqtt_event_handler,
.cert_pem = (const char *)ca_crt_start,
.transport = MQTT_TRANSPORT_OVER_SSL,
.lwt_topic = "Death",
.lwt_msg = "Device is Disconnected",
};
this is the config.
and output is
I (3107) event: sta ip: 192.168.43.114, mask: 255.255.255.0, gw: 192.168.43.1
I (3107) MQTTS_SAMPLE: [APP] Free memory: 239004 bytes
I (3107) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (3887) MQTT_CLIENT: Sending MQTT CONNECT message, type: 1, id: 0000
E (3897) MQTT_CLIENT: Error network response
I (3897) MQTT_CLIENT: Error MQTT Connected
I (3897) MQTT_CLIENT: Reconnect after 10000 ms
I (3897) MQTTS_SAMPLE: MQTT_EVENT_DISCONNECTEDD

What can be the possible reason?

mqtt over ssl had use cafile?and memory all use.

When I open -> Component config -> mbedTLS Enable mbedTLS debugging and the debug is "W (3923) mbedtls: ssl_tls.c:4587 x509_verify_cert() returned -9984 (-0x2700)"?
when I use openssl s_client -showcerts -connect (My server addr):8883 </dev/null 2>/dev/null|openssl x509 -outform PEM >iot_eclipse_org.pem,get the pem is same to my server certfile , BUT I will get x509_verify_cert wrong returned -9984, But when I use the cafile same with server,It is will be ok,and just mqtt_ssl whrn connected will use about 50k memory.
@tuanpmt , Can u explain why I must use cafile on mqtt over ssl to connect my server?
And mqtt over ssl use 50k memory is correct?
Best regar to you.

mqtt_publish from another task ?

Can anyone tell me how to send data to the broker from another task ?
What client should I use as a pointer to mqtt_publish ?
I tried the one that is returned from mqtt_start(&settings), but as soon as it sends the data the esp crashes and reboots.....

Not connecting to SSL Broker

Previously I had used your esp8266 mqtt lib with a mosquitto server and it works very well.
However, this esp32 lib is failing to connect to the same server.
I am using mosquitto server with tls version tlsv1.
No certificates are used on the client side, only username and password is used for authentication.

We get the below error in server side:

error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number

Below is my mosquitto.conf:

port 1883
listener 8883

log_dest stdout
log_type all

allow_anonymous false
password_file /etc/mosquitto/password.txt

cafile /home//ca.crt
certfile /home//server.crt
keyfile /home//server.key
tls_version tlsv1

Any insights or suggestions

How to get issue (IDFGH-2513)

I try your method and get a certificate which is different to your certificate in the mqtt_ssl demo.
openssl s_client -showcerts -connect iot.eclipse.org:8883 </dev/null 2>/dev/null|openssl x509 -outform PEM >iot_eclipse_org.pem

-----BEGIN CERTIFICATE----- MIIGCTCCBPGgAwIBAgISBCgMMsgO+rB7pl+8oxmRJzKnMA0GCSqGSIb3DQEBCwUA MEoxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MSMwIQYDVQQD ExpMZXQncyBFbmNyeXB0IEF1dGhvcml0eSBYMzAeFw0xODA0MjMxMzM2MTNaFw0x ODA3MjIxMzM2MTNaMBoxGDAWBgNVBAMTD2lvdC5lY2xpcHNlLm9yZzCCASIwDQYJ KoZIhvcNAQEBBQADggEPADCCAQoCggEBANwqiLf1e6OY1alW19RLpey5IldDjVIW FLC2vF8Nv+WkHvShN5phMbazrb1Tm3LC7mNvX73wHIMZcjJ0qnWLPOPA/fKCEZSn RY0D/x4KN9tsL5NLJSPXcwuY3/SP8Gx5kPM2csDSDpAR9bZ/CgEe+gZphT3Ink0L honSW7QCkW5APu/MYQddlXr6NrZpEK/PnDbtmVr7xo/BUqCSqrWJlaNftF6eKXJW Ay4Zu3fhuQOuLRhAI+Sinv7I2f8LqfpmNzVYUc/ahi4KEdJUnMVmh5tziPED/fG0 qwVgwboNwJzXgKXhRUR7ihXL4iJJpVgTeSJfAPJjMpChXmZljYn4Xj0CAwEAAaOC AxcwggMTMA4GA1UdDwEB/wQEAwIFoDAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYB BQUHAwIwDAYDVR0TAQH/BAIwADAdBgNVHQ4EFgQU+k6Am15WnUPA1ZSQXaK7JZ0R DaswHwYDVR0jBBgwFoAUqEpqYwR93brm0Tm3pkVl7/Oo7KEwbwYIKwYBBQUHAQEE YzBhMC4GCCsGAQUFBzABhiJodHRwOi8vb2NzcC5pbnQteDMubGV0c2VuY3J5cHQu b3JnMC8GCCsGAQUFBzAChiNodHRwOi8vY2VydC5pbnQteDMubGV0c2VuY3J5cHQu b3JnLzAaBgNVHREEEzARgg9pb3QuZWNsaXBzZS5vcmcwgf4GA1UdIASB9jCB8zAI BgZngQwBAgEwgeYGCysGAQQBgt8TAQEBMIHWMCYGCCsGAQUFBwIBFhpodHRwOi8v Y3BzLmxldHNlbmNyeXB0Lm9yZzCBqwYIKwYBBQUHAgIwgZ4MgZtUaGlzIENlcnRp ZmljYXRlIG1heSBvbmx5IGJlIHJlbGllZCB1cG9uIGJ5IFJlbHlpbmcgUGFydGll cyBhbmQgb25seSBpbiBhY2NvcmRhbmNlIHdpdGggdGhlIENlcnRpZmljYXRlIFBv bGljeSBmb3VuZCBhdCBodHRwczovL2xldHNlbmNyeXB0Lm9yZy9yZXBvc2l0b3J5 LzCCAQQGCisGAQQB1nkCBAIEgfUEgfIA8AB1ACk8UZZUyDlluqpQ/FgH1Ldvv1h6 KXLcpMMM9OVFR/R4AAABYvLvA64AAAQDAEYwRAIgCDZaOTZnCU82Uo6lCMcqg79Q wJXk2A5zqtBZAMc+eDsCID9p45HDrbOlHftbnmnjA75CRD7GIB52izggv2XafOTV AHcA23Sv7ssp7LH+yj5xbSzluaq7NveEcYPHXZ1PN7Yfv2QAAAFi8u8D0AAABAMA SDBGAiEA6a/IgfiCbbNYygRemL6MdbM9QQbB7DxGrwvirVxQneYCIQDy74FAsA8W Lj8Ajy6WtBChRJrg8X2avdDR0Qk6cRDFNDANBgkqhkiG9w0BAQsFAAOCAQEASdA1 MZkWskB0423mxJ/WsR+MUjSZV3CXhQbPY+HQtiBKvQurUG1egZTy1D6AZg0LtMNG T60hoCOA2kw+nAQt1tJ1eBcOzHY2w1qEeUl4qmycsHf7oxfQc0WfCZuZu/rwl6Td SoTKsOsLYZ5tCqrFQISTgAhitqnJcMFsJz4lnA3BjbmQ6/M3LlN+j/wS1ESvj0I2 q5ejIhe6ge72A27IgMysWISdmReluu2fWmFmcOKswGuqfQCsYV9U+JEQeQ+rstHi BgvQvG/06a6RsYMvKUJawjNM2Ar58k3JRrn/++xb+26FQVS7HIMeNobR1fVdI0Lc hXx2rq59Hgy8T/vBrg== -----END CERTIFICATE-----

How to get the right certificate ?

Payload larger than CONFIG_MQTT_BUFFER_SIZE_BYTE not received

If the payload size is greater than CONFIG_MQTT_BUFFER_SIZE_BYTE only the first part of the payload is received.
The issue is caused by the bug in deliver_publish function where the event_data.data pointer is not updated when the blocks after the first one are read. As a result, the data_cb function can get only the data received in first CONFIG_MQTT_BUFFER_SIZE_BYTE bytes.

I don't have the time to make the pull request at the moment, but the solution is simple.
The following code in deliver_publish function:

        event_data.topic_length = length;
        event_data.topic = mqtt_get_publish_topic(message, &event_data.topic_length);
        event_data.data_length = length;
        event_data.data = mqtt_get_publish_data(message, &event_data.data_length);

        if(total_mqtt_len == 0){
            total_mqtt_len = client->mqtt_state.message_length - client->mqtt_state.message_length_read + event_data.data_length;
            mqtt_len = event_data.data_length;
        } else {
            mqtt_len = len_read;
        }

should be replaced with:

        if(total_mqtt_len == 0){
            event_data.topic_length = length;
            event_data.topic = mqtt_get_publish_topic(message, &event_data.topic_length);
            event_data.data_length = length;
            event_data.data = mqtt_get_publish_data(message, &event_data.data_length);
            total_mqtt_len = client->mqtt_state.message_length - client->mqtt_state.message_length_read + event_data.data_length;
            mqtt_len = event_data.data_length;
        } else {
            mqtt_len = len_read;
            event_data.data = (const char*)client->mqtt_state.in_buffer;
        }

After the change everything works as expected and the full data payload can be received by data callback function.

About add espmqtt component into project MQTT_CLIENT: Error network response

I (2567) MQTT_CLIENT: Sending MQTT CONNECT message, type: 1, id: 0000
E (2587) MQTT_CLIENT: Error network response
I (2587) MQTT_CLIENT: Error MQTT Connected
I (2587) MQTT_CLIENT: Reconnect after 10000 ms

Directly adding espmqtt component into the existing project doesn't work.

Debug

Need to make clean the existing project and make again.
And you need to choose the SSL or websocket or TCP and you can use the component.

Error write data or timeout (IDFGH-2514)

Hi,

I've been using quite a while this library but after few git pull updates, it stopped working and I'm getting the follow message:

E (151464) MQTT_CLIENT: Error write data or timeout, written len = -1
E (151464) MQTT_CLIENT: Error to public data to topic=/data/0001/, qos=0
E (151474) MQTT_CLIENT: Error write data or timeout, written len = -1
E (151474) MQTT_CLIENT: Error to public data to topic=/data/0001/, qos=0
E (151494) MQTT_CLIENT: Error write data or timeout, written len = -1
E (151494) MQTT_CLIENT: Error to public data to topic=/data/0001/, qos=0

The client connects successfully to MQTT Server:

D (16414) MQTT_CLIENT: MQTT client_id=teste
D (16414) TRANS_TCP: [sock=54],connecting to server IP:192.168.1.92,Port:1883...
D (16784) MQTT_CLIENT: Transport connected to mqtt://192.168.1.92:1883
I (16794) MQTT_CLIENT: Sending MQTT CONNECT message, type: 1, id: 0000
D (16804) MQTT_CLIENT: Connected
I (16804) MY_LOGGER: MQTT_EVENT_CONNECTED

I've tried with qos=0,1 and 2 and the same error happens (output differ a little bit 'cause 0 we don't enqueue the message).

I'm using username and password, at port 1883, disable_clean_session=true.

Using mosquitto_pub I can easily publish messages:

mosquitto_pub -h <host> -u <username> -P <password> -t '/data/0001/' -m "{}"

The same credentials and configs are used for mqtt_client (esp32) and mosquitto_pub.

What can I do to try to figure out what's happening?

Thanks in advance.

Compatibility with thingsboard.io

I am unable to submit data to mqtt://demo.thingsboard.io. After calling esp_mqtt_client_publish() I get the following error:

E (24381) MQTT_CLIENT: Read error or end of stream

If submitting to mqtt://iot.eclipse.org everything works as expected. Also tested also with the examples/mqtt_tcp app. Behaviour is the same. Eclipse works while Thingsboard not. Tested with both 3.1.1 protocol enabled and disabled. MQTT packets when inspected in Wireshark look the same.

Currently running out of ideas. Are there any known issues with Thingsboard or configuration changes I should try?

I (2171) event: sta ip: 192.168.8.106, mask: 255.255.255.0, gw: 192.168.8.1
I (2171) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (2461) MQTT_CLIENT: Sending MQTT CONNECT message, type: 1, id: 0000
I (2671) MQTT_SAMPLE: MQTT_EVENT_CONNECTED
I (2671) MQTT_SAMPLE: sent subscribe successful, msg_id=28741
I (2671) MQTT_SAMPLE: sent subscribe successful, msg_id=11408
I (2681) MQTT_SAMPLE: sent unsubscribe successful, msg_id=6495
I (2871) MQTT_SAMPLE: MQTT_EVENT_SUBSCRIBED, msg_id=28741
I (2871) MQTT_SAMPLE: sent publish successful, msg_id=0
I (3081) MQTT_SAMPLE: MQTT_EVENT_SUBSCRIBED, msg_id=11408
I (3081) MQTT_SAMPLE: sent publish successful, msg_id=0
I (3081) MQTT_SAMPLE: MQTT_EVENT_UNSUBSCRIBED, msg_id=6495
E (3281) MQTT_CLIENT: Read error or end of stream
I (3291) MQTT_CLIENT: Reconnect after 10000 ms
I (3291) MQTT_SAMPLE: MQTT_EVENT_DISCONNECTED

TRANS_SSL: mbedtls_ssl_handshake returned -0x2700

Hi I am trying to connect to my mqtt broker using SSL. I am copying my certificates directly to the code just for testing:

const char* raspberrypi_pem=
//next server certificate of my raspberrypi 192_mqtt_srv.crt
"-----BEGIN CERTIFICATE-----\n"
"MIIDlDCCAnwCCQDokqMaDCZuYzANBgkqhkiG9w0BAQsFADCBizELMAkGA1UEBhMC\n"
...TRUNCATED...
"/wNyf821mrUkNOqo8yH1KN21qJkJQb3hbbmHlEuw2DSKdMAZDTDb7NcH89kYPVWf\n"
"b+jcOvfgFW8=\n"
"-----END CERTIFICATE-----\n"
//next server key from my pi 192_mqtt_server.key
"-----BEGIN RSA PRIVATE KEY-----\n"
"MIIEogIBAAKCAQEAxnBrr2URRKS4qTlBW1nq4hW3/DOC51ukUZVKCg4w8B8uhWgB\n"
...TRUNCATED...
"vm4b5eTD59jUGQMMT66wiSUc0VaPeFkWZc6H48aLBkih0QljoMGA5udejXCZoMIU\n"
"xtg+Elmrwp+6Li/BjtpLie+xJYHWFRwqk+NupXzLiIz/F+VULtY=\n"
"-----END RSA PRIVATE KEY-----\n"
//next CA root certificate from my raspberrypi: 192_mqtt_ca.crt
"-----BEGIN CERTIFICATE-----\n"
"MIID7jCCAtagAwIBAgIJALRpVJTQuFNvMA0GCSqGSIb3DQEBCwUAMIGLMQswCQYD\n"
...TRUNCATED...
"2w3jmt1V5v9HsST/CYoBzAgMe9oylpr7miJF1e1iB3tdNTGqrprZAi+wMWydHTDc\n"
"do0=\n"
"-----END CERTIFICATE-----\n";

I cat contents of the files the server certificate, server key and mqtt ca certificate to create variable raspberrypi_pem. I used same approach with Adafruit MQTT examples and the same ESP32 dev module.

Next I call the raspberrypi const char definition:

const esp_mqtt_client_config_t mqtt_cfg = { .uri = "mqtts://192.168.0.16:8883", .event_handle = mqtt_event_handler, //.cert_pem = (const char *)iot_eclipse_org_pem_start, .cert_pem = raspberrypi_pem, };

Fom the console I getting this message:

W (107474) MQTT_CLIENT: Connection refused, not authorized

From my mqtt broker's log I see this:

1526754871: Sending CONNACK to 192.168.0.33 (0, 5)
1526754871: Socket error on client , disconnecting

Thank you.

Changing config values

I see that Kconfig was removed. Is there currently a good way to modify config values without changing the espmqtt source?

Auto-reconnect leaks memory

When connection to broker is lost, the library automatically re-connects. Unfortunately we lose about 30 kB of heap here when using SSL. Hope you have a fix for this.

MQTT_EVENT_PUBLISHED event not firing

First found in my own program, I have identified a bug which can be reproduced using the mqtt_tcp example. This event doesn't fire:

   58         case MQTT_EVENT_PUBLISHED:
   59             ESP_LOGI(TAG, "MQTT_EVENT_PUBLISHED, msg_id=%d", event->msg_id);
   60             break;

Subscribing to relevant mqtt topic shows that data packets do flow to their correct locations; it's just the event that isn't firing.

I (4170) MQTT_SAMPLE: MQTT_EVENT_SUBSCRIBED, msg_id=63326
I (4180) MQTT_SAMPLE: sent publish successful, msg_id=0
D (4190) MQTT_CLIENT: msg_type=11, msg_id=23782
D (4190) MQTT_CLIENT: pending_id=23782, pending_msg_count = 1
D (4200) MQTT_CLIENT: UnSubscribe successful
I (4200) MQTT_SAMPLE: MQTT_EVENT_UNSUBSCRIBED, msg_id=23782

Can't Multiple client in one application

I get the newest code and Clone this component to ESP-IDF project (as submodule).
Then I esp_mqtt_client_init(cfg1), esp_mqtt_client_start(clinet1), then I esp_mqtt_client_init(cfg2), esp_mqtt_client_start(clinet2), cfg1 and cfg2 's event is diff , client_id and uasername di diff but always tell me :
I (5167) MQTT_CLIENT: Sending MQTT CONNECT message, type: 1, id: 0000
E (5167) MQTT_CLIENT: Writing failed, errno= 4
I (5177) MQTT_CLIENT: Error MQTT Connected
I (5177) MQTT_CLIENT: Reconnect after 10000 ms

How can I can use Multiple client in one application?Can U give a example for Multiple client?

MQTT - Unable to send Disconnect ACKs

Hi,

I'm working on research with a PhD student and I need to run an MQTT protocol with Wifi Power Save Mode on the Sparkfun ESP32 Thing board. We are using an unsecured WiFi network and simply connecting to an MQTT broker on a raspberry pi, publishing a message, and disconnecting.

I have been unable to see Disconnect ACKs (using Wireshark). I went through the API and I'm not sure why this is a problem. I can see a Connect Command and ACK and also a publish packet but the Disconnect never happens. This library is based on the lwmqtt and I noticed their header file mentioned the disconnect ack so I assumed this library worked similarly. Am I doing something wrong in my code?

I'm also seeing a ton of out-of-order, dup ack, and acked unseen segment packets. What might be causing that? (I'm still looking into this issue so it might be the fault of my AP or my broker)

Here is my code. I just put the low power WiFi example and the MQTT example together.
https://gist.github.com/Sedwin97/308ab1f562fbd9984a67023ade0c194e

Guru Meditation Error

ESP-idf version- v3.1-dev-239-g1c3dd23f
MQTT server- local mosquitto server

Hello,
I am using mqtt-tcp example and modified it as below:
esp_mqtt_client_config_t mqtt_cfg = { .event_handle = mqtt_event_handler, .host = "192.168.1.9", .port = 1883, .client_id = "mqtt_client_id", .username = "user", .password = "password", .keepalive = 10, .lwt_topic = "/lwt", .lwt_msg = "offline", .lwt_qos = 2, .lwt_retain = 0, };

Its crashing while connecting to server
`
�[0;32mI (137) MQTT_SAMPLE: [APP] Startup..�[0m
�[0;32mI (137) MQTT_SAMPLE: [APP] Free memory: 274420 bytes�[0m
�[0;32mI (147) MQTT_SAMPLE: [APP] IDF version: v3.1-dev-239-g1c3dd23-dirty�[0m
I (187) wifi: wifi firmware version: 403db1d
I (187) wifi: config NVS flash: enabled
I (187) wifi: config nano formating: disabled
�[0;32mI (187) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE�[0m
�[0;32mI (197) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE�[0m
I (227) wifi: Init dynamic tx buffer num: 32
I (227) wifi: Init data frame dynamic rx buffer num: 32
I (227) wifi: Init management frame dynamic rx buffer num: 32
I (237) wifi: wifi driver task: 3ffc08ac, prio:23, stack:4096
I (237) wifi: Init static rx buffer num: 10
I (237) wifi: Init dynamic rx buffer num: 32
I (247) wifi: wifi power manager task: 0x3ffc54ec prio: 21 stack: 2560
�[0;32mI (257) MQTT_SAMPLE: start the WIFI SSID:[ExploreEmbedded] password:[******]�[0m
�[0;32mI (287) phy: phy_version: 366.0, ba9923d, Dec 29 2017, 14:25:06, 0, 0�[0m
I (287) wifi: mode : sta (24:0a:c4:00:20:9e)
�[0;32mI (287) MQTT_SAMPLE: Waiting for wifi�[0m
I (657) wifi: n:3 1, o:1 0, ap:255 255, sta:3 1, prof:1
I (1637) wifi: state: init -> auth (b0)
I (1637) wifi: state: auth -> assoc (0)
I (1647) wifi: state: assoc -> run (10)
I (1717) wifi: connected with ExploreEmbedded, channel 3
I (4647) wifi: pm start, type:0

�[0;32mI (5087) event: sta ip: 192.168.1.10, mask: 255.255.255.0, gw: 192.168.1.1�[0m
D (5087) MQTT_CLIENT: MQTT client_id=mqtt_client_id�[0m
D (5087) TRANSPORT_TCP: [sock=4096],connecting to server IP:192.168.1.9,Port:1883...�[0m
Guru Meditation Error: Core 1 panic'ed (LoadProhibited)
. Exception was unhandled.
Register dump:
PC : 0x400014fd PS : 0x00060d30 A0 : 0x8012d2b0 A1 : 0x3ffc8830
A2 : 0x00000000 A3 : 0xfffffffc A4 : 0x000000ff A5 : 0x0000ff00
A6 : 0x00ff0000 A7 : 0xff000000 A8 : 0x00000000 A9 : 0x3ffc87e0
A10 : 0x00000000 A11 : 0x3f40b597 A12 : 0x3ffc8a74 A13 : 0x3ffae8d8
A14 : 0x00000000 A15 : 0x00000001 SAR : 0x00000004 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xffffffff

Backtrace: 0x400014fd:0x3ffc8830 0x4012d2ad:0x3ffc8840 0x4012eaa9:0x3ffc8b50 0x40083151:0x3ffc8b80 0x4010cb47:0x3ffc8bd0
`

Any helps will be greatly appreciated

SSL Support

I notice the readme says the lib doesnt support, but when I switch it on, messages come through to Azure IotHub fine.

Am I missing something?

race conditions in MQTT_Publish when queue is full

there seems to some kind of race conditions in MQTT_Publish(), happens sometimes when the queue is full.

I have added some debug printing to QUEUE_Puts and QUEUE_Gets:

MQTT_Publish id: 125
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20286/20480)
QUEUE_Puts: failed to add 192 to queue
QUEUE_Puts: queue size(20480/20480)
QUEUE_Gets: removed 192 from queue
QUEUE_Puts: queue size(20176/20480)
QUEUE_Puts: added 192 to queue
QUEUE_Puts: queue size(20371/20480)

[help request]How to send and receive stuff?

Send and Receive

Hello,

first of all thank you for your work!
I am quite new to how networks and MQTT works. So I hope my question isnt too dump.
I know at least the Basics of the freeRTOS and I am aware of the ESP-IDF API. And I think I also got a raw idea how your code Works but I am far away from knowing whats going on there!

My goal is to receive and process a MQTT paket. To do so I tried to understand how the code works.
I try to Start from the TCP Example.

1. Start

I call the Example in a Task, so renamed the app_main and called it mqtt_client

xTaskCreatePinnedToCore(mqtt_client, "MQTT Client", 4000, NULL, 2, NULL, 0);

        while(1){
                printf("main: Idle\n");
                vTaskDelay(1000/portTICK_PERIOD_MS);
        }
        vTaskDelete(NULL);
}

I pretty much left the Example as it is.
Just added a Delay and vTaskDelete() at the end of mqtt_client but it should not reached there.

    while(1){
                vTaskDelay(1000/portTICK_PERIOD_MS);
        }
        vTaskDelete(NULL);
    }

So far so good, I flashed it
the output seems to be okay:

I (0) cpu_start: App cpu up.
I (355) heap_init: Initializing. RAM available for dynamic allocation:
I (362) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (368) heap_init: At 3FFB9148 len 00026EB8 (155 KiB): DRAM
I (374) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (381) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (387) heap_init: At 4008E8EC len 00011714 (69 KiB): IRAM
I (393) cpu_start: Pro cpu start user code
I (76) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
This is ESP32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 0, 4MB external flash
I (83) MQTT_ClIENT: [APP] Startup..
I (93) MQTT_ClIENT: [APP] Free memory: 270276 bytes
I (93) MQTT_ClIENT: [APP] IDF version: v3.1-dev-601-gda278163-dirty
I (133) wifi: wifi firmware version: c202b34
I (133) wifi: config NVS flash: enabled
I (133) wifi: config nano formating: disabled
I (133) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (143) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (173) wifi: Init dynamic tx buffer num: 32
I (173) wifi: Init data frame dynamic rx buffer num: 32
I (173) wifi: Init management frame dynamic rx buffer num: 32
I (173) wifi: wifi driver task: 3ffc18a0, prio:23, stack:4096
I (183) wifi: Init static rx buffer num: 10
I (183) wifi: Init dynamic rx buffer num: 32
I (183) wifi: wifi power manager task: 0x3ffc64e0 prio: 21 stack: 2560
I (193) MQTT_ClIENT: start the WIFI SSID:[Boot] password:[******]
I (273) phy: phy_version: 383.0, 79a622c, Jan 30 2018, 15:38:06, 0, 0
I (273) wifi: mode : sta (24:0a:c4:07:5d:c0)
I (273) MQTT_ClIENT: Waiting for wifi
main: Idle
main: Idle
I (1603) wifi: n:11 0, o:1 0, ap:255 255, sta:11 0, prof:1
I (2583) wifi: state: init -> auth (b0)
I (2583) wifi: state: auth -> assoc (0)
main: Idle
I (2593) wifi: state: assoc -> run (10)
I (2623) wifi: connected with Boot, channel 11
main: Idle
I (3593) event: sta ip: 192.168.2.116, mask: 255.255.255.0, gw: 192.168.2.1
I (3593) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (3743) MQTT_CLIENT: Sending MQTT CONNECT message, type: 1, id: 0000
I (3883) MQTT_ClIENT: MQTT_EVENT_CONNECTED
I (3883) MQTT_ClIENT: sent subscribe successful, msg_id=51413
I (3883) MQTT_ClIENT: sent subscribe successful, msg_id=59147
I (3893) MQTT_ClIENT: sent unsubscribe successful, msg_id=3030
I (4043) MQTT_ClIENT: MQTT_EVENT_SUBSCRIBED, msg_id=51413
I (4043) MQTT_ClIENT: sent publish successful, msg_id=0
I (4193) MQTT_ClIENT: MQTT_EVENT_SUBSCRIBED, msg_id=59147
I (4193) MQTT_ClIENT: sent publish successful, msg_id=0
I (4313) MQTT_ClIENT: MQTT_EVENT_UNSUBSCRIBED, msg_id=3030
I (4443) MQTT_CLIENT: deliver_publish, message_length_read=19, message_length=19
I (4443) MQTT_ClIENT: MQTT_EVENT_DATA
TOPIC=/topic/qos0
DATA=data
main: Idle
I (4663) MQTT_CLIENT: deliver_publish, message_length_read=19, message_length=19
I (4663) MQTT_ClIENT: MQTT_EVENT_DATA
TOPIC=/topic/qos0
DATA=data
main: Idle
I (5593) wifi: pm start, type:0

2. Stuggle

So but my first struggle is "How do is send stuff?" and even more interesting for me atm.
"How do I receive stuff?"

I went through your Code an found the

static esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event)

It has as well as the mqtt_app_start
a line which say // .user_context = (void *)your_context (not exactly but it seems to belong to each other)

But what does that mean exactly?
I need a Struct which exists in esp_mqtt_event_handle_t
and it may carrys my payload? Event If I am right, how do i use it in a good Style?

I also found the function esp_mqtt_client_publish() the Name seems to be the right point to start, but
this function needs a "client" passed, its type is esp_mqtt_client_handle_t this type is also used in the
esp_mqtt_client_init

It says:
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);

But I am a bit confused here, because it seems that I have to Initialize my MQTT Client each time I want to send something?

What ever I think I dont got it right so I would appreciate If some could help me out. What Functions do I have to call or to what do I have to listen If I want to send/receive stuff to an Topic.

thank you,
Greetings

Feature Request: Mqtt Broker(server) running on ESP32 (IDFGH-1213)

hello tuan, Is it possible to implement a mqtt broker/server on ESP32, So that we can run a local broker right from an esp32 and let other esp32 connect to this broker and talk to each other. Further we can also BRIDGE this broker to cloud such as AWS IOT or cloudmqtt. This would be an awesome feature to look forward to.

Last Will delivery fails - info->will_length not populated

Hello,
this is just a small thing - I just looked at the MQTT message file:

    if (info->will_topic != NULL && info->will_topic[0] != '\0')
    {
ESP_LOGW("TAM", "WANT TO APPEND");
ESP_LOGW("TAM", "WANT TO APPEND %s %d", info->will_message, info->will_length);

        if (append_string(connection, info->will_topic, strlen(info->will_topic)) < 0)
            return fail_message(connection);

        if (append_string(connection, info->will_message, strlen(info->will_message)) < 0)
            return fail_message(connection);

ESP_LOGW("TAM", "APPEND DONE");

This version works. However, will_length always is zero, causing the registration of the payload to fail when tested against Mosquitto. I totally suck at GitHub, and thus dont know how to upload a fix - but if anyone of you has problems with the last will not being sent on the ESP32 with Mosquitto, here is the solution...I replaced will_length with strlen blahblah in the second call to append_string.

mbedtls_sha1' is deprecated

components/espmqtt/lib/transport_ws.c: In function 'ws_connect':
components/espmqtt/lib/transport_ws.c:101:5: warning: 'mbedtls_sha1' is deprecated [-Wdeprecated-declarations]
mbedtls_sha1(client_key_b64, (size_t)key_len, valid_client_key);
^
In file included from components/espmqtt/lib/transport_ws.c:10:0:
esp-idf/components/mbedtls/mbedtls/include/mbedtls/sha1.h:300:25: note: declared here
MBEDTLS_DEPRECATED void mbedtls_sha1( const unsigned char *input,

memory leak when initializing SSL

Hi,

I tried out the newest version and I noticed a memory leak :( . the memory leak is when calling mbedtls_ssl_set_hostname in ssl_connect function twice.
After I narrowed down on the problem, I found this issue on ARMmbed/mbedtls :
Mbed-TLS/mbedtls#836.

I am not sure why we call that function , it worked just fine without it before , for my code I just commented out the code and all is good.

BR. Andrei

Only first message processed in multiple PUBLISH messages in single TCP read

I'm still investigating this however it would be good to have a discussion with someone else familiar with the code. I'm not sure what the purpose of the loop in deliver_publish() is. I thought it might be to handle fragmented TCP reads, but the data callback is invoked before any subsequent reads occur. Or perhaps it is to handle multiple Publish Message instances in a single TCP read?

I have a case that fails in the circumstance where multiple Publish Messages are present in a single TCP read. deliver_publish() is called with a total length covering all included messages, but only the first message is processed.

Packet data (two intentionally sent publish messages, that happen to have the same value coincidentally):

0000   24 0a c4 0e 4e f4 b8 27 eb 00 44 6c 08 00 45 00  $...N..'..Dl..E.
0010   00 5c fd 22 40 00 3f 06 58 c5 c0 a8 b2 2c c0 a8  .\."@.?.X....,..
0020   b2 36 07 5b 57 2a eb 45 10 42 00 00 1a 03 50 18  .6.[W*.E.B....P.
0030   72 10 db 3d 00 00 30 18 00 08 78 6d 61 73 2f 72  r..=..0...xmas/r
0040   65 64 30 2e 35 33 33 37 35 35 33 30 32 34 32 39  ed0.533755302429
0050   30 18 00 08 78 6d 61 73 2f 72 65 64 30 2e 35 33  0...xmas/red0.53
0060   33 37 35 35 33 30 32 34 32 39                    3755302429

I've added additional debug to show the values of each variable just after they are set:

[MQTT INFO] Read len 52
[MQTT INFO] msg_type 3, msg_id 0, pending_type 0, pending_id 0
[MQTT INFO] deliver_publish
[MQTT INFO] deliver_publish: length 52
[MQTT INFO] client->mqtt_state.message_length 26
[MQTT INFO] client->mqtt_state.message_length_read 52
[MQTT INFO] event_data.topic_length 8
[MQTT INFO] event_data.data_length 14
[MQTT INFO] total_mqtt_len -12
[MQTT INFO] mqtt_len 14
[MQTT INFO] event_data.data_total_length 65524
[MQTT INFO] event_data.data_offset 0
[MQTT INFO] event_data.data_length 14
[MQTT INFO] Data received: 14/-12 bytes 

Note the negative value of total_mqtt_len and subsequent nonsense value of event_data.data_total_length. The loop only executes once.

If I could better understand the intent of the loop I could look at improving it, however as it stands I don't think it properly handles multiple messages per read, and I'm not sure about fragmented reads either.

capto_capture 2017-12-14_00-15-47_

Buffer overflow in ws_read()

A buffer overflow occurs when a websocket frame is bigger then the receive buffer is received.

len holds the read buffer length. rlen represents the number of bytes read and should be equal or smaller then len. payload_len is extracted out of the received data and is used to process the received data.

However payload_len is never checked against rlen. This results into a buffer overflow when a websocket frame bigger then the receive buffer is received.

msg_id not consistent over multiple MQTT_EVENT_DATA events

When receiving MQTT messages bigger then the receive buffer, one would expect multiple MQTT_EVENT_DATA events with the same msg_id and an increasing current_data_offset.

However only the first MQTT_EVENT_DATA event contains the correct msg_id, subsequent events contain a corrupted msg_id.

The issue is that esp_mqtt_dispatch_event() overwrites msg_id cause it assume that in_buffer contains a MQTT message with header. This is not the case when deliver_publish() requires additional transport_read() calls when it is receiving messages bigger then the read buffer.

Problems with IDF 2.1.1?

This won't be a very useful post I'm sorry. I found many problems began appearing after updating to IDF 2.1.1. Has anyone else tried it?

Sap Leonardo (ssl:// with authentication)

Hi,
Im trying connect with sap leonardo iot platform. It require 3 certificates (CA, cert, key cert). I create single file with 3 certificates (ca+cert+key), but is imposible connect. Config client is:

const esp_mqtt_client_config_t mqtt_cfg = { .uri = "mqtts://iotae-ekt.eu10.cp.iot.sap:8883", .event_handle = mqtt_event_handler, .cert_pem = (const char *)client_pem_start, .client_id = (const char *)client_id };

error message:

`I (101040) event: sta ip: 192.168.43.47, mask: 255.255.255.0, gw: 192.168.43.1
I (101040) MQTTS_SAMPLE: [APP] Free memory: 237468 bytes
I (103320) wifi: pm start, type:0

I (104260) MQTT_CLIENT: Sending MQTT CONNECT message, type: 1, id: 0000
W (104570) MQTT_CLIENT: Connection refused, server unavailable
I (104570) MQTT_CLIENT: Error MQTT Connected
I (104580) MQTT_CLIENT: Reconnect after 10000 ms
I (104580) MQTTS_SAMPLE: MQTT_EVENT_DISCONNECTED
I (127450) MQTT_CLIENT: Sending MQTT CONNECT message, type: 1, id: 0000
W (127770) MQTT_CLIENT: Connection refused, server unavailable
I (127770) MQTT_CLIENT: Error MQTT Connected
I (127770) MQTT_CLIENT: Reconnect after 10000 ms
I (127770) MQTTS_SAMPLE: MQTT_EVENT_DISCONNECTED
`
t
I tried similar code with python paho without problems. The single cert file is included with "COMPONENT_EMBED_TXTFILES"

Please, could you help me?

mqtt_ssl example

Hi,
i tried the mqtt_ssl and mqtt_ssl_mutual_auth examples and they both work correctly.
Then i tried to configure the mqtt_ssl to connect to mqtts://test.mosquitto.org:8883 by downloading the pem CA certificate from here: https://test.mosquitto.org but i have a problem with the server connection.

This is the error:
E (1623211) TRANS_SSL: mbedtls_ssl_handshake returned -0x2700
E (1623221) MQTT_CLIENT: Error transport connect

The same problem also occurs on a mosquitto broker running on my pc with a self-signed CA certificate created by me. If i use mosquitto to publish or subscrive using my self-signed CA certificate it work.

The error -0x2700 is MBEDTLS_ERR_X509_CERT_VERIFY_FAILED but i downloaded it from test.mosquitto web site so i think it's correct

Is there anyone who can tell me where the problem is?

Thanks
Andrea

How is QOS 1 intended to work? (IDFGH-2512)

I can see in the code that when qos 1 is specified, the published message is saved in the mqtt_outbox and/or state pending_message field, and when the ack is received, it is cleared. The problem I'm investigating is how to handle mqtt disconnects, ostensibly because of networking problems. That is, a few messages are undelivered because the transport failed, we are notified of the mqtt_disconnect, and so we tear down and rebuild the connection. At this point, I would like to retry sending un-ack'ed messages.

The way I imagined it would work is some form of retry mechanism on pending messages (for QOS1) (e.g. on reconnection), but don't see that in the code anywhere. Given that the topic is not saved with the outbox item, or anywhere else, I don't see how a retry could be implemented, even though there is a retry_count field (that seems to not be used). Any guidance is appreciated.

Task watchdog triggered when MQTT_EVENT_DISCONNECTED

My application starts mqtt once on startup.

wifi_init(); // Blocking until connected
mqtt_app_start();

main_loop();

  1. Device is running and connected to wifi and mqtt broker
  2. WiFi AP shutdown.
  3. Getting SYSTEM_EVENT_STA_DISCONNECTED
  4. Wait for lost IP event SYSTEM_EVENT_STA_LOST_IP
  5. Restart Wifi AP.
  6. Event SYSTEM_EVENT_STA_GOT_IP
  7. MQTT_CLIENT: Read error or end of stream
  8. MQTT_EVENT_DISCONNECTED
    Task watchdog got triggered. The following tasks did not feed the watchdog in time:
  • IDLE (CPU 0)
    Tasks currently running:
    CPU 0: mqtt_task

After consecutive watchdog triggered system seems to restart and MQTT connection reestablished
Connection to broker restored and communication continues.

Is there any way to manually restart mqtt to prevent watchdog timeout? As I see it the client connection needs to be restarted after IP connection lost. Is there any other garbage collection that needs to be done?

Following a detailed log:

....... everything is running smooth ...........
I (31472) DB: MQTT_EVENT_DATA /dbnode/labrat/register/1 2200
I (31860) wifi: state: run -> auth (3c0)
I (31861) wifi: n:3 0, o:3 1, ap:255 255, sta:3 1, prof:1
I (31862) wifi: pm stop, total sleep time: 0/26954813

I (31864) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (34280) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (36692) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (39103) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (41514) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (43926) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (46337) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (48748) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (51160) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (53571) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (55982) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (58394) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (60806) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (63217) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (65629) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (68040) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (70452) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (72863) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (75275) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (77686) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (80097) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (82509) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (84920) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (87332) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (89743) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (92154) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (94566) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (96977) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (99388) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (101799) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (104211) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (106622) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (109033) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (111444) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (113856) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (116267) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (118678) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (121090) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (123501) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (125912) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (128324) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (130735) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (133147) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (135558) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (137969) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (140381) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (142792) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (145204) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (147615) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (150024) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (151967) event: station ip lost
I (151967) WIFI_EVENT: SYSTEM_EVENT_STA_LOST_IP
I (152434) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (154844) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
E (156042) MQTT_CLIENT: Error write data or timeout, written len = 0
E (156042) MQTT_CLIENT: Error to public data to topic=/dbnode/labrat/register/1, qos=0
I (157253) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (159663) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
E (160925) MQTT_CLIENT: Error write data or timeout, written len = 0
E (160925) MQTT_CLIENT: Error to public data to topic=/dbnode/labrat/watchdog, qos=0
I (162072) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (164482) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
E (166047) MQTT_CLIENT: Error write data or timeout, written len = 0
E (166047) MQTT_CLIENT: Error to public data to topic=/dbnode/labrat/register/2, qos=0
I (166891) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (169301) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (171710) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (174119) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
E (175929) MQTT_CLIENT: Error write data or timeout, written len = 0
E (175929) MQTT_CLIENT: Error to public data to topic=/dbnode/labrat/watchdog, qos=0
E (176052) MQTT_CLIENT: Error write data or timeout, written len = 0
E (176052) MQTT_CLIENT: Error to public data to topic=/dbnode/labrat/out, qos=0
I (176529) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (178939) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (181349) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (183758) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
E (186057) MQTT_CLIENT: Error write data or timeout, written len = 0
E (186057) MQTT_CLIENT: Error to public data to topic=/dbnode/labrat/register/1, qos=0
I (186167) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (188577) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
E (190933) MQTT_CLIENT: Error write data or timeout, written len = 0
E (190933) MQTT_CLIENT: Error to public data to topic=/dbnode/labrat/watchdog, qos=0
I (190986) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (193395) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
E (195474) MQTT_CLIENT: Error write data or timeout, written len = 0
E (195474) MQTT_CLIENT: Error sending ping
I (195805) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
E (196062) MQTT_CLIENT: Error write data or timeout, written len = 0
E (196062) MQTT_CLIENT: Error to public data to topic=/dbnode/labrat/register/2, qos=0
I (198214) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (200624) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (203033) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (205442) WIFI_EVENT: SYSTEM_EVENT_STA_DISCONNECTED
I (205564) wifi: n:3 1, o:3 0, ap:255 255, sta:3 1, prof:1
I (205565) wifi: state: auth -> auth (b0)
I (205568) wifi: state: auth -> assoc (0)
I (205574) wifi: state: assoc -> run (10)
I (205593) wifi: connected with MySSID, channel 3
E (205937) MQTT_CLIENT: Error write data or timeout, written len = 0
E (205937) MQTT_CLIENT: Error to public data to topic=/dbnode/labrat/watchdog, qos=0
E (206068) MQTT_CLIENT: Error write data or timeout, written len = 0
E (206068) MQTT_CLIENT: Error to public data to topic=/dbnode/labrat/out, qos=0
I (208574) wifi: pm start, type:0

I (209694) event: sta ip: 172.16.2.200, mask: 255.255.255.0, gw: 172.16.2.254
I (209694) WIFI_EVENT: SYSTEM_EVENT_STA_GOT_IP
E (211131) MQTT_CLIENT: Read error or end of stream
I (211132) DB: MQTT_EVENT_DISCONNECTED
Task watchdog got triggered. The following tasks did not feed the watchdog in time:

  • IDLE (CPU 0)
    Tasks currently running:
    CPU 0: mqtt_task
    E (220942) MQTT_CLIENT: Error write data or timeout, written len = 0
    E (220942) MQTT_CLIENT: Error to public data to topic=/dbnode/labrat/watchdog, qos=0
    Task watchdog got triggered. The following tasks did not feed the watchdog in time:
  • IDLE (CPU 0)
    Tasks currently running:
    CPU 0: mqtt_task
    E (221136) MQTT_CLIENT: Error write data or timeout, written len = 0
    E (221136) MQTT_CLIENT: Error to public data to topic=/dbnode/labrat/register/1, qos=0
    E (221145) MQTT_CLIENT: Client has not connected
    E (221150) MQTT_CLIENT: Client has not connected
    E (221155) MQTT_CLIENT: Client has not connected
    E (221200) MQTT_CLIENT: Client has not connected
    I (221347) DB: MQTT_EVENT_CONNECTED
    I (221445) DB: MQTT_EVENT_SUBSCRIBED, msg_id=2600
    I (224562) DB: MQTT_EVENT_DATA /dbnode/labrat/register/2 2500

Accessing variables for ESP mqtt client struct in the callback functions

Hi,
It might be that my coding style is bad or maybe its some other reason, but I have to get access to the variables in the esp_mqtt_client because I pass that variable around in my functions and use the user context to differentiate between the multiple clients running.
If I compile the library in current form, the linker gives me an error, as it doesnt have access to .c file where that structure is declared.
Is there any reason why you would want the application code to have access to that structure?

Certificate error during SSL handshake. (IDFGH-2822)

Hello,
I'm trying to implement a MQTT node using the mqtt_ssl example. Using the command (as the example said):

openssl s_client -showcerts -connect iot.eclipse.org:8883 </dev/null 2>/dev/null|openssl x509 -outform PEM >iot_eclipse_org.pem

The node doesn't work, but neither with mosquitto_pub:

mosquitto_pub --cafile iot_eclipse_org.pem -h iot.eclipse.org -t "data" -m "2" -p 8883 --tls-version tlsv1.2

Any idea?

Furthermore, in my application, I will use my self-signed certificates using the script of this link. Looks correct.

My mosquitto conf is:

port 8883
allow_anonymous false
password_file /etc/mosquitto/mqtt_passwd.txt
cafile /etc/mosquitto/certs/ca.crt
keyfile /etc/mosquitto/certs/raspberrypi.key
certfile /etc/mosquitto/certs/raspberrypi.crt
tls_version tlsv1.2

The Espressif node conf is:

    const esp_mqtt_client_config_t mqtt_cfg = {
        .uri = "mqtts://192.168.135.157",
	.port = 8883,
	.event_handle = mqtt_event_handler,
        .cert_pem = (const char *)iot_eclipse_org_pem_start, //Updated with README command
	.username = "dismuntel_mqtt",
	.password = "dismuntel_pass",
    };

My server trace:

1540467565: New connection from 192.168.139.236 on port 8883.
1540467566: OpenSSL Error: error:14094412:SSL routines:ssl3_read_bytes:sslv3 alert bad certificate
1540467566: Socket error on client <unknown>, disconnecting.

The node trace:

I (2220) event: sta ip: 192.168.139.236, mask: 255.255.255.0, gw: 192.168.139.1
I (2220) MQTTS_SAMPLE: [APP] Free memory: 236712 bytes
I (2220) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (2470) mbedtls: ssl_tls.c:8021 => handshake
I (2470) mbedtls: ssl_cli.c:3405 client state: 0
I (2470) mbedtls: ssl_tls.c:2751 => flush output
I (2480) mbedtls: ssl_tls.c:2763 <= flush output
I (2480) mbedtls: ssl_cli.c:3405 client state: 1
I (2490) mbedtls: ssl_tls.c:2751 => flush output
I (2490) mbedtls: ssl_tls.c:2763 <= flush output
I (2500) mbedtls: ssl_cli.c:774 => write client hello
I (2510) mbedtls: ssl_tls.c:3180 => write handshake message
I (2510) mbedtls: ssl_tls.c:3337 => write record
I (2520) mbedtls: ssl_tls.c:2751 => flush output
I (2520) mbedtls: ssl_tls.c:2770 message length: 244, out_left: 244
I (2530) mbedtls: ssl_tls.c:2775 ssl->f_send() returned 244 (-0xffffff0c)
I (2540) mbedtls: ssl_tls.c:2803 <= flush output
I (2540) mbedtls: ssl_tls.c:3470 <= write record
I (2550) mbedtls: ssl_tls.c:3314 <= write handshake message
I (2560) mbedtls: ssl_cli.c:1106 <= write client hello
I (2560) mbedtls: ssl_cli.c:3405 client state: 2
I (2570) mbedtls: ssl_tls.c:2751 => flush output
I (2570) mbedtls: ssl_tls.c:2763 <= flush output
I (2580) mbedtls: ssl_cli.c:1499 => parse server hello
I (2580) mbedtls: ssl_tls.c:4305 => read record
I (2590) mbedtls: ssl_tls.c:2532 => fetch input
I (2590) mbedtls: ssl_tls.c:2693 in_left: 0, nb_want: 5
I (2780) mbedtls: ssl_tls.c:2717 in_left: 0, nb_want: 5
I (2780) mbedtls: ssl_tls.c:2718 ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)
I (2780) mbedtls: ssl_tls.c:2738 <= fetch input
I (2780) mbedtls: ssl_tls.c:2532 => fetch input
I (2790) mbedtls: ssl_tls.c:2693 in_left: 5, nb_want: 66
I (2800) mbedtls: ssl_tls.c:2717 in_left: 5, nb_want: 66
I (2800) mbedtls: ssl_tls.c:2718 ssl->f_recv(_timeout)() returned 61 (-0xffffffc3)
I (2810) mbedtls: ssl_tls.c:2738 <= fetch input
I (2820) mbedtls: ssl_tls.c:4379 <= read record
I (2820) mbedtls: ssl_cli.c:1781 server hello, total extension length: 17
I (2830) mbedtls: ssl_cli.c:1970 <= parse server hello
I (2830) mbedtls: ssl_cli.c:3405 client state: 3
I (2840) mbedtls: ssl_tls.c:2751 => flush output
I (2850) mbedtls: ssl_tls.c:2763 <= flush output
I (2850) mbedtls: ssl_tls.c:5440 => parse certificate
I (2860) mbedtls: ssl_tls.c:4305 => read record
I (2860) mbedtls: ssl_tls.c:2532 => fetch input
I (2870) mbedtls: ssl_tls.c:2693 in_left: 0, nb_want: 5
I (2870) mbedtls: ssl_tls.c:2717 in_left: 0, nb_want: 5
I (2880) mbedtls: ssl_tls.c:2718 ssl->f_recv(_timeout)() returned 5 (-0xfffffffb)
I (2890) mbedtls: ssl_tls.c:2738 <= fetch input
I (2890) mbedtls: ssl_tls.c:2532 => fetch input
I (2900) mbedtls: ssl_tls.c:2693 in_left: 5, nb_want: 2742
I (2910) mbedtls: ssl_tls.c:2717 in_left: 5, nb_want: 2742
I (2910) mbedtls: ssl_tls.c:2718 ssl->f_recv(_timeout)() returned 2737 (-0xfffff54f)
I (2920) mbedtls: ssl_tls.c:2738 <= fetch input
I (2950) mbedtls: ssl_tls.c:4379 <= read record
W (3000) mbedtls: ssl_tls.c:5713 x509_verify_cert() returned -9984 (-0x2700)
I (3000) mbedtls: ssl_tls.c:5244 => send alert message
I (3000) mbedtls: ssl_tls.c:3337 => write record
I (3010) mbedtls: ssl_tls.c:2751 => flush output
I (3020) mbedtls: ssl_tls.c:2770 message length: 7, out_left: 7
I (3020) mbedtls: ssl_tls.c:2775 ssl->f_send() returned 7 (-0xfffffff9)
I (3030) mbedtls: ssl_tls.c:2803 <= flush output
I (3030) mbedtls: ssl_tls.c:3470 <= write record
I (3040) mbedtls: ssl_tls.c:5257 <= send alert message
I (3050) mbedtls: ssl_tls.c:5810 <= parse certificate
I (3050) mbedtls: ssl_tls.c:8031 <= handshake
E (3060) esp-tls: mbedtls_ssl_handshake returned -0x2700
I (3060) esp-tls: Failed to verify peer certificate!
I (3070) esp-tls: verification info:   ! The certificate is not correctly signed by the trusted CA
E (3080) esp-tls: Failed to open new connection
E (3080) TRANS_SSL: Failed to open a new connection
E (3090) MQTT_CLIENT: Error transport connect
I (3090) MQTT_CLIENT: Reconnect after 10000 ms
I (3100) MQTTS_SAMPLE: MQTT_EVENT_DISCONNECTED

Thanks for all :)

Request for advice: integrating this library with other FreeRTOS tasks

I note that there are user-configurable read_cb and write_cb pointers in the mqtt_settings struct. Can I assume that you considered a use-case where the MQTT task is required to yield to lower-priority tasks? If so, can I ask for your advice on how you envisioned this working please?

In my case I have two other tasks that need to continue working while the mqtt task is waiting on a read. In addition, one of those tasks must be able to initiate a publish at any time. At the moment, the read() call blocks but does not yield to the other tasks. I'm not yet familiar enough with FreeRTOS/lwip to understand how to avoid this limitation. Do you have any notes or proof-of-concept code for this use case please?

keepalive timeout (IDFGH-2511)

I tried this code and set the CPU FREQ 240MHz, keepalive of esp_mqtt_client_config_t to 120
my problems are:

  1. pingreq sent interval is 60sec instead of 120sec
  2. if WIFI is connected but internet connect failed, it takes more than 30 minutes to find mqtt disconnection (seems found by socket layer instead of MQTT layer)

ESP8266 light sleep: how to get it?

Environment

esp8266ex (ESP-12S)

Application

  • Waiting for incoming MQTT packet to boot the master device, use battery.
  • So deep-sleep is useless, I have to use light-sleep keeping MQTT connection.

Problem Description

  • forced light sleep: ok!, 0.7~0.8mA current, but WIFI have to be disconnected. It is worse than deep-sleep.
  • automatic light sleep: never success!, because I cannot manually halt (control) the CPU while DTIM period.

Dear Espressif!

Please help me!

Receiving large payloads

In order to support OTA firmware updates over MQTT, I need to be able to accept very large payloads. Right now any incoming payload larger than MQTT_BUFFER_SIZE_BYTE results in a crash immediately after receiving the first chunk:

I (172815) HOMIE: MQTT_EVENT_DATA
TOPIC=homie/30aea41b1168/$implementation/ota/firmware/13727f4f93b6e6862bfe16f4894d68a4
DATA=6QECQJzyEEAA8BBAaAUAABAQAABQ9RBAHEsAQMwkAED///8///8PQP9/EED///9f8P//PwAQAAAc4gBAAEoAQExKAEAABwBgAAAAgOgrAEDwMABAoC8AQLcdwQQAEgBgABAA63wSAGASwdAJsfmh/QEpTzhPIeb/KiNLPwxEAeb/wAAAjFIMEoYHAAAAIeH/KQ8oDygCKS8oDygSKT84H4svAd7/wAAADAIdDwix+KESwTAN8AAAABLBwAnx+eH9ASmPKI8i0hApDzLPECgPQqAIAdH/wAAAjEIMEkYuAAAoD4siKQ8MAikfBiUADAIpbwwCKX8yzxgoDwyEAcf/wAAAjDIMIsYjACgPiyIpDyhvKT8MAiJPCCg/McH/JzMEDBIiTwgoPzG//yezDCg/Mb7/JzMEDBIiTwgoPzG8/yezBSKgASJPCDIPCAwSICMwICB0jJIofzgPKiMpD8YGADg/SH8oDwGs/8AAAIxCDDJGCQAAKH84DyojKQ8oHxsiKR8iDxE4HyezAsbX/xGo/yhfPQKgAwAMAh0PCPH44RLBQA3wEsGwAmETwmES0mER4mEQ+fH9ASmPOZ9Jry0B7QIojyAgBMxiKJ8gIAQWQgAMEoYvACGX/yk/KD8LIilPKD+NAgwJgC0l0NkR0NIg0MgRKD9tAgwHYC0l0LcRsLIg0KYRKD/7IiAkQcAiESARwC0BLQIpXzivKD8qIwsyKD8gIGAgIxApDyiPKR8onykvBhYAKC84PwGA/8AAAAF//8AAAIxCDCIGEgAAOF8oH0g/AXH/wAAAjEIMMgYNAAA4XygvSD8Bdv/AAACMQgxCBggAADgfKD8qIykfOC8oPyojKS84Dyg/ICPAKQ8oD1YS+gwCHQ4dDwIhE8IhEtIhEeIhEPjxEsFQDfAAkqCgkBHAAmEn8mEmEPEgIqAJKQ
[...]
I (172915) HOMIE: MQTT_EVENT_DATA
Guru Meditation Error: Core  0 panic'ed (LoadProhibited)
. Exception was unhandled.
Core 0 register dump:
PC      : 0x4000c250  PS      : 0x00060230  A0      : 0x800daab1  A1      : 0x3ffc7d50
A2      : 0x00000000  A3      : 0x00000000  A4      : 0x00000400  A5      : 0x3f400830
A6      : 0x3ffc7d80  A7      : 0xff000000  A8      : 0x80082d98  A9      : 0x3ffc7d20
A10     : 0x00000000  A11     : 0xffffffff  A12     : 0x00000004  A13     : 0x00000001
A14     : 0x00000000  A15     : 0x00000000  SAR     : 0x00000004  EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xffffffff

Backtrace: 0x4000c250:0x3ffc7d50 0x400daaae:0x3ffc7d70 0x400d2c59:0x3ffc8080 0x4010ec0a:0x3ffc80d0 0x4010eeab:0x3ffc8130 0x4010f0d1:0x3ffc8150 0x4010f361:0x3ffc8170 0x4010f51e:0x3ffc81b0 0x4010f6f4:0x3ffc81e0
0x400daaae: _vfprintf_r at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/vfprintf.c:1522

0x400d2c59: printf at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/printf.c:58

0x4010ec0a: homie_handle_mqtt_event at /Users/luke/Code/esp32/esp32-homie-example/components/esp32-homie/./homie.c:25

0x4010eeab: mqtt_event_handler at /Users/luke/Code/esp32/esp32-homie-example/components/esp32-homie/./homie.c:76 (discriminator 1)

0x4010f0d1: esp_mqtt_dispatch_event at /Users/luke/Code/esp32/esp32-homie-example/components/esp32mqtt/./mqtt_client.c:808

0x4010f361: deliver_publish at /Users/luke/Code/esp32/esp32-homie-example/components/esp32mqtt/./mqtt_client.c:808

0x4010f51e: mqtt_process_receive at /Users/luke/Code/esp32/esp32-homie-example/components/esp32mqtt/./mqtt_client.c:808

0x4010f6f4: esp_mqtt_task at /Users/luke/Code/esp32/esp32-homie-example/components/esp32mqtt/./mqtt_client.c:808


Rebooting...

Would it be possible to receive them in multiple chunks, each sized to MQTT_BUFFER_SIZE_BYTE? For example this is how marvinroger/async-mqtt-client does it

This library is not thread-safe and it that should be clear in the docs

Hi,

I was getting error in my MQTT Broker and then I realize that was happening 'cause packets of MQTT are getting mixed together because this library isn't thread-safe and I was using 3 tasks to publish at the same time messages to MQTT. Adding a semaphore fixed the problem. The docs should be clear about that or the thread-safety procedure should be implemented.

multiple definition of `transport_ssl_set_cert_data'

When I fired the command

make flash monitor -j5

And got this error

multiple definition of transport_ssl_set_cert_data

Error log is:

1. AR build/wpa_supplicant/libwpa_supplicant.a
2. LD build/SmartDoorBell.elf
3. D:/Users/hello/esp/hello_world/SmartDoorBell/build/espmqtt\libespmqtt.a(transport_ssl.o): In function `transport_ssl_set_cert_data':
4. D:/msys32/home/hello/esp/esp-idf/components/espmqtt/lib/transport_ssl.c:274: multiple definition of `transport_ssl_set_cert_data'
5. D:/Users/hello/esp/hello_world/SmartDoorBell/build/esp_http_client\libesp_http_client.a(transport_ssl.o):D:/msys32/home/hello/esp/esp-idf/components/esp_http_client/lib/transport_ssl.c:249: first defined here
6. D:/Users/hello/esp/hello_world/SmartDoorBell/build/espmqtt\libespmqtt.a(transport_ssl.o): In function `transport_ssl_init':
7. transport_ssl.c:(.text.transport_ssl_init+0x0): multiple definition of `transport_ssl_init'
8. D:/Users/hello/esp/hello_world/SmartDoorBell/build/esp_http_client\libesp_http_client.a(transport_ssl.o):transport_ssl.c:(.text.transport_ssl_init+0x0): first defined here
9. collect2.exe: error: ld returned 1 exit status
10. make: *** [D:/msys32/home/hello/esp/esp-idf/make/project.mk:407: /d/Users/hello/esp/hello_world/SmartDoorBell/build/SmartDoorBell.elf] Error 1

Only one message received at MQTT start if subscribe multiple retained topics

I used the mqtt_tcp example in the folder and change nothing but added two topics like
"api/v1/devices/5/rules/water"
"api/v1/devices/5/rules/temperature"
default
my server seems normally receiving two SUB request and sending back to ESP ,it always received first topic i subscribed like below
``[0;32mI (3115) MQTT_CLIENT: Sending MQTT CONNECT message, type: 1, id: 0000[0m
[0;32mI (3135) MQTT_SAMPLE: MQTT_EVENT_CONNECTED[0m
[0;32mI (3135) MQTT_SAMPLE: sent subscribe successful, msg_id=4614[0m
[0;32mI (3135) MQTT_SAMPLE: sent subscribe successful, msg_id=30749[0m
[0;32mI (3135) MQTT_SAMPLE: sent subscribe successful, msg_id=55238[0m
[0;32mI (3145) MQTT_SAMPLE: sent unsubscribe successful, msg_id=1965[0m
[0;32mI (3155) MQTT_SAMPLE: MQTT_EVENT_SUBSCRIBED, msg_id=4614[0m
[0;32mI (3155) MQTT_SAMPLE: sent publish successful, msg_id=0[0m
[0;32mI (3165) MQTT_CLIENT: deliver_publish, message_length_read=40, message_length=40[0m
[0;32mI (3175) MQTT_SAMPLE: MQTT_EVENT_DATA[0m
TOPIC=api/v1/devices/5/rules/temperature

DATA=45

[0;32mI (3175) MQTT_SAMPLE: MQTT_EVENT_SUBSCRIBED, msg_id=30749[0m
[0;32mI (3185) MQTT_SAMPLE: sent publish successful, msg_id=0[0m
[0;32mI (3195) MQTT_SAMPLE: MQTT_EVENT_SUBSCRIBED, msg_id=55238[0m
[0;32mI (3195) MQTT_SAMPLE: sent publish successful, msg_id=0[0m
[0;32mI (3205) MQTT_SAMPLE: MQTT_EVENT_UNSUBSCRIBED, msg_id=1965[0m

But i manually pub to ESP it work fine and get both topic back

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.