256dpi / arduino-mqtt

MQTT library for Arduino
MIT License
1.01k stars 232 forks source link

Question: How to handle the -13 Return-Code #258

Closed sladig closed 1 year ago

sladig commented 3 years ago

Hello,

i'm working with the Arduino MKR NB 1500 board and this MQTT library. The connection is done via TLS and after some optimizations it is more or less working. But from time to time i receive the -13 return code.

My question: any idea what is really behind this return code and how i could handle it without the WatchDog?

Currently i'm checking the MQTT connecting and try to reconnect but then i run into a deadlog and the WatchDog becomes active. This is something i would like to handle without a complete restart of the Arduino board.

Some code:

// Check for MQTT Connection and try to connect ...
void connectMQTT()
{
MyWatchDoggy.clear();

if (!mqttClient.connected()) {
Serial.println(F("MQTT not connected."));
int count = 0;

// Check for NB-IoT connection.
connectNB();

//
// HERE THE WHOLE EXECUTION STOPS ... WHAT COULD I DO BEFORE?
//
while (!mqttClient.connect(ICCID, MQTT_USER.c_str(), MQTT_PASS.c_str())) {
  count++;

  Serial.print(F("MQTT try to connect: "));
  Serial.println(count);

  if (count > mqtt_attempts) {
    Serial.println(F("MQTT connect failed. Waiting for watchdog."));
    while (1);
  }

  delay(5000);
}
256dpi commented 1 year ago

Return code "-13" means that there was a problem with keeping the connection alive.

Closing as stale, please reopen if issue persists.