-
Notifications
You must be signed in to change notification settings - Fork 575
Connecting with Pico W #876
-
The main page says Raspberry Pico W is supported, but I cannot get it work.
Connecting to server and upgrading to websocket connection seems to work, but the library does not get into CONNECTED state, stuck in WSC_HEADER state (checked with debugger). From servers side, the websocket channel is OPEN.
The code:
void setup(){
// ... omitted
wsClient.begin(WS_HOST, WS_PORT);
wsClient.onEvent(webSocketEvent);
}
void loop() {
wsClient.loop();
if(!wsClient.sendTXT("sending text")){
Serial.println("Failed to send text");
};
}
Debug messages from the serial port:
[WS-Client] connected to 192.168.0.208:8766.
[WS-Client][sendHeader] sending header...
[WS-Client][sendHeader] handshake GET / HTTP/1.1
Host: 192.168.0.208:8766
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: 3zQTKCo4+M3X4zFf2WJybg==
Sec-WebSocket-Protocol: arduino
Origin: file://
User-Agent: arduino-WebSocket-Client
[write] n: 245 t: 15489
[WS-Client][sendHeader] sending header... Done (1561us).
[WS][0][sendFrame] not in WSC_CONNECTED state!?
Failed to send
I tried adding compile time flags, like -D ARDUINO_ARCH_RP2040=1
, but does not work.
Do I miss something obvious?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments
-
Okay, after doing some more debugging.. The server is sending the upgrade header (Python's websockets)
[DEBUG] server.write_http_response > HTTP/1.1 101 Switching Protocols
[DEBUG] server.write_http_response > Upgrade: websocket
[DEBUG] server.write_http_response > Connection: Upgrade
The arduinoWebSockets libraries gets Upgrade: websocket
but not the the Connection: Upgrade
.
HTTP/1.1 101 Switching Protocols // arrives
Upgrade: websocket // arrives && client->cIsWebsocket = true;
Connection: Upgrade // does not arrive/processed
// server says: ConnectionResetError: [Errno 104] Connection reset by peer
Beta Was this translation helpful? Give feedback.
All reactions
-
Okay.
As far as I can tell, the sendTXT
in the loop was premature.
If I setup a flag/semaphore and enable it in case WStype_CONNECTED:
the client gets all the headers and it is all good.
Beta Was this translation helpful? Give feedback.