简体   繁体   English

当PubSubClient设置mqttserver时,ESP8266崩溃

[英]ESP8266 crashes when PubSubClient set mqttserver

I'm using NodeMCU (ESP12E) controlled using pubsubclient library. 我正在使用使用pubsubclient库控制的NodeMCU(ESP12E)。 NodeMCU is crashed when i call 我打电话时,NodeMCU崩溃了
client.setServer(mqtt_server, 1883);
Message: 信息:

Exception (28):
    epc1=0x4000bf80 epc2=0x00000000 epc3=0x00000000 excvaddr=0x0000096c depc=0x00000000

It seems setServer action conflicting with ESP8266WebServer. 似乎setServer操作与ESP8266WebServer冲突。
I tried: this but the problem is not resolved. 我试过: 这个但问题没有解决。
This is my code: 这是我的代码:

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <EEPROM.h>
#include <ESP8266WebServer.h>

// Khởi tạo biến toàn cục
const char* mqtt_server = "iot.eclipse.org";

WiFiClient espClient;
PubSubClient client;
ESP8266WebServer *server;
void setup() {
  EEPROM.begin(512);
  Serial.begin(9600);
  //I tried this
  server = new (ESP8266WebServer);
  //Check wifi, if failed -> run as web server
  if (!setup_wifi()) {
    wifiStartServerMode();
  }

  //.....Some function to get username and password from EEPROM

  // Call back-end using new local WiFiClient
  //  String serverResponse = registerDevice(mac, username, userpassword, 3);
  //If ok, serser response this:
  String serverResponse = "null;null;root/phan/abc";
  if (serverResponse.indexOf(';') > 0) {
    Serial.println("start mqtt client");
    client.setClient(espClient);

    ////////////////
    //CRASHED HERE//
    ///////////////
    client.setServer(mqtt_server, 1883);
    client.setCallback(callback);
    String tempTopic = getValue(serverResponse, ';', 2);
    for (int i = 0; i < tempTopic.length(); i++) {
      topic += tempTopic[i];
    }
    //Đăng ký nhận tín hiệu
    client.subscribe(topic);
    errConnect2BackEnd = false;
    stConnectBroker = true;
  } else if (serverResponse.equals("failed")) {//Không thể kết nối server
    Serial.println("Can't connect to server");
    //TODO: Báo lỗi, không kết nối server
  } else {
    Serial.print("Error: ");
    Serial.println(serverResponse);
    //TODO: Nhập sai thông tin đăng nhập -> reset để nhập lại (nhấn nút, xóa EEPROM)
  }
  Serial.println("End of setup");

}

Function start run server in loop and stop when it's done 函数开始在循环中运行服务器并在完成后停止

  //-> run as web server

  void wifiStartServerMode() {
  //Active AP_ST_MODE
  setupAP_STA_Mode();
  //Run server->handleClient(); in loop
  viewRunConfig();
  server->stop();
  server->close();
  delay(100);
  delete(server);
  setup_Station_Mode();
}

When function "wifiStartServerMode" not run, it still crash. 当函数“wifiStartServerMode”未运行时,它仍然会崩溃。

What could be the problem? 可能是什么问题呢?

If your algorithm is right. 如果你的算法是正确的。 Please check pointer.....and move others files. 请检查指针.....并移动其他文件。
It seems bug of Arduino IDE, when i copy this functions, code to other files. 这似乎是Arduino IDE的bug,当我将这些函数复制到其他文件时。
It works. 有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM