Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Connecting with Pico W #876

Unanswered
andzsinszan asked this question in Q&A
Discussion options

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?

You must be logged in to vote

Replies: 2 comments

Comment options

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
You must be logged in to vote
0 replies
Comment options

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.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /