Closed andreapas79 closed 4 years ago
Hi, sorry for the long delay.
There are a few questions here, I'll try answering all of them.
Currently, the client object will only work for one connection. Meaning you cannot use the same instance for connect(...)
twice (for example, calling connect
after the client disconnected once).
The solution for that is doing:
WebsocketsClient client;
// ...
client = {}; // This will reset the client object
The code for receiving websocket messages are executed in your loop
(client.poll
does the work).
You can always do multiple stuff, for example:
// update interval is 10 seconds in this example
#define UPDATE_INTERVAL (1000 * 10)
int last_update_sent = 0;
void loop() {
if (millis() - last_update_sent > UPDATE_INTERVAL) {
client.send("here is an update");
last_update_sent = millis();
}
// we execute poll anyways
client.poll();
}
This might be a bug, but it might also be a usage issue. Do you sleep between sending messages? If you won't give the firmware some time to do it's internal stuff (handle incoming and send outgoing tcp buffers) it might result in a disconnect. Unless you are doing some task that requires extremely short update intervals, just sleep in your loop and you'll be fine :)
Thanks. Gil.
Closing for inactivity, hopefully I resolved your issues.
Hi, really nice work, your library is really useful. My problem is this I have a WebSocket server with python and some clients with your WebSockets. Sometime after sending 100/200 messages, the client disconnect from the server and I cannot able to reconnect again...I must reset the client to work it again. Another question: how can I manage sending a message(for example sensor data) without interrupting listening, I tried with interrupts but restart the connection every time. Until now the only way I found, it's during GotPing event, some other ideas?