tuanpmt/esp32-mqtt

Client socket being destroyed after unsuccessful read from mqtt_start_receive_schedule() function

Opened this issue · 2 comments

Hello Tuan,
Great work. Code makes sense to me but I could not further dig deep into the problem.
I have tried using your MQTT example.
I successfully get connected to Adafruit MQTT server but seems like subscribing does not work fine for me.
Here is the MQTT log I get:
`[MQTT INFO] Starting mqtt task
[MQTT INFO] Resolve dns for domain: io.adafruit.com
[MQTT INFO] Connecting to server 52.5.238.97:8883,45858
[MQTT INFO] Creating SSL object...
[MQTT INFO] Start SSL connect..
[MQTT INFO] Connected!
[MQTT INFO] Connected to server io.adafruit.com:8883
[MQTT INFO] Sending MQTT CONNECT message, type: 1, id: 0000
[MQTT INFO] Reading MQTT CONNECT response message
I (5983) wifi: pm start, type:0

[MQTT INFO] Connected
[MQTT INFO] Connected to MQTT broker, create sending thread before call connected callback
[MQTT INFO] mqtt_sending_task
[MQTT INFO] Sending...21 bytes
[MQTT INFO] Queue subscribe, topic"Lock_Status", id: 1
[MQTT INFO] Sending...18 bytes
[MQTT INFO] mqtt_start_receive_schedule
[MQTT INFO] Read len -1
[MQTT INFO] Read error 0
[MQTT INFO] Closing client socket
[MQTT INFO] Client destroyed
`

In the connected callback I am only using subscribe, I have commented publishing for now but the unsuccessful read problem from mqtt_start_receive_schedule() function stays the same:

`void connected_cb(void *self, void *params)
{
mqtt_client *client = (mqtt_client *)self;
mqtt_subscribe(client, "Lock_Status", 0);
//mqtt_publish(client, "/test", "howdy!", 6, 0, 0);
}

Can you please help me figuring out the problem.
Thanks a lot.`

Hello,
Up there, I had kept .lwt_topic = "", BUT when I changed the .lwt_topic = "/lwt" (which is default too)
I got the unauthorization error while subscribing to a topic to MQTT server:

Here are the options I am using:
.client_id = "ESP32_Client", .username = "..............", //I have put it right Adafruit USER .password = ".......................................", //I have put it right Adafruit PASS .clean_session = 0, .keepalive = 120, .lwt_topic = "/lwt", // = "" for disable lwt, will don't care other options previously "/lwt" .lwt_msg = "offlines", .lwt_qos = 0, .lwt_retain = 0, .connected_cb = connected_cb, .disconnected_cb = disconnected_cb, //.reconnect_cb = reconnect_cb, .subscribe_cb = subscribe_cb, .publish_cb = publish_cb, .data_cb = data_cb

I am getting the following UNAUTHORIZED CONNECTION on the log:

[MQTT INFO] Starting mqtt task [MQTT INFO] Resolve dns for domain: io.adafruit.com [MQTT INFO] Connecting to server 52.70.203.194:8883,45858 [MQTT INFO] Creating SSL object... [MQTT INFO] Start SSL connect.. [MQTT INFO] Connected! [MQTT INFO] Connected to server io.adafruit.com:8883 [MQTT INFO] Sending MQTT CONNECT message, type: 1, id: 0000 [MQTT INFO] Reading MQTT CONNECT response message [MQTT WARN] Connection refused, not authorized [MQTT INFO] Closing client socket [MQTT INFO] Client destroyed