1

I am creating home automation using esp's and little home server. Idea is to connect arduinos to server, add each of them id and let them talk via websockets with server and server will forward (by some logic inside) messages to different arduinos. Pretty simple.

What I found, is that I cannot tell, what websocket client I am talking to. I use simple example from lib: https://github.com/gilmaimon/ArduinoWebsockets

client.onMessage(onMessageCallback);
client.onEvent(onEventsCallback);
client.connect(websockets_server_host, websockets_server_port, "/");
client.ping();

My idea is to send id of arduino with connection handshake. Is it even possible?

4
  • This is a websocket client code. The client is not talking to other clients, but the server. He doesn't need to differentiate clients.
    – Sim Son
    Dec 7, 2021 at 18:33
  • Exactly. Server will forward messages from one client to antoher. Problem is, that on server side I have multiple clients, that I cannot distinguish so I need each client to identify itself when it connect
    – 110mat110
    Dec 7, 2021 at 19:16
  • You can even add your device id with every message you send to the server.
    – Fahad
    Dec 7, 2021 at 22:19
  • I like to pass a an identifying GET param in the websocket URL (eg. system_get_chip_id()), then the PC-based server socket lib has a (sometimes roundabout) way of getting the request URL to id who's asking.
    – dandavis
    Dec 8, 2021 at 18:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.