Links2004 / arduinoWebSockets

arduinoWebSockets
GNU Lesser General Public License v2.1
1.85k stars 549 forks source link

ESP32 + ENC28J60 = tcpip_send_msg_wait_sem #868

Open KoffeinKaio opened 5 months ago

KoffeinKaio commented 5 months ago

Heyo,

I'm trying to get WebSockets to work with an ESP32 (az-delivery, wroom) and an ENC28J60 module.

Minimal example:

#include <Arduino.h>
#define WEBSOCKETS_NETWORK_TYPE NETWORK_ENC28J60
#include <WebSocketsServer.h>
#include <UIPEthernet.h>

WebSocketsServer webSocket = WebSocketsServer(81);
byte mac[] = { 0x5E, 0xA9, 0xBE, 0xE7, 0xFE, 0xED };

void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
  switch (type) {
    case WStype_DISCONNECTED:
      Serial.printf("[%u] Disconnected!\n", num);
      break;
    case WStype_CONNECTED:
      // send message to client
      webSocket.sendTXT(num, "Connected");
      break;
  }
}

void setup() {
  Serial.begin(115200);
  Serial.setDebugOutput(true);

  Serial.println();
  Serial.println();
  Serial.println();

  Serial.println("Initializing Ethernet with DHCP...");
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    while (true) {
      delay(1);
    }
  }

  Serial.print("localIP: ");
  Serial.println(Ethernet.localIP());
  Serial.print("subnetMask: ");
  Serial.println(Ethernet.subnetMask());
  Serial.print("gatewayIP: ");
  Serial.println(Ethernet.gatewayIP());
  Serial.print("dnsServerIP: ");
  Serial.println(Ethernet.dnsServerIP());

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

void loop() {
    webSocket.loop();
}

As soon as webSocket.begin is hit it crashes with:

assert failed: tcpip_send_msg_wait_sem IDF/components/lwip/lwip/src/api/tcpip.c:455 (Invalid mbox)

Backtrace: 0x400834cd:0x3ffc66c0 0x40088401:0x3ffc66e0 0x4008d6a1:0x3ffc6700 0x400e67ca:0x3ffc6830 0x400f2dad:0x3ffc6860 0x400f2e0c:0x3ffc6880 0x400e6501:0x3ffc68d0 0x400d3576:0x3ffc68f0 0x400d35ec:0x3ffc6940 0x400d50e3:0x3ffc6960 0x400d2575:0x3ffc6980 0x400dab5a:0x3ffc69d0

ELF file SHA256: ba825132c37e99cd

Which according to the stacktrace is:

Output:
0x400834cd: panic_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/panic.c:408
0x40088401: esp_system_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/esp_system.c:137
0x4008d6a1: __assert_func at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/newlib/assert.c:85
0x400e67ca: tcpip_send_msg_wait_sem at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/api/tcpip.c:455
0x400f2dad: netconn_apimsg at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/api/api_lib.c:136
0x400f2e0c: netconn_new_with_proto_and_callback at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/api/api_lib.c:166
0x400e6501: lwip_socket at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/lwip/lwip/src/api/sockets.c:1774
0x400d3576: socket at /home/sascha/.arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32/include/lwip/lwip/src/include/lwip/sockets.h:656
0x400d3576: WiFiServer::begin(unsigned short, int) at /home/sascha/.arduino15/packages/esp32/hardware/esp32/2.0.11/libraries/WiFi/src/WiFiServer.cpp:80
0x400d35ec: WiFiServer::begin(unsigned short) at /home/sascha/.arduino15/packages/esp32/hardware/esp32/2.0.11/libraries/WiFi/src/WiFiServer.cpp:70
0x400d50e3: WebSocketsServer::begin() at /home/sascha/Arduino/libraries/WebSockets/src/WebSocketsServer.cpp:921
0x400d2575: setup() at /home/sascha/Arduino/WebSocketServer/WebSocketServer.ino:61
0x400dab5a: loopTask(void*) at /home/sascha/.arduino15/packages/esp32/hardware/esp32/2.0.11/cores/esp32/main.cpp:42

Any Ideas?

EDIT: after digging around a bit - is using WebSocketServer with NETWORK_ENC28J670 even supported?

builder26 commented 4 months ago

Hello, I'm having the exact same problem. Versions 2.0.11 and 2.0.10 produce this error. You can use my example too:

#include <WebServer.h>
#include <WiFiClient.h>
#include <WiFiAP.h>

const char *ssid = "test";
const char *password = "1234";

WebServer server(80);

void handleRoot(){
  server.send(200, "text/plain", "Hi there!");

}

void setup() {
  Serial.begin(115200);
  WiFi.softAP(ssid, password);
  delay(100);
  IPAddress myIP = WiFi.softAPIP();
  Serial.println(myIP);
  Serial.println("Server started");

  server.on("/", handleRoot);
  server.begin();
  delay(2000);
  Serial.println("Server up");
}

void loop() {
  server.handleClient();
  delay(1);
}

Output:

load:0x40080400,len:3600
entry 0x400805f0
0.0.0.0
Server started

assert failed: tcpip_send_msg_wait_sem IDF/components/lwip/lwip/src/api/tcpip.c:455 (Invalid mbox)

Backtrace: 0x400835a1:0x3ffca6d0 0x4008b6e1:0x3ffca6f0 0x40090b61:0x3ffca710 0x400ed2c2:0x3ffca840 0x400fd6ad:0x3ffca870 0x400fd70d:0x3ffca890 0x400ecab1:0x3ffca8e0 0x400d4476:0x3ffca900 0x400d44f0:0x3ffca950 0x400d645d:0x3ffca970 0x400d27e5:0x3ffca990 0x400d924a:0x3ffca9f0

I've tried to completely erase the flash and reprogram the board with no success. Also, I've tried with version 1.0.6 and it works.

Edit: In my case, the solution was to add this line, you may need to change some parameters for your specific case. I believe in the previous versions this was not needed.

  WiFi.begin();
OlliePugh commented 1 week ago

Also seeing the above issue. I tried @builder26's solution, but that actually just connected to my WiFi and didn't use the ethernet. (Absolutely no idea how it has the credentials - asumming its stored in the EEPROM or something?!)

Did you ever find any solution to this problem? I am running the exact same setup as you.