From fa1d1619b607ddfbd9cd6f133dbe73cb6fbc7c13 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sun, 26 Sep 2021 08:37:59 +0200 Subject: [PATCH] wifi sendData --- WifiESP.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/WifiESP.cpp b/WifiESP.cpp index e99b1a9..36040f1 100644 --- a/WifiESP.cpp +++ b/WifiESP.cpp @@ -46,20 +46,22 @@ static void handleData(void* arg, AsyncClient* client, void *data, size_t len) { byte cmd[len+1]; memcpy(cmd,data,len); cmd[len]=0; + outboundRing->mark(clientId); CommandDistributor::parse(clientId,cmd,outboundRing); + outboundRing->commit(); } +} + +bool sendData(uint8_t clientId, char* data, int count) { + AsyncClient *client = clients[clientId]; + // reply to client - int c; - if (client->space() >= (c=outboundRing->count()) && client->canSend()) { - char cmd[c+1]; - int i; - for (i=0;iread(); - } - cmd[i]=0; - client->add(cmd, strlen(cmd)); + if (client->space() >= count && client->canSend()) { + client->add(data, count); client->send(); + return true; } + return false; } static void handleDisconnect(void* arg, AsyncClient* client) { @@ -117,7 +119,12 @@ bool WifiESP::setup(const char *wifiESSID, return true; } + void WifiESP::loop() { + + // Do something with outboundRing + // call sendData + static unsigned long last = 0; if (millis() - last > 60000) { last = millis();