Giter VIP home page Giter VIP logo

esp-mqtt's People

Contributors

256dpi avatar jpf91 avatar kshyshkin avatar shmuelzon 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

Watchers

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

esp-mqtt's Issues

Initializing NVS before WIFI

Hi Joël,

wifi_init error raises at app_main() in test code;

W (57) wifi: wifi nvs_open fail ret=4353
E (59) wifi: wifi_init 1515 ret=4353

It is required to initialize nvs before wifi init as follows, which worked for me;

esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
  ESP_ERROR_CHECK(nvs_flash_erase());
  ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);

Reference Issue:
espressif/arduino-esp32#761

include string.h missing - memset undefined

CC build/esp-mqtt/esp_lwmqtt.o
In file included from /home/lieven/esp/esp-idf/components/lwip/include/lwip/lwip/netdb.h:39:0,
from /home/lieven/workspace/vertx-esp32/components/esp-mqtt/./esp_lwmqtt.c:1:
/home/lieven/workspace/vertx-esp32/components/esp-mqtt/./esp_lwmqtt.c: In function 'esp_lwmqtt_network_select':
/home/lieven/esp/esp-idf/components/lwip/include/lwip/lwip/sockets.h:441:23: error: implicit declaration of function 'memset' [-Werror=implicit-function-declaration]
#define FD_ZERO(p) memset((void*)(p), 0, sizeof((p)))
^
/home/lieven/workspace/vertx-esp32/components/esp-mqtt/./esp_lwmqtt.c:70:3: note: in expansion of macro 'FD_ZERO'
FD_ZERO(&set);
^
/home/lieven/esp/esp-idf/components/lwip/include/lwip/lwip/sockets.h:441:23: warning: incompatible implicit declaration of built-in function 'memset'
#define FD_ZERO(p) memset((void
)(p), 0, sizeof((p)))
^
/home/lieven/workspace/vertx-esp32/components/esp-mqtt/./esp_lwmqtt.c:70:3: note: in expansion of macro 'FD_ZERO'
FD_ZERO(&set);
^
/home/lieven/esp/esp-idf/components/lwip/include/lwip/lwip/sockets.h:441:23: note: include '<string.h>' or provide a declaration of 'memset'
#define FD_ZERO(p) memset((void
)(p), 0, sizeof(*(p)))
^
/home/lieven/workspace/vertx-esp32/components/esp-mqtt/./esp_lwmqtt.c:70:3: note: in expansion of macro 'FD_ZERO'
FD_ZERO(&set);
^
cc1: some warnings being treated as errors
/home/lieven/esp/esp-idf/make/component_wrapper.mk:273: recipe for target 'esp_lwmqtt.o' failed
make[1]: *** [esp_lwmqtt.o] Error 1
/home/lieven/esp/esp-idf/make/project.mk:450: recipe for target 'component-esp-mqtt-build' failed
make: *** [component-esp-mqtt-build] Error 2

Security features

Hello,

How I can implement some encryption with your code? Unfortunately, there are not some public examples or descriptions for this kind of issue.

Please, give me some point where I can start from. Thanks.

How does it compare to "official" esp-mqtt ?

Since there is already a MQTT client in esp-idf, how does this software compare to the idf's client ?
I'm asking for speed / memory usage / flash size / features numbers here, if you have them.
Thanks!

old version of lwmqtt

Is there a particular reason this is still pulling in lwmqtt 0.7.0? It seems this would benefit from some of the more recent changes (particularly the arbitrary output sizes in 0.8.0).

does this ever vTaskDelay?

Hi,
Does this ever vTaskDelay once successfully connected and then sitting there waiting for data?
I could not track down where it gives up it's timeslice, and did get (once):

Task watchdog got triggered. The following tasks did not reset the watchdog in time:
 - IDLE (CPU 1)
Tasks currently running:
CPU 0: IDLE
CPU 1: esp_mqtt
␛[0;31mE (707191) esp_mqtt: lwmqtt_keep_alive: -13␛[0m

and am having real trouble with mqtt disconnects (-13 and -4).

However, having added

    } else {
      // no data available, so
      // delay loop by 10ms and yield to other processes
      vTaskDelay(10 / portTICK_PERIOD_MS);
    }

on the end of if (available), I now longer get any regular mqtt disconnects....

s

Installation help

I'm not that familiar with platformio, so I would like more explicit installation instructions -- should I be adding the contents of this repo to ~/.platformio/packages/framework-espidf/components/esp-mqtt?

MQTT connection works, publish fails - v0.4.4 OK, v 0.5.1 FAILS

Connecting to my own mosquitto server or test.mosquitto.org works, but publishing fails with lwmqtt_yield = -4.

I|3090 esp32-2 -| Wifi.cpp: 26 | wifi event : 7
I|3091 esp32-2 -| EventBus.cpp: 64 | publish event : 'wifi/connected'
I|3098 esp32-2 -| LedBlinker.cpp: 33 | led1 => interval : 1000
I (3269) esp_mqtt: esp_mqtt_start: create task
I (3269) esp_mqtt: esp_mqtt_process: begin connection attempt
I (3319) esp_mqtt: esp_mqtt_process: connection attempt successful
I|3161 esp32-2 -| EventBus.cpp: 64 | publish event : 'mqtt/connected'
E (5479) esp_mqtt: lwmqtt_yield: -4
I (5479) esp_mqtt: esp_mqtt_process: exit task
W (5479) esp_mqtt: esp_mqtt_publish: not connected
I|5325 esp32-2 -| EventBus.cpp: 64 | publish event : 'mqtt/disconnected'
I|5325 esp32-2 -| EventBus.cpp: 64 | publish event : 'mqtt/disconnected'E|5327 esp32-2 -| Mqtt.cpp: 135 | mqtt publish failed : src/esp32-2/system/lowestStack size:1
I (5509) esp_mqtt: esp_mqtt_start: create task
I (5509) esp_mqtt: esp_mqtt_process: begin connection attempt
I (5539) esp_mqtt: esp_mqtt_process: connection attempt successful
I|5380 esp32-2 -| EventBus.cpp: 64 | publish event : 'mqtt/connected'
I (5649) wifi: pm start, type:0

E (7549) esp_mqtt: lwmqtt_yield: -4
I (7549) esp_mqtt: esp_mqtt_process: exit task
W (7549) esp_mqtt: esp_mqtt_publish: not connected
I|7394 esp32-2 -| EventBus.cpp: 64 | publish event : 'mqtt/disconnected'
I|7394 esp32-2 -| EventBus.cpp: 64 | publish event : 'mqtt/disconnected'E|7397 esp32-2 -| Mqtt.cpp: 135 | mqtt publish failed : src/esp32-2/now size:1
I (7569) esp_mqtt: esp_mqtt_start: create task
I (7579) esp_mqtt: esp_mqtt_process: begin connection attempt
I (7599) esp_mqtt: esp_mqtt_process: connection attempt successful
I|7440 esp32-2 -| EventBus.cpp: 64 | publish event : 'mqtt/connected'
E (9689) esp_mqtt: lwmqtt_yield: -4
I (9689) esp_mqtt: esp_mqtt_process: exit task
I|9530 esp32-2 -| EventBus.cpp: 64 | publish event : 'mqtt/disconnected'

void Mqtt::publish(const char *topic, uint8_t *payload, size_t len, int qos, bool retained) { if ( ! _mqttConnected ) return; if (!esp_mqtt_publish(topic, payload, len, qos, retained)) { ERROR(" mqtt publish failed : %s size:%d ", topic, len); esp_mqtt_stop(); esp_mqtt_start(_host.c_str(), "1883", _clientId.c_str(), _user.c_str(), _password.c_str()); } else { INFO(" published %s", topic); } }

example

Hello.

Thank you for your good work.
Have you any example of using your component?

assertion "netconn state error" in lwip when iterating a 2nd time through MQTT Start, Publish, Stop

We would like to use your library on ESP32 MCU's with the latest ESP-IDF to send sensor data every 15 minutes to a MQTT Server. The programme will establish each time a Wifi connection, and make the MQTT connection, and publish its metrics using MQTT, and then end the MQTT connection and the Wifi connection.

This works fine for the 1st iteration but during the 2nd iteration it crashes the program consistently.

Sequence:
Start Wifi
esp_mqtt_start()
esp_mqtt_publish()
esp_mqtt_stop()
Stop Wifi
[wait 15 minutes in Production]
Start Wifi
esp_mqtt_start()
esp_mqtt_publish()
=> crash

The following thread stack is about the modules lwip and tcpip_adapter and these are triggered by this esp-mqtt library. The last significant log messages (a full coredump does not show more thread stack information unfortunately):

assertion "netconn state error" failed: file "C:/myiot/esp/esp-idf/components/lwip/api/api_msg.c", line 1055, function: lwip_netconn_do_delconn
abort() was called at PC 0x400d2ad7 on core 0

0x400d2ad7: __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdlib/
../../../.././newlib/libc/stdlib/assert.c:63 (discriminator 8)

Backtrace: 0x4008c478:0x3ffbdb20 0x4008c61b:0x3ffbdb40 0x400d2ad7:0x3ffbdb60 0x4011ea47:0x3ffbdb90 0x4010fda5:0x3ffbdbb0
0x4008c478: invoke_abort at C:/myiot/esp/esp-idf/components/esp32/panic.c:648

0x4008c61b: abort at C:/myiot/esp/esp-idf/components/esp32/panic.c:648

0x400d2ad7: __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdlib/
../../../.././newlib/libc/stdlib/assert.c:63 (discriminator 8)

0x4011ea47: lwip_netconn_do_delconn at C:/myiot/esp/esp-idf/components/lwip/api/api_msg.c:1881 (discriminator 6)

0x4010fda5: tcpip_thread at C:/myiot/esp/esp-idf/components/lwip/api/tcpip.c:474

CPU halted.

The program works fine when keeping the Wifi logic but removing the MQTT logic.

A reproducible ESP-IDF project can be found at https://github.com/pantaluna/support_esp_mqtt
@Important The instructions and the full make-monitor-logs are in the README.md

Thanks for your help.

Feature: add event ESP_MQTT_STATUS_STOPPED

This is a feature request.

Environment: branch idf3.

Sometimes we do multiple iterations of esp_mqtt_start() esp_mqtt__publish() esp_mqtt__stop() sequences in the same program; either to save resources or when we need to publish to multiple MQTT servers.

For the moment the library has no MQTT status event in mqtt_status_callback() to signal when the func esp_mqtt__stop() has done its work; e.g. the main mqtt task has been deleted etcetera. So in the calling program we have to, for example, clear an MQTT_CONNECTED_BIT manually every time after calling the esp_mqtt__stop() method.

It would be cleaner if the mqtt_status_callback() would provide a status event when stopped() has really finished, for example ESP_MQTT_STATUS_STOPPED. The idea is similar to how the existing ESP_MQTT_STATUS_CONNECTED event works.

Note: the event ESP_MQTT_STATUS_DISCONNECTED already exists but it seems to have another purpose (when an existing connection has been aborted/disconnected unintentionally for whatever reason, opposed to being stopped specifically).

Please check with the project https://github.com/pantaluna/support_esp_mqtt for inspiration (I changed it for this issue).

esp_mqtt: lwmqtt_connect: -5 with mosquitto broker

Hi, first off, thanks so much for the work, it is much appreciated.

I managed to get this library to work with the shiftr.io MQTT broker and now I wanted to use my own broker, however I keep getting this error when I try and connect:

I (19834) esp_mqtt: esp_mqtt_process: begin connection attempt
E (20094) esp_mqtt: lwmqtt_connect: -5
W (20094) esp_mqtt: esp_mqtt_process: connection attempt failed

And on the mosquitto log, it shows:

mqtt    | 1521896205: New connection from 177.97.217.166 on port 1883.
mqtt    | 1521896205: Socket error on client <unknown>, disconnecting.

How can I debug this? It seems error -5 is: LWMQTT_NETWORK_FAILED_READ

It it works with shiftr.io brokers, it must be some broker-side configuration I need to change... My mosquitto.conf file is very simple:

pid_file /var/run/mosquitto.pid

persistence false
persistence_location /mqtt/data/

user mosquitto
allow_anonymous true

# Port to use for the default listener.
port 1883

log_dest file /mqtt/log/mosquitto.log
log_dest stdout

include_dir /mqtt/config/conf.d

esp-open-rtos: Not able to publish from another task

Hi All,

I have created following task:

xTaskCreate(&wifi_task, "wifi_task", 256, NULL, 2, NULL);
xTaskCreate(&mqtt_task, "mqtt_task", 2048, NULL, 2, NULL);
xTaskCreate(buttonPollTask, "buttonPollTask", 1048, NULL, 2, NULL);

I have initialize aws mqtt from task mqtt_task and trying to publish data from another task buttonPollTask. I have taken mqtt_client_t as a static global but unfortunately, failed to publish. It's not even connected.

But if i create only one task mqtt_task then it is publishing perfectly with the static global mqtt_client_t.

can anyone help in this case?

Thanks in advance.

components/freertos/./tasks.c:1066 (prvAddNewTaskToReadyList)- assert failed!

I got the below error message. Could this be related to this issue : espressif/arduino-esp32#749 ?

I (4220) esp_mqtt: esp_mqtt_start: create task
/home/lieven/esp/esp-idf/components/freertos/./tasks.c:1066 (prvAddNewTaskToReadyList)- assert failed!
abort() was called at PC 0x40085782 on core 0

Backtrace: 0x40088078:0x3ffc2640 0x40088177:0x3ffc2660 0x40085782:0x3ffc2680 0x400858ea:0x3ffc26a0 0x40124a3e:0x3ffc26e0 0x40109911:0x3ffc2710 0x40121161:0x3ffc2730 0x40108410:0x3ffc2750 0x4010804a:0x3ffc2770 0x400d0e2e:0x3ffc2790

assert failed!. Why is task pinned to core 1?

Had the 'assert failed!' issue when esp_mqtt_start was called.

Was wondering what the rationale is for pinning to core 1. You might want to change so that either core (or no core) can be defined. Easy enough for me to change but I hate modifying libraries since it makes maintenance much more difficult.

Issues compiling library

I'm using eclipse (linux) and c++. Installed library in project components folder with
git clone --recursive https://github.com/256dpi/esp-mqtt.git

I'm assuming this is an installation/config issue but I have not had problems with component libraries in the past.

Any suggestions would be appreciated
compile errors...
/home/rick/eclipse-test/OldOrb/build/main/libmain.a(wifiMqtt.o):(.literal._Z15status_callback17esp_mqtt_status_t+0x10): undefined reference to esp_mqtt_subscribe(char const*, int)' /home/rick/eclipse-test/OldOrb/build/main/libmain.a(wifiMqtt.o):(.literal._ZN8wifiMqtt9mqttInit1Ev+0x18): undefined reference to esp_mqtt_init(void ()(esp_mqtt_status_t), void ()(char const*, unsigned char*, unsigned int), unsigned int, int)'
/home/rick/eclipse-test/OldOrb/build/main/libmain.a(wifiMqtt.o):(.literal._ZN8wifiMqtt9mqttInit1Ev+0x1c): undefined reference to esp_mqtt_start(char const*, int, char const*, char const*, char const*)' /home/rick/eclipse-test/OldOrb/build/main/libmain.a(wifiMqtt.o): In function status_callback(esp_mqtt_status_t)':
/home/rick/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/bits/char_traits.h:243: undefined reference to esp_mqtt_subscribe(char const*, int)' /home/rick/esp/esp-idf/make/project.mk:387: recipe for target '/home/rick/eclipse-test/OldOrb/build/oldorb.elf' failed /home/rick/eclipse-test/OldOrb/build/main/libmain.a(wifiMqtt.o): In function wifiMqtt::mqttInit1()':
/home/rick/eclipse-test/OldOrb/main/./wifiMqtt.cpp:61: undefined reference to esp_mqtt_init(void (*)(esp_mqtt_status_t), void (*)(char const*, unsigned char*, unsigned int), unsigned int, int)' /home/rick/eclipse-test/OldOrb/main/./wifiMqtt.cpp:62: undefined reference to esp_mqtt_start(char const*, int, char const*, char const*, char const*)'

Support multiple instances in parallel

Hi,

I'd like to be able to have multiple instances of the esp-mqtt client running in parallel.
Adding this support seems simple enough, as the lwmqtt library and the connection support code here already seems to handle multiple instances just fine. So I likely only need to change esp_mqtt.c.

Before I make those changes in esp_mqtt.c and open a pull request, I'd like to ask for some quick feedback:

  • I guess you want to keep backwards compatibility? So current dunctions should be kept and should probably forward to the new functions, using a single global client instance?
  • How should I name the new functions? Those will mirror the current function API 1:1 but take an additional context argument as first parameter. Just add 2 to the function names?

Can't Sub or Pub

So I tried following the Test code on the repo, but I just can't seem to Pub or Sub. Connecting works fine. I can confirm that I am indeed connected to the broker.

static void process()
{
    esp_mqtt_subscribe(Mytopic, 0);
while(1)
    {
        esp_mqtt_publish(Mytopic, (uint8_t *)"world", 5, 2, false);
        vTaskDelay(1000/portTICK_PERIOD_MS);
    }

}

//MQTT MESSAGE CALLBACK
static void message_callback(const char *topic, uint8_t *payload, size_t len)
{
   // printf("incoming: %s => %s (%d) \n", topic, payload, (int)len);
   printf("Message Received \n");
}

static void status_callback(esp_mqtt_status_t status)   
{
    switch(status)
    {
        case ESP_MQTT_STATUS_CONNECTED: //I commented the code in here because I thought the callback wasnt working. The printf doesn't fire
            printf("Attempting to subscribe and run the process \n");
            //esp_mqtt_subscribe(Mytopic, 0);
            //xTaskCreatePinnedToCore(process, "process", 1024, NULL, 10, &task,1);
            break;
        case ESP_MQTT_STATUS_DISCONNECTED:
           // vTaskDelete(task);
           printf("MQTT Disconnected");
    }
}

void app_main(){
esp_mqtt_init(message_callback,status_callback,buffer_size, command_timeout);
xTaskCreate(process,"process",1024,NULL,2,&task);
}

You can find the full code here

Query: esp_mqtt_start API

If I do not use server-side username and password? In the parameters ... const char * username and const char * password of the function esp_mqtt_start (....) should I send a NULL?

Connection loss after a few seconds

I am trying to use this lib in a C++ project.

I am able to build my project and connect to my broker. But after a few seconds my ESP disconnects from the broker.

In my terminal I can see some debug messages. The last two are

esp_mqtt: esp_lwmqtt_network_peek: -5
esp_mqtt: esp_mqtt_process: exit task

My code is inspired by the example.

  • First I setup my ESP and my WiFi.
  • Then i call esp_mqtt_init:

esp_mqtt_init(status_callback, message_callback, 256, 10);

Where status_callback is:

static void status_callback(esp_mqtt_status_t status)

{
    switch (status) 
    {
        case ESP_MQTT_STATUS_CONNECTED:
            printf("mqtt connected\n");
            break;
        case ESP_MQTT_STATUS_DISCONNECTED:
            printf("mqtt disconnected\n");
            esp_mqtt_start(MQTT_HOST, MQTT_PORT, "esp_mqtt_client", MQTT_USER, MQTT_PASS);
            break;
    }
}

My message_callback function is even simpler:

static void message_callback(const char *topic, uint8_t *payload, size_t len) 
{
    printf("incoming: %s => %s (%d)\n", topic, payload, (int)len);
}
  • As soon as the ESP is connected to the WiFi esp_mqtt_start is executed:
static esp_err_t event_handler(void *ctx, system_event_t *event)
{
    if (event->event_id == SYSTEM_EVENT_STA_GOT_IP)
    {
        esp_mqtt_start(MQTT_HOST, MQTT_PORT, "esp_mqtt_client", MQTT_USER, MQTT_PASS);
    }
    return ESP_OK;
}

This works so far. I can even publish a message in my status_callback function.
But after a short delay I get the described error messages:

esp_mqtt: esp_lwmqtt_network_peek: -5
esp_mqtt: esp_mqtt_process: exit task

My status_callback function reconnects the ESP after the connection is lost, but the same thing happens again.

I use a mosca broker on a local machine. All other devices I tested so far can connect to this broker. When the connection is lost the broker log tells me something about a keepalive timeout.

Thanks for the lib so far and thanks in advance for the help.

Error -6 and -13 on sending larger (up to 37kB) chunks of data

I'm sending data with up to 37kB (a jpg picture) to a mosquitto-broker. Before each such package I send a timestemp with 5bytes. The timestamp always reaches the broker while the picture only sometimes gets sent.
When the picture doesn't get sent succesfully I get this error:

E (52275) esp_mqtt: lwmqtt_publish: -6

Occasionally I get

Task watchdog got triggered. The following tasks did not reset the watchdog in time:
 - IDLE (CPU 1)
Tasks currently running:
CPU 0: IDLE
CPU 1: esp_mqtt
E (75785) esp_mqtt: lwmqtt_keep_alive: -13

directly after I tried to send the picture and it failed and sometimes the error 13 just gets thrown randomly without any traffic happening (mosquitto is of course still running to handle the pings).
The third error I noticed is an error on reconnect:

I (75795) esp_mqtt: esp_mqtt_process: begin connection attempt
Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x40136893  PS      : 0x00060e30  A0      : 0x801325b1  A1      : 0x3ffe1290
A2      : 0xffffffff  A3      : 0x00009088  A4      : 0x00000010  A5      : 0x00000000
A6      : 0x0000abab  A7      : 0x00000038  A8      : 0x3ffe12bc  A9      : 0x00000000
A10     : 0x00001dd8  A11     : 0x3ffc13cc  A12     : 0x00000000  A13     : 0x00000001
A14     : 0x0000abab  A15     : 0x00000000  SAR     : 0x0000001c  EXCCAUSE: 0x0000001d
EXCVADDR: 0x00000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0x00000000

Backtrace: 0x40136893:0x3ffe1290 0x401325ae:0x3ffe12b0 0x40132384:0x3ffe1300 0x400d3bcd:0x3ffe1350

Rebooting...

The buffer size given to esp_mqtt_init is 37kB and the timeout 15000ms. I regularly check wether the heap has large enough blocks to handle the data and there are always blocks left with >60kB.

My code can be found at repository.

Max library MQTT message recieve size?

Hi :)

I am using Mosquitto (V.1.14) as an MQTT broker. From the broker, if i am sending a string longer than 236 char in length to a topic which my ESP32 is subscribed it makes the MQTT client on ESP32 disconnect
(lwmqtt_yield -1).

Is this normal? If it would be normal my understanding is that the lwmqtt max buffer size is 256 bytes so 236 bytes for data and 20 bytes for message header. Is this a problem from my side or the library is limited in terms of data size recieved bigger than 236 bytes?

See attached picture for ESP32 logging.

*I am using almost the exact code as the example provided in the repo. On the image provided, you can see recieved message size in parentheses ( ). It crashes (lwmqtt_yield -1) when i send a message of 237 bytes in length.

Regards,
ogensyts

espmqtt

"esp_mqtt: lwmqtt_publish: -4" when sending larger chunks of data

So I'm trying to send two kinds of mqtt messages, using your library and a mosquitto broker. I always send a timestamp with 6 bytes to one topic followed by another publish with a picture and up to 37kB. While the small publish with the timestamp always sucedes the publish with the picture randomly fails.
Taking a look at Wireshark I can see the first incoming TCP-segments of the published picture but then the stream suddenly stops and never gets finished. The ESP32 gives out the error esp_mqtt: lwmqtt_publish: -4.
The attached zip file containt a Wireshark capture. Filtering it by ip.addr ==192.168.178.20 reveales three cycles. The first with a successful publish of timestamp and picture. The second with a successful publish of the timestamp but a failed publish of the picture (TCP-stream randomly gets interrupted before it transmitted all the data; lwmqtt_publish: -4 error was thrown; reconnect of broker and client). The third shows another successfull publish of timestamp and picture.
lwmqtt_publish_-4.zip

At the moment I am a little helpless about where to search for the error but your mqtt libraries.

The project can be found at https://github.com/Thomseeen/Summerschool.MQTT_Doorbell_Demo.

Reconnect after lost connection

Trying to figure out where my mqtt connection stability is failing and wondering if its at the broker and not the esp32 code. I get mqtt disconnect callbacks every few hours. I've got a monitor task that checks whether mqtt is connected (flag set by mqtt status callback) and, if not, calls esp_mqtt_start. I'm wondering if this is the correct logic. I'm also logging whether or not my wifi connection is failing and that does not seem to be the case.

  • should I be destroying (esp_mqtt_stop?) before trying to re-start?
  • is reconnect logic built into the library

This is the list of messages I'm logging on a regular basis...
I (41036017) wifiMqtt: ESP_MQTT_STATUS_DISCONNECTED
I (41036032) esp_mqtt: esp_mqtt_start: create task
I (41036033) esp_mqtt: esp_mqtt_process: begin connection attempt
I (41036307) esp_mqtt: esp_mqtt_process: connection attempt successful
W (41036307) esp_mqtt: esp_mqtt_start: already running
I (41036308) wifiMqtt: ESP_MQTT_STATUS_CONNECTED
E (42251281) esp_mqtt: lwmqtt_keep_alive: -13
I (42251284) esp_mqtt: esp_mqtt_process: exit task
I (42251284) wifiMqtt: ESP_MQTT_STATUS_DISCONNECTED

