skaarj1989 / mWebSockets

WebSockets for microcontrollers
https://skaarj1989.github.io/mWebSockets/autobahn-testsuite/servers/
MIT License
106 stars 22 forks source link

WebSocket client is not connecting to any server ( online ) not local #76

Closed buffed-ets closed 6 days ago

buffed-ets commented 2 months ago

WebSocket client is not connecting to the actual server ( echo.websocket.org ) but i can connect to local node server

I'm using Ethernet module W5500 with [Mega 2560 PRO MINI]

here is my code logs after uploading it, its attempting to connect to echo.websocket.org but fails!

Screenshot 2024-09-03 182436

here is another attempt trying to connect it to a local server ( node )

image

as you can see its connecting and sending data properly

here is my code


include

include

using namespace net;

byte mac[]{0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};

WebSocketClient client;

int Light1 = 1; int Light2 = 0; int gas1 = 22.3; void setup() { Serial.begin(115200); Ethernet.init(53); Ethernet.begin(mac); Serial.print(F("Device IP: ")); Serial.println(Ethernet.localIP()); client.onOpen([](WebSocket &ws) { Serial.println(F("Connected"));

JsonDocument Home_status;
Home_status["rooms"]["room1"]["Light"] = Light1;
Home_status["rooms"]["room1"]["ac"] = Light2;
Home_status["rooms"]["room1"]["gas"] = gas1;
Home_status["rooms"]["room2"]["Light"] = Light1;
Home_status["rooms"]["room2"]["ac"] = Light2;
Home_status["rooms"]["room2"]["gas"] = gas1;
char json_string[256];
serializeJson(Home_status, json_string);

 ws.send(WebSocket::DataType::TEXT, json_string, strlen(json_string));
 Serial.print("msg sent");
}
);

client.onMessage([](WebSocket &ws, const WebSocket::DataType dataType, const char message, uint16_t length) { switch (dataType) { case WebSocket::DataType::TEXT: Serial.print(F("Received: ")); Serial.println(message); break; case WebSocket::DataType::BINARY: Serial.println(F("Received binary data")); break; } ws.send(dataType, message, length); // Echo back to server }); client.onClose([](WebSocket &, const WebSocket::CloseCode, const char , uint16_t) {Serial.println(F("Disconnected\n")); });

if (!client.open("echo.websocket.org", 80,"/")) {

Serial.println(F("Connection failed!"));
while (true);
}

}

void loop() { client.listen(); }


my goal is to get it to connect to an online server kindly help me.

skaarj1989 commented 1 month ago

If I remember correctly echo.websocket.org was closed a few years ago. Have you tried any other (non-local network) server? (mind that WebSocket Secure is not supported).

buffed-ets commented 1 month ago

i have tried my own server: tserver-production.up.railway.app it works when i used postman

image

it didn't work Aswell "mind that WebSocket Secure is not supported" is there a way to be able to connect to secure websocket ?

stale[bot] commented 3 weeks ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.