客户端断开连接时,NodeMCU(ESP8266)异常28

时间:2018-12-12 16:38:10

标签: arduino arduino-uno esp8266 arduino-ide nodemcu

我在nodemcu v3(ESP8266)上有一个Websocket服务器,还有一个用Qt制造的Websocket客户端。当客户端断开连接时,服务器会给出异常28,但我不知道为什么。

这是使用ESP异常解码器解码的堆栈。

>= 10v

这是nodemcu上的代码。一个简单的websocket服务器,它从串行接收数据并将其发送到客户端。

ecoding stack results
0x4020b7f8: __ssputs_r at ../../../.././newlib/libc/stdio/nano-vfprintf.c     line 180
0x4020b7f8: __ssputs_r at ../../../.././newlib/libc/stdio/nano-vfprintf.c     line 180
0x40207851: _printf_common at ../../../.././newlib/libc/stdio/nano-    vfprintf_i.c line 94
0x4020b7f8: __ssputs_r at ../../../.././newlib/libc/stdio/nano-vfprintf.c     line 180
0x40207c0c: _printf_i at ../../../.././newlib/libc/stdio/nano-    vfprintf_i.c line 241
0x4020baa0: _svfprintf_r at ../../../.././newlib/libc/stdio/nano-    vfprintf.c line 531
0x4020d151: glue2esp_linkoutput at glue-esp/lwip-esp.c line 299
0x4020bc58: _svfprintf_r at ../../../.././newlib/libc/stdio/nano-    vfprintf.c line 641
0x4020d4a6: new_linkoutput at glue-lwip/lwip-git.c line 259
0x40213a64: etharp_output_LWIP2 at core/ipv4/etharp.c line 882
0x4020453c: WebSockets::handleWebsocketWaitFor(WSclient_t*, unsigned int)     at C:\Users\aurel\OneDrive\Documents\Arduino\libraries\arduinoWebSockets-    master\src\WebSockets.cpp line 296
0x40209639: _vsnprintf_r at ../../../.././newlib/libc/stdio/vsnprintf.c     line 73
0x40209639: _vsnprintf_r at ../../../.././newlib/libc/stdio/vsnprintf.c     line 73
0x4020967c: vsnprintf at ../../../.././newlib/libc/stdio/vsnprintf.c line     42
0x40205a68: Print::printf(char const*, ...) at C:\Users\aurel\AppData    \Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266    \Print.cpp line 63
0x402028d0: webSocketEvent(unsigned char, WStype_t, unsigned char*,     unsigned int) at D:\Workspace\Arduino\arduino-health-care-system\Arduino    \WebSocketServerApp/WebSocketServerApp.ino line 69
0x402028fc: webSocketEvent(unsigned char, WStype_t, unsigned char*,     unsigned int) at D:\Workspace\Arduino\arduino-health-care-system\Arduino    \WebSocketServerApp/WebSocketServerApp.ino line 71
0x4010020c: _umm_free at C:\Users\aurel\AppData\Local\Arduino15\packages    \esp8266\hardware\esp8266\2.4.2\cores\esp8266\umm_malloc\umm_malloc.c line     1295
0x401006dc: free at C:\Users\aurel\AppData\Local\Arduino15\packages    \esp8266\hardware\esp8266\2.4.2\cores\esp8266\umm_malloc\umm_malloc.c line     1755
0x4010020c: _umm_free at C:\Users\aurel\AppData\Local\Arduino15\packages    \esp8266\hardware\esp8266\2.4.2\cores\esp8266\umm_malloc\umm_malloc.c line     1295
0x402068a4: std::_Function_handler ::_M_invoke(std::_Any_data const&,     unsigned char, WStype_t, unsigned char*, unsigned int) at c:\users\aurel    \appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-    gcc\1.20.0-26-gb404fb9-2\xtensa-lx106-elf\include\c++\4.8.2/functional line     2073
0x40206b04: WebSocketsServer::runCbEvent(unsigned char, WStype_t,     unsigned char*, unsigned int) at C:\Users\aurel\OneDrive\Documents\Arduino    \libraries\arduinoWebSockets-master\src/WebSocketsServer.h line 182
0x402048c6: WebSocketsServer::clientDisconnect(WSclient_t*) at C:\Users    \aurel\OneDrive\Documents\Arduino\libraries\arduinoWebSockets-master    \src\WebSocketsServer.cpp line 585
0x40206b41: WebSocketsServer::clientIsConnected(WSclient_t*) at C:\Users    \aurel\OneDrive\Documents\Arduino\libraries\arduinoWebSockets-master    \src\WebSocketsServer.cpp line 611
0x40205371: WebSocketsServer::handleClientData() at C:\Users\aurel    \OneDrive\Documents\Arduino\libraries\arduinoWebSockets-master    \src\WebSocketsServer.cpp line 671
0x402053fd: WebSocketsServer::loop() at C:\Users\aurel\OneDrive\Documents    \Arduino\libraries\arduinoWebSockets-master\src\WebSocketsServer.cpp line 135
0x40202b14: loop() at D:\Workspace\Arduino\arduino-health-care-system    \Arduino\WebSocketServerApp/WebSocketServerApp.ino line 58
0x402065d1: esp_schedule() at C:\Users\aurel\AppData\Local\Arduino15    \packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266\core_esp8266_main.cpp     line 95
0x4020663c: loop_wrapper() at C:\Users\aurel\AppData\Local\Arduino15    \packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266\core_esp8266_main.cpp     line 125

1 个答案:

答案 0 :(得分:0)

我用此代码替换了代码,现在它可以了。

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <WebSocketsServer.h>
#include <Hash.h>

// Replace with your network credentials
const char* ssid = "";
const char* password = "";

WebSocketsServer webSocket = WebSocketsServer(81);
ESP8266WebServer server(80);   //instantiate server at port 80 (http port)

String page = "";
int LEDPin = 13;

void setup(void){

 pinMode(LEDPin, OUTPUT);
 digitalWrite(LEDPin, LOW);

 delay(1000);

 Serial.begin(9600);
 WiFi.begin(ssid, password); //begin WiFi connection
 Serial.println("");

 // Wait for connection
 while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
 }

 Serial.println("");
 Serial.print("Connected to ");
 Serial.println(ssid);
 Serial.print("IP address: ");
 Serial.println(WiFi.localIP());



server.begin();
 webSocket.begin();
 webSocket.onEvent(webSocketEvent);

 Serial.println("Web server started!");
}

void loop(void){
  webSocket.loop();
  server.handleClient();
  if (Serial.available() > 0){
    char c[] = {(char)Serial.read()};
    webSocket.broadcastTXT(c, sizeof(c));
  }
}

void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length){
  if (type == WStype_TEXT){
   for(int i = 0; i < length; i++) Serial.print((char) payload[i]);
   Serial.println();

  }

  if(type == WStype_CONNECTED)
            {
              IPAddress ip = webSocket.remoteIP(num);
              Serial.printf("[%u] Connected from %d.%d.%d.%d url: %s\r\n", num,     ip[0], ip[1], ip[2], ip[3], payload);    
            }
}