1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-30 03:26:13 +01:00

wifi sendData

This commit is contained in:
Harald Barth 2021-09-26 08:37:59 +02:00
parent b048879eaa
commit fa1d1619b6

View File

@ -46,20 +46,22 @@ static void handleData(void* arg, AsyncClient* client, void *data, size_t len) {
byte cmd[len+1]; byte cmd[len+1];
memcpy(cmd,data,len); memcpy(cmd,data,len);
cmd[len]=0; cmd[len]=0;
outboundRing->mark(clientId);
CommandDistributor::parse(clientId,cmd,outboundRing); CommandDistributor::parse(clientId,cmd,outboundRing);
outboundRing->commit();
} }
}
bool sendData(uint8_t clientId, char* data, int count) {
AsyncClient *client = clients[clientId];
// reply to client // reply to client
int c; if (client->space() >= count && client->canSend()) {
if (client->space() >= (c=outboundRing->count()) && client->canSend()) { client->add(data, count);
char cmd[c+1];
int i;
for (i=0;i<c;i++) {
cmd[i]=outboundRing->read();
}
cmd[i]=0;
client->add(cmd, strlen(cmd));
client->send(); client->send();
return true;
} }
return false;
} }
static void handleDisconnect(void* arg, AsyncClient* client) { static void handleDisconnect(void* arg, AsyncClient* client) {
@ -117,7 +119,12 @@ bool WifiESP::setup(const char *wifiESSID,
return true; return true;
} }
void WifiESP::loop() { void WifiESP::loop() {
// Do something with outboundRing
// call sendData
static unsigned long last = 0; static unsigned long last = 0;
if (millis() - last > 60000) { if (millis() - last > 60000) {
last = millis(); last = millis();