arduinoWebSockets
arduinoWebSockets copied to clipboard
ATmega2560 with Ethernet Shield Can't connect to Server.
I'm using an arduino with ATmega2560 with Ethernet shield. I'm using version 1.3, trying to connect to a NodeJs websocket server. On server side, I'm using express-ws, which uses ws.
I tried to connect to the server with my computer and my phone. Everything went fine.
However, when I tried to connect with arduino, I got this error on the server:
RangeError: Invalid WebSocket frame: RSV2 and RSV3 must be clear
at Receiver.getInfo (/media/theneverchosen/MyDocs/Documents/DevSpace/Projects/remote-lab-back/node_modules/ws/lib/receiver.js:171:14)
at Receiver.startLoop (/media/theneverchosen/MyDocs/Documents/DevSpace/Projects/remote-lab-back/node_modules/ws/lib/receiver.js:131:22)
at Receiver._write (/media/theneverchosen/MyDocs/Documents/DevSpace/Projects/remote-lab-back/node_modules/ws/lib/receiver.js:78:10)
at writeOrBuffer (node:internal/streams/writable:389:12)
at _write (node:internal/streams/writable:330:10)
at Receiver.Writable.write (node:internal/streams/writable:334:10)
at Socket.socketOnData (/media/theneverchosen/MyDocs/Documents/DevSpace/Projects/remote-lab-back/node_modules/ws/lib/websocket.js:1102:35)
at Socket.emit (node:events:390:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9) {
code: 'WS_ERR_UNEXPECTED_RSV_2_3',
[Symbol(status-code)]: 1002
}
The arduino can't connect and keeps firing the WStype_DISCONNECTED
event.
Arduino code:
#include <SPI.h>
#include <Ethernet.h>
#include <WebSocketsClient.h>
WebSocketsClient client;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 177);
void webSocketEvent(WStype_t type, uint8_t *payload, size_t length){
switch(type) {
case WStype_DISCONNECTED:
Serial.println("[WSc] Disconnected!\n");
break;
case WStype_CONNECTED:
Serial.print("[WSc] Connected to url: ");
Serial.println((char *) payload);
break;
case WStype_TEXT:
Serial.print("[WSc] get text: ");
Serial.println((char *)payload);
break;
case WStype_BIN:
Serial.print("[WSc] get binary length: ");
Serial.println(length);
break;
}
}
void setup(){
Serial.begin(9600);
while(!Serial){}
if(Ethernet.begin(mac) == 0){
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip);
}
client.begin("192.168.100.10", 3333, "/arduino");
client.onEvent(webSocketEvent);
}
void loop(){
client.loop();
}
I have the same issue. is anybody can help?
+1