-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebSocket is already in CLOSING or CLOSED state. #6
Comments
Hi! Thank you for opening an issue. What your code in
So, for every iteration of void loop() {
auto client = server.accept();
while(client.available()) {
Serial.println("client.available");
auto msg = client.readBlocking();
// log
Serial.print("Got Message: ");
Serial.println(msg.data());
}
} Notice how I changed the Few notes:
You can get rid of those checks if you use the callback-based interface. It will look like this: void handle_message(WebsocketsMessage msg) {
// log
Serial.print("Got Message: ");
Serial.println(msg.data());
}
void loop() {
auto client = server.accept();
client.onMessage(handle_message);
while(client.available()) {
client.poll();
}
} This code accepts a connection, and while the connection is open, does Gil. |
Thanks for your detailed response. The final project is to add pan and tilt to an ESP32 based camera board. For this I need to send a 'stream' of jpgs from the camera to the browser and the browser to be able to send a 'stream' of co-ordinates (from a touch interface) to the ESP. I've tried nearly every combination of async, sync http and websocket servers to get this working and the solution is always just around the corner! Your code below worked perfectly the first time I tried
I had the servo whizzing back and forth but now it stops after a bit with the same error but I think this is because the ESP32 has locked up. Maybe it's Wifi related that it worked better before. I should probably restrict the number of times coordinates are sent from the browser. This code worked really well for streaming the camera data:
I'll try again with it tomorrow. Here's my messy code if you want to try it: https://pastebin.com/cs0CSntM |
Interesting. You can try adding some delay between calls to poll. Also it is a very good idea to add delays between Also, if you want to see more info about the errors with the esp32, change the board to "ESP32 Dev Module" and change Share the crash/fail logs here, it might help. Also, where do you see the error "WebSocket is already in CLOSING or CLOSED state"? Is it in the browser that sends the data or in the esp32? Gil. |
Is it working now? |
I got distracted by another project. I'll get back to this one soon! |
I'm not sure I'm doing this right. I'm want to send a stream of co-ordinates from the browser and drive a servo based on them, I get one though and then the browser error shown in the subject line above. Code pasted below.
Maybe auto client = server.accept(); should be outside the loop?
The text was updated successfully, but these errors were encountered: