I recently noticed some seemingly random crashs on my esp32 application.
I was able to catch a crash message which is the following and which is due to some erroneuos behaviour when I check if my PubSubClient is still connected. The MqttClient is my own wrapper around the actual PubSubClient . I created a separate task for handling the connection state which is below.
Here is my task creation :
xTaskCreate(
[](void *parameters)
{
MqttClient *mqttClient = (MqttClient *)parameters;
while (true)
{
mqttClient->doConnectionCheck();
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}, // Function to implement the task
"mqttConnectionTask", // Name of the task
8192, // Stack size in words
this, // Task input parameter
1, // Priority of the task
&mqttConnectionTaskHandle // Task handle
);
and my actual check for the connection:
void MqttClient::doConnectionCheck()
{
if (WiFi.status() != WL_CONNECTED)
{
Serial.println("Wait for WiFi");
}
else if (!isConnected()) # Here goes the crash
{
Serial.println("Try connect");
connect(); // This function downloads certs and so on and connects the client, but that is not the crash reason. Because of the certificates I set the stack size to 8192 (?)
}
else
{
// Everything connected
}
}
bool MqttClient::isConnected()
{
return client->connected();
}
It crashes when isConnected()
is called.
Does anyone have a slight idea what is happening here?
Best regards,
Michael
I tried to use my PubSubClient to do some MQTT communication and in general it sometimes behaves a bit strange. For instance, it connects to my broker and cancels the connection several times in a row and then succeeds.
And obviously it crashes like described which I do not know how to solve and I have no idea why.