Open papakpmartin opened 1 year ago
Digging around here in this project, I did notice this comment on a feature that you decided not to do, and I was indeed using a member function for the callback, but i switched it to a lambda with no change in symptoms.
On ESP32, I have code for which Wi-Fi and MQTT are working perfectly reliably in one task, but in another task the
m_mqttClient.connect(…)
call hangs untilMQTT_SOCKET_TIMEOUT
, at which point it tries again and never succeeds. Here is some debug:However, at every
MQTT: State: -3
and/orMQTT: State: -4
I can see from the mosquitto logs that the device is indeed connected:In the “working perfectly” case, it looks like this:
Project looks like this:
For the connection that works reliably, a task in
main.cpp
calls theComms.connect()
which connects to both Wi-Fi and MQTT and then I set the callback in the task likeComms::instance().m_mqttClient.setCallback(mqtt_callback);
.For the one that is failing, a task in
main.cpp
callsSetup.begin()
, and it's withinSetup.begin()
thatComms.connect()
andsetCallback()
are done. In this case, the callback is a method ofSetup
.The two connections never try to run at the same time.
Why would a connected client think it's not connected? Am I misusing something?