Skip to content

Commit

Permalink
Use an event loop for WS client repeating actions
Browse files Browse the repository at this point in the history
  • Loading branch information
mairas committed Sep 26, 2024
1 parent 088528a commit b91b3a1
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/sensesp/signalk/signalk_ws_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <HTTPClient.h>
#include <WiFiClient.h>

#include "ReactESP.h"
#include "Arduino.h"
#include "elapsedMillis.h"
#include "sensesp/signalk/signalk_listener.h"
Expand All @@ -24,21 +25,21 @@ SKWSClient* ws_client;
static const char* kRequestPermission = "readwrite";

void ExecuteWebSocketTask(void* /*parameter*/) {
elapsedMillis connect_loop_elapsed = 0;
elapsedMillis delta_loop_elapsed = 0;
auto task_event_loop = reactesp::EventLoop();

ws_client->connect();

task_event_loop.onRepeat(2000, [] {
ws_client->connect();
});

task_event_loop.onRepeat(1, [] {
ws_client->send_delta();
});

while (true) {
if (connect_loop_elapsed > 2000) {
connect_loop_elapsed = 0;
ws_client->connect();
}
if (delta_loop_elapsed > 5) {
delta_loop_elapsed = 0;
ws_client->send_delta();
}
delay(1);
task_event_loop.tick();
delayMicroseconds(100);
}
}

Expand Down

0 comments on commit b91b3a1

Please sign in to comment.