0

My code always gets exception decoder message and resets a few ms after MQTT connection is done successfully.

My connectMqtt function:

void MyClass::connectMqtt(PubSubClient client)
{
  // Loop until we're reconnected
  int attempts = 0;
  bool connected = false;
  while (!connected && attempts < 5)
  {
    std::string clientId = _my_device.getBarcode();
    // Attempt to connect
    if (client.connect(clientId.c_str(), _my_device.getMqttUser(), _my_device.getMqttPassword()))
    {
      Serial.println(F("MQTT connected"));
      connected = true;

      //Subscribe to config topic of the device
      //TODO not done yet
    }
    else
    {
      Serial.print(F("failed, rc="));
      Serial.print(client.state());
      Serial.println(F(" try again in 5 seconds"));
      attempts++;
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
  Serial.println(F("Done."));
}

Exception decoder mesage starts by:

Exception (3):
epc1=0x40100691 epc2=0x00000000 epc3=0x00000000 excvaddr=0x40032468 depc=0x00000000
2
  • Show the full exception output. Also you might want to follow these to get more information. Commented Sep 2, 2020 at 11:25
  • 1
    try passing a reference to the function, not a copy void MyClass::connectMqtt(PubSubClient& client) Commented Sep 2, 2020 at 13:50

1 Answer 1

0

As @Juraj said:

The solution is passing a reference to the function, not a copy

void MyClass::connectMqtt(PubSubClient& client)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.