在我的 ESP8266 中与 PubSubClient 连接后的异常解码器

Exception decoder after connected with PubSubClient in my ESP8266

我的代码总是收到异常解码器消息并在 MQTT 连接成功完成后几毫秒重置。

我的 connectMqtt 函数:

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 (3):
epc1=0x40100691 epc2=0x00000000 epc3=0x00000000 excvaddr=0x40032468 depc=0x00000000

正如@Juraj 所说:

解决方案是传递对函数的引用,而不是副本

void MyClass::connectMqtt(PubSubClient& client)