You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I added new broadcast function to WebSocketServer class.
Just put something like this in your code:
unsigned long previousTime = 0;
void loop() {
server.listen();
unsigned long currentTime = millis();
if (currentTime - previousTime > 2000) {
previousTime = currentTime;
server.broadcast(TEXT, "hello", 5);
}
}
server will send hello every 2sec to all connected clients.
Alternatively you can add callback to WebSocketServer which would react on message (i.e "getData") and send sensor data. On client side send this message ("getData") every X seconds.
That's great, the "Broadcast" really is what i needed, i had tried already as you said by "getData" but it proved to be too slow since i need to send data from the server each 100ms. Broadcast does the trick.
I got the simple-server. ino and the JS chat-client running straight out of the box, no issues, works like a charm.
my Q is, i would like to add a function in the arduino INO where i send sensor data on regular intervals to the client.
something like:
How can i do this the best and easiest way?
The text was updated successfully, but these errors were encountered: