pubsubclient icon indicating copy to clipboard operation
pubsubclient copied to clipboard

[ESP32] Guru Meditation Error: (LoadProhibited) on reconnect

Open Schrolli91 opened this issue 5 years ago • 9 comments

Hello folks,

i have a little Problem at the moment. After some time, the connection gets lost. It looks like the wificlient has a disconnect:

[D][WiFiClient.cpp:509] connected(): Disconnected: RES: 0, ERR: 128
[W][Tasks.cpp:181] Task_ConnWatcher(): mqtt was down: -1 - connect

No problem so far ... As you can see on this two lines, my code does detect this connection drop with the .connected() method. After that i try a reconnect with .connect() method and get this exception immediately (every time).

Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x4000c63c  PS      : 0x00060330  A0      : 0x800d5d39  A1      : 0x3ffb5920  
A2      : 0x00000000  A3      : 0x00000100  A4      : 0x3ffb5958  A5      : 0x3ffb595e  
A6      : 0x00000004  A7      : 0x00000000  A8      : 0x00000000  A9      : 0x3ffb58f0  
A10     : 0x00000001  A11     : 0x3ffc12ab  A12     : 0x0000075b  A13     : 0xffffffff  
A14     : 0x00060320  A15     : 0x00000000  SAR     : 0x00000006  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0xffffffff  

Backtrace: 0x4000c63c:0x3ffb5920 0x400d5d36:0x3ffb5940 0x400d5ea2:0x3ffb5980 0x400d31ce:0x3ffb59b0 0x400891ed:0x3ffb5ad0
  #0  0x4000c63c:0x3ffb5920 in ?? ??:0
  #1  0x400d5d36:0x3ffb5940 in PubSubClient::connect(char const*, char const*, char const*, char const*, unsigned char, bool, char const*, bool) at .pio/libdeps/esp32dev/PubSubClient/src/PubSubClient.cpp:734
  #2  0x400d5ea2:0x3ffb5980 in PubSubClient::connect(char const*) at .pio/libdeps/esp32dev/PubSubClient/src/PubSubClient.cpp:734
  #3  0x400d31ce:0x3ffb59b0 in Tasks::Task_ConnWatcher(void*) at src/Tasks.cpp:183
  #4  0x400891ed:0x3ffb5ad0 in vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c:355 (discriminator 1)

The value of EXCVADDR: 0x00000000 tells me, that there maybe is a kind of nullptr exception here. Does anyone have a idea whats going wrong?

BTW: the first connection after start goes trough the same code block and that works every time (check connection and connect).

Regards, Basti


Here is the connect/reconnect snippet: NOTE: The mutex is given a few lines later ... after subscribe is done. So no part of my code does try to send something at the moment we see the was down log message.

if (!mqtt.connected())  {
                xSemaphoreTake(mutex_mqtt, portMAX_DELAY);
                log_w("mqtt was down: %d - connect", mqtt.state());
                uint8_t recon_ctr = 0;
                while (!mqtt.connect(test->mqtt_device_name)) // here exception hits
                {
                    recon_ctr++;
                    log_e("mqtt connection error: %d", mqtt.state());
                    log_e("connection try %d failed!", recon_ctr);
                    if (recon_ctr >= 5)
                    {
                        log_e("mqtt connection failed! restart...");
                        esp_restart();
                        break;
                    }
                    vTaskDelay(pdMS_TO_TICKS(5000));
                }
// ...
// subscribe and mutex GIVE
// ...
}

As you can see here - the disconnect is at totally random times: image (data from millis() over mqtt - so there was real restart of the ESP (millis() reset))

Schrolli91 avatar Dec 03 '20 20:12 Schrolli91

same problem over here. but for me it happens immediately with the first connect

jappyjan avatar Jan 20 '21 09:01 jappyjan

Just for information: I have switched to https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/protocols/mqtt.html This implementation works like a charme - stable for weeks with no disconnect or other problems..

Schrolli91 avatar Jan 20 '21 10:01 Schrolli91

Dito 😅😂

Am 20.01.2021 um 11:24 schrieb Bastian Schroll [email protected]:

 Just for information: I have switched to https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/protocols/mqtt.html This implementation works like a charme - stable for weeks with no disconnect or other problems..

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

jappyjan avatar Jan 20 '21 12:01 jappyjan

@jappyjan I had the same problem when trying to connect the first time, but I found a detail in one of the tutorials I read: I missed the constructor that needs a wifi client... now it works =)

WiFiClient espClient;
PubSubClient mqttClient(espClient);

c-zenker avatar Mar 17 '21 15:03 c-zenker

I still getting this error, is there someone who understood why this happen? It happens when sending fast messages to the device.

sblantipodi avatar Apr 28 '21 21:04 sblantipodi

In my case this error (LoadProhibited) caused by the program access null variable.

Example program below cause loadprohibited when i run.

     // Get frame 
    camera_fb_t * fb = NULL;
    fb = esp_camera_fb_get();
    if (!fb) {
      Serial.println("Camera capture failed");
      return;
    }

    size_t outputLength;
     
    // Access property fb->buf and fb->len
    unsigned char * encoded = base64_encode(fb->buf, fb->len, &outputLength);

Thats code return error because fb->buf and fb->len stilll have null value or thats task esp_camera_fb_get() not finished.

For fix this problem i use delay() method at under task, it works for waiting fb task until all property ex fb->buf filled with data

ichsanputr avatar May 22 '22 00:05 ichsanputr

I still getting this error, is there someone who understood why this happen? It happens when sending fast messages to the device.

@sblantipodi

Look my reply below https://github.com/knolleary/pubsubclient/issues/796#issuecomment-1133787741

ichsanputr avatar May 22 '22 00:05 ichsanputr

Based on the suggestions here I also switched to esp_mqtt. Fixed all my issues. While PubSubClient is a wonderful generic mqtt lib, I think the esp_mqtt lib is better suited for the esp32.

MichMich avatar Jun 15 '23 09:06 MichMich

it's sad but last commit on this repo was made in may 2020. no one is answering issues or reviewing the pull requests.

I would consider pubsubclient unmaintained so we all need to find a new lib one day or another.

sblantipodi avatar Jun 15 '23 19:06 sblantipodi