Comments (6)
Hi everyone, I have the same problem with the latest version.
Thank you for your help
from esp-mqtt.
I just tried here and I've got the notification "MQTT_EVENT_DISCONNECTED" when my broker went down. Is that what you're referring to?
D (28694) MQTT_CLIENT: mqtt_enqueue id: 29690, type=3 successful
D (28714) MQTT_CLIENT: msg_type=4, msg_id=39347
D (28714) MQTT_CLIENT: pending_id=39347, pending_msg_count = 1
D (28714) MQTT_CLIENT: received MQTT_MSG_TYPE_PUBACK, finish QoS1 publish
I (28724) LOG: MQTT_EVENT_PUBLISHED, msg_id=39347
E (28954) MQTT_CLIENT: Read error or end of stream
I (28954) MQTT_CLIENT: Reconnect after 10000 ms
I (28954) LOG: MQTT_EVENT_DISCONNECTED <<<<< this is my log
Snippet of my code:
static esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event) {
switch (event->event_id) {
case MQTT_EVENT_CONNECTED:
client = event->client;
ESP_LOGI(LOG, "MQTT_EVENT_CONNECTED");
break;
case MQTT_EVENT_DISCONNECTED:
ESP_LOGI(LOG, "MQTT_EVENT_DISCONNECTED");
break;
case MQTT_EVENT_SUBSCRIBED:
ESP_LOGI(LOG, "MQTT_EVENT_SUBSCRIBED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_UNSUBSCRIBED:
ESP_LOGI(LOG, "MQTT_EVENT_UNSUBSCRIBED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_PUBLISHED:
ESP_LOGI(LOG, "MQTT_EVENT_PUBLISHED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_DATA:
ESP_LOGI(LOG, "MQTT_EVENT_DATA");
printf("TOPIC=%.*s\r\n", event->topic_len, event->topic);
printf("DATA=%.*s\r\n", event->data_len, event->data);
break;
case MQTT_EVENT_ERROR:
ESP_LOGI(LOG, "MQTT_EVENT_ERROR");
break;
}
return ESP_OK;
}
And the reconnection after 10s works too:
D (76214) MQTT_CLIENT: Reconnecting...
D (81214) TRANS_TCP: [sock=56],connecting to server IP:192.168.1.92,Port:1883...
E (98774) MQTT_CLIENT: Error transport connect
I (98774) MQTT_CLIENT: Reconnect after 10000 ms
I (98774) LOG: MQTT_EVENT_DISCONNECTED
The only thing that I noticed is that even when the client is disconnected, after a fail attempt, it will rise MQTT_EVENT_DISCONNECTED again.
And when my broker was started again, my MQTT client automatically connected to it:
D (263834) MQTT_CLIENT: Reconnecting...
D (268834) TRANS_TCP: [sock=61],connecting to server IP:192.168.1.92,Port:1883...
D (268834) MQTT_CLIENT: Transport connected to mqtt://192.168.1.92:1883
I (268844) MQTT_CLIENT: Sending MQTT CONNECT message, type: 1, id: 0000
D (268854) MQTT_CLIENT: Connected
I (268854) LOG: MQTT_EVENT_CONNECTED
I (268854) wifi: ic_enable_sniffer
D (269854) MQTT_CLIENT: Sent PING successful
D (270214) MQTT_CLIENT: msg_type=13, msg_id=0
D (270214) MQTT_CLIENT: MQTT_MSG_TYPE_PINGRESP
D (271674) MQTT_CLIENT: mqtt_enqueue id: 0, type=1 successful
D (271684) MQTT_CLIENT: mqtt_enqueue id: 29589, type=3 successful
D (271684) OUTBOX: ENQUEUE msgid=29589, msg_type=3, len=133, size=133
D (272054) MQTT_CLIENT: msg_type=4, msg_id=29589
D (272054) MQTT_CLIENT: pending_id=56570, pending_msg_count = 2
D (272054) OUTBOX: DELETED msgid=29589, msg_type=3, remain size=0
D (272064) MQTT_CLIENT: received MQTT_MSG_TYPE_PUBACK, finish QoS1 publish
I (272064) LOG: MQTT_EVENT_PUBLISHED, msg_id=29589
D (272074) MQTT_CLIENT: msg_type=4, msg_id=56570
D (272074) MQTT_CLIENT: pending_id=56570, pending_msg_count = 1
D (272084) MQTT_CLIENT: received MQTT_MSG_TYPE_PUBACK, finish QoS1 publish
I (272094) LOG: MQTT_EVENT_PUBLISHED, msg_id=56570
from esp-mqtt.
Hi @casmeiron
It is correct what you mention.
I am using the ethernet interface, when I disconnect the interface, the mqtt client does not launch the MQTT_EVENT_DISCONNECTED event, but in the previous version after disconnecting the interface the event was launched after the 10 second timeout.
Everything else is correct.
thanks for your answer.
from esp-mqtt.
Hi all,
Can we close this old issue? As far as I can see MQTT_EVENT_DISCONNECTED
event works as expected (will yet test it with ethernet, but don't expect any issue there)
from esp-mqtt.
@bengiexd just tested on ethernet and MQTT_EVENT_DISCONNECTED
event received correctly. Please note that you can configure keep alive timeout (by default 120s) to any value of your preference:
esp_mqtt_client_config_t mqtt_cfg = {
.uri = "mqtt://192.168.0.111",
.event_handle = mqtt_event_handler,
.keepalive = 10,
// .user_context = (void *)your_context
};
I'm taking the liberty to close the issue, please reopen if needed.
from esp-mqtt.
maybe tihs problem only use ethetnet interface
from esp-mqtt.
Related Issues (20)
- Not compatible with CPP, IDF 5.0 (IDFGH-9334) HOT 5
- How can I detect Expired certificates (IDFGH-9420) HOT 3
- ESP-IDF won't connect to MQTT broker local gateway IP (IDFGH-9465) HOT 4
- Init multiple network components in separate network interfaces (IDFGH-9466) HOT 2
- MQTT 5 Bug - Checks packet header but there is none (IDFGH-9603) HOT 1
- esp_mqtt_client_publish() does not return -1 for QOS0 when disconnect (IDFGH-10129) HOT 1
- Possible bug on mqtt5 client when QoS>0 (IDFGH-10436) HOT 4
- MQTT QOS2 not resend PUBREC ACKNOWLEDGED message (IDFGH-10609)
- Qos 2 wrong implementation (IDFGH-10613) HOT 5
- Last Will Message pushed when I reconnect (IDFGH-10970) HOT 1
- esp_mqtt_set_config ignores buffer_size (IDFGH-11058) HOT 2
- AUTH command not supported (IDFGH-11745)
- MQTT data persistence (QOS 1 and 2) (IDFGH-12616) HOT 3
- Retransmission of QOS0 (IDFGH-12829) HOT 1
- Connection aborts when mqtt_resend_queued fails (IDFGH-12830) HOT 9
- Expired messages only delete when connected (IDFGH-12831)
- Memory Leak when using esp_mqtt_client_publish (IDFGH-12840) HOT 3
- User Error (IDFGH-13164)
- TCP_NODELAY (IDFGH-13350) HOT 2
- MQTT outbox dequeuing mechanism for esp_mqtt_client_enqueue (IDFGH-13400) HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esp-mqtt.