I program in the platformio.
I use web sockets to exchange data between a web page and a controller. It has always been like this, I have many projects constantly on this principle. But now for some reason as soon as I try to open a web page, my controller reboots. For a long time I did not understand what could be wrong, as a result I found out that the problem is in the web socket.
If you remove the web socket initialization ( ws.onEvent(onEvent);
server.addHandler(&ws);). The server starts and no reboots are observed.
how can this be, i have used this method of working with web server for esp32 so many times, what happened now?
My platformini File.
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
upload_port = COM12
monitor_port = COM12
board_build.partitions = partitions.csv
lib_deps =
ESP Async WebServer
arduino-libraries/Arduino_JSON @ 0.1.0
esphome/ESP32-audioI2S@^2.0.7
My partitions
#Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x4000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 3M,
spiffs, data, spiffs, , 0x50000,
Work with WebServ Lib/
AsyncWebServer server(80);
AsyncWebSocket ws("/ws");
//Event handle
void onEvent(AsyncWebSocket *server, AsyncWebSocketClient *client,AwsEventType type,
void *arg, uint8_t *data, size_t len)
{
switch (type)
{
case WS_EVT_CONNECT:
ESP_LOGE(TAG,"WebSocket client #%u connected from %s", client->id(), client->remoteIP().toString().c_str());
if(sWebServControl.FormSelect == SELECT_FORM_WIFI) FnChangeForm(SELECT_FORM_WIFI); // SELECT_FORM_WIFI SELECT_FORM_SOUND
else FnChangeForm(SELECT_FORM_SOUND);
break;
case WS_EVT_DISCONNECT:
ESP_LOGE(TAG,"WebSocket client #%u disconnected", client->id() );
break;
case WS_EVT_DATA:
// ESP_LOGE(TAG,"WS_EVT_DATA !!!");
handleWebSocketMessage(arg, data, len);
break;
case WS_EVT_PONG:
case WS_EVT_ERROR:
break;
}
}
//init WebSocket
void initWebSocket()
{
test = 0;
ws.onEvent(onEvent);
server.addHandler(&ws);
}
//Init WebServ
void FnStartWebServer(void)
{
initWebSocket();
server.on("/index_main", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(SPIFFS, "/index_main.html", "text/html");
});
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(SPIFFS, "/index_main.html", "text/html", false);
});
server.serveStatic("/", SPIFFS, "/");
server.begin();
}
JS File for init WebSocket
var gateway = `ws://${window.location.hostname}/ws`;
var websocket;
function initWebSocket()
{
console.log('Trying to open a WebSocket connection...');
websocket = new WebSocket(gateway);
websocket.onopen = onOpen;
websocket.onclose = onClose;
websocket.onmessage = onMessage;
}
function onLoad(event)
{
console.log("Start Init Web_SOCKET");
initWebSocket();
}
function onOpen(event)
{
console.log('Connection opened');
}
function onClose(event)
{
console.log('Connection closed');
setTimeout(initWebSocket, 2000);
}
window.addEventListener('load', onLoad);
I repeat, I have used this model of working with a web server many times and it works now in other projects, but it does not work in this project. And even if I copy the working project and try to use it, my controller reboots.
Whenever I try to open a web page in a browser, I get the following error.
ets Jun 8 2016 00:22:57
rst:0x8 (TG1WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13232
load:0x40080400,len:3028
entry 0x400805e4