Every once in awhile, the log pattern looks like this...
E (29620650) esp_mqtt: lwmqtt_connect: -9
W (29620651) esp_mqtt: esp_mqtt_start: already running
W (29620651) esp_mqtt: esp_mqtt_process: connection attempt failed
W (29620751) esp_mqtt: esp_mqtt_start: already running
W (29620852) esp_mqtt: esp_mqtt_start: already running
W (29620952) esp_mqtt: esp_mqtt_start: already running
W (29621052) esp_mqtt: esp_mqtt_start: already running
W (29621152) esp_mqtt: esp_mqtt_start: already running
W (29621252) esp_mqtt: esp_mqtt_start: already running
W (29621352) esp_mqtt: esp_mqtt_start: already running
W (29621453) esp_mqtt: esp_mqtt_start: already running
W (29621554) esp_mqtt: esp_mqtt_start: already running
W (29621654) esp_mqtt: esp_mqtt_start: already running
I (29621654) esp_mqtt: esp_mqtt_process: begin connection attempt
I (29621891) esp_mqtt: esp_mqtt_process: connection attempt successful
W (29621892) esp_mqtt: esp_mqtt_start: already running
I (29621892) wifiMqtt: ESP_MQTT_STATUS_CONNECTED
E (31869026) esp_mqtt: lwmqtt_keep_alive: -13
I (31869029) esp_mqtt: esp_mqtt_process: exit task
I (31869030) wifiMqtt: ESP_MQTT_STATUS_DISCONNECTED
I (31869031) wifiMqtt: CAN'T PUBLISH MQTT - not connected
I (31869093) esp_mqtt: esp_mqtt_start: create task
I (31869094) esp_mqtt: esp_mqtt_process: begin connection attempt
I (31873966) esp_mqtt: esp_mqtt_process: connection attempt successful
W (31873966) esp_mqtt: esp_mqtt_start: already running
I (31873966) wifiMqtt: ESP_MQTT_STATUS_CONNECTED
E (31875971) esp_mqtt: lwmqtt_subscribe_one: -9
E (33849447) esp_mqtt: lwmqtt_keep_alive: -13
I (33849450) esp_mqtt: esp_mqtt_process: exit task
I (33849451) wifiMqtt: ESP_MQTT_STATUS_DISCONNECTED
I (33849455) wifiMqtt: CAN'T PUBLISH MQTT - not connected
I (33849467) esp_mqtt: esp_mqtt_start: create task
I (33849468) esp_mqtt: esp_mqtt_process: begin connection attempt
I (33849894) esp_mqtt: esp_mqtt_process: connection attempt successful
W (33849895) esp_mqtt: esp_mqtt_start: already running
I (33849895) wifiMqtt: ESP_MQTT_STATUS_CONNECTED

