微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

我的代码总是会获得异常解码器消息,并在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)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。