Please help how to reconnect to MQTT broker after resume

amichalu
Posts: 1
Joined: Mon Oct 05, 2020 7:58 pm

Please help how to reconnect to MQTT broker after resume

Postby amichalu » Mon Oct 05, 2020 8:03 pm

Hi, I'm facing problem with ESP32 DevKitv1, I cannot reconnect to broker, scenario is following:

1) MQTT client connected to broker (mosquitto);

2) Messages are being sent to broker normally;

3) after while mosquitto is down,

4) MQTT client reports disconnection;

5) mosquitto is up again and working normally, network connection valid (ping answers);

4) MQTT client cannot reconnect any more, log: "MQTT_CLIENT: Client force reconnect requested"

I use code modified, based on MQTT example https://github.com/espressif/esp-idf/tr ... s/mqtt/tcp:

Code: Select all

case MQTT_EVENT_DISCONNECTED:
            ESP_LOGI(TAG, "MQTT_EVENT_DISCONNECTED");
            ESP_LOGI(TAG, "Trying to reconnect...");

            xFrequency = 2*1000 / portTICK_PERIOD_MS;
            xLastWakeTime = xTaskGetTickCount();
            for( ;; )
            {
                ESP_LOGI(TAG, "another attempt ...");
                vTaskDelayUntil( &xLastWakeTime, xFrequency );                
                esp_err_t err = esp_mqtt_client_reconnect(client);   // <====== it seems not working !!!
                if (err != ESP_OK) ESP_LOGI(TAG, "reconnect error !");
            }
            break;

Who is online

Users browsing this forum: No registered users and 31 guests