Guru Meditation Error of type LoadProhibited occurred on core 1

I wanted to run a simple test of esp-mqtt library on a NodeMCU-ESP32 board. My code is largely based on wifi scan example in esp-idf. It tries to connect to an specified AP and after getting an IP, it attempts to connect to a mqtt broker and publish a message to a specific topic. But as soon as it wants to connect to mqtt broker, the chip gets rebooted and this scenario repeats again and again. Here is the code and the following is the monitor log:

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x1b (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:3
load:0x3fff0010,len:4
load:0x3fff0014,len:5620
load:0x40078000,len:0
load:0x40078000,len:12476
entry 0x40078f74
W (73) rtc_clk: Bogus XTAL frequency: 0 MHz
I (33) boot: ESP-IDF v3.0-dev-899-g3a271a4a-dirty 2nd stage bootloader
I (34) boot: compile time 08:54:13
I (45) boot: Enabling RNG early entropy source...
I (46) boot: SPI Speed      : 26.7MHz
I (46) boot: SPI Mode       : DIO
I (48) boot: SPI Flash Size : 4MB
I (52) boot: Partition Table:
I (56) boot: ## Label            Usage          Type ST Offset   Length
I (63) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (71) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (78) boot:  2 factory          factory app      00 00 00010000 00100000
I (86) boot: End of partition table
I (90) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x0f338 ( 62264) map
I (124) esp_image: segment 1: paddr=0x0001f360 vaddr=0x3ffb0000 size=0x00cb0 (  3248) load
I (126) esp_image: segment 2: paddr=0x00020018 vaddr=0x400d0018 size=0x4edc0 (323008) map
0x400d0018: _stext at ??:?

I (262) esp_image: segment 3: paddr=0x0006ede0 vaddr=0x3ffb0cb0 size=0x0223c (  8764) load
I (266) esp_image: segment 4: paddr=0x00071024 vaddr=0x40080000 size=0x00400 (  1024) load
0x40080000: _iram_start at E:/My-Projects/esp/esp-idf/components/freertos/xtensa_vectors.S:167
5

I (269) esp_image: segment 5: paddr=0x0007142c vaddr=0x40080400 size=0x0f620 ( 63008) load
I (307) esp_image: segment 6: paddr=0x00080a54 vaddr=0x400c0000 size=0x00000 (     0) load
I (317) boot: Loaded app from partition at offset 0x10000
I (317) boot: Disabling RNG early entropy source...
I (319) cpu_start: Pro cpu up.
I (322) cpu_start: Starting app cpu, entry point is 0x40080e8c
0x40080e8c: call_start_cpu1 at E:/My-Projects/esp/esp-idf/components/esp32/cpu_start.c:219

I (312) cpu_start: App cpu up.
I (333) heap_init: Initializing. RAM available for dynamic allocation:
I (340) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (346) heap_init: At 3FFB88F8 len 00027708 (157 KiB): DRAM
I (352) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (359) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (365) heap_init: At 4008FA20 len 000105E0 (65 KiB): IRAM
I (371) cpu_start: Pro cpu start user code
I (54) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (120) wifi: wifi firmware version: 7bd4899
I (120) wifi: config NVS flash: enabled
I (120) wifi: config nano formating: disabled
I (120) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (130) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (170) wifi: Init dynamic tx buffer num: 32
I (170) wifi: Init data frame dynamic rx buffer num: 32
I (170) wifi: Init management frame dynamic rx buffer num: 32
I (180) wifi: wifi driver task: 3ffc529c, prio:23, stack:4096
I (180) wifi: Init static rx buffer num: 10
I (180) wifi: Init dynamic rx buffer num: 32
I (190) wifi: Init rx ampdu len mblock:7
I (190) wifi: Init lldesc rx ampdu entry mblock:4
I (200) wifi: wifi power manager task: 0x3ffca708 prio: 21 stack: 2560
I (230) phy: phy_version: 359.0, e79c19d, Aug 31 2017, 17:06:07, 0, 0
I (230) wifi: mode : sta (24:0a:c4:06:62:7c)
I (230) scan: SYSTEM_EVENT_STA_START
I (2640) wifi: n:7 0, o:1 0, ap:255 255, sta:7 0, prof:1
I (3630) wifi: state: init -> auth (b0)
I (3640) wifi: state: auth -> assoc (0)
I (3650) wifi: state: assoc -> run (10)
I (3660) wifi: connected with My Network, channel 7
I (5080) event: ip: 192.168.1.35, mask: 255.255.255.0, gw: 192.168.1.1
I (5080) scan: SYSTEM_EVENT_STA_GOT_IP
I (5080) scan: got ip:192.168.1.35

I (5080) esp_mqtt: esp_mqtt_start: create task
I (5090) esp_mqtt: esp_mqtt_publish: not connected
I (5090) esp_mqtt: esp_mqtt_process: begin connection attempt
Guru Meditation Error of type LoadProhibited occurred on core  1. Exception was unhandled.
Register dump:
PC      : 0x400014fd  PS      : 0x00060330  A0      : 0x80119411  A1      : 0x3ffbee00
A2      : 0x00000000  A3      : 0xfffffffc  A4      : 0x000000ff  A5      : 0x0000ff00
A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x00000000  A9      : 0x3ffbeda0
A10     : 0x00000000  A11     : 0x7fffffff  A12     : 0x3ffcafd8  A13     : 0x3ffc150c
A14     : 0x00060123  A15     : 0xff000000  SAR     : 0x00000004  EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xffffffff

Backtrace: 0x400014fd:0x3ffbee00 0x4011940e:0x3ffbee10 0x40118d67:0x3ffbee40 0x40118df6:0x3ffbeeb0
0x4011940e: lwmqtt_string at E:/My-Projects/esp/esp-idf/components/esp-mqtt/lwmqtt/src/string.
c:7

0x40118d67: esp_mqtt_process_connect at E:/My-Projects/esp/esp-idf/components/esp-mqtt/esp_mqt
t.c:376

0x40118df6: esp_mqtt_process at E:/My-Projects/esp/esp-idf/components/esp-mqtt/esp_mqtt.c:376

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.