-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for multiple connected clients
and more networking libraries supported
- Loading branch information
Showing
5 changed files
with
145 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=TelnetStream | ||
version=1.0.0 | ||
version=1.1.0 | ||
author=Juraj Andrassy | ||
maintainer=Juraj Andrassy <[email protected]> | ||
sentence=Stream implementation over telnet for OTA debuging | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
ArduinoWiFiServer.h - Arduino compatible WiFiServer | ||
implementation for ESP8266/ESP32 Arduino Wifi library. | ||
Copyright (c) 2020 Juraj Andrassy | ||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#ifndef arduinowifiserver_h | ||
#define arduinowifiserver_h | ||
|
||
#ifdef ESP8266 | ||
#include <ESP8266WiFi.h> | ||
#else | ||
#include <WiFi.h> | ||
#endif | ||
|
||
#ifndef MAX_MONITORED_CLIENTS | ||
#define MAX_MONITORED_CLIENTS 5 | ||
#endif | ||
|
||
class ArduinoWiFiServer : public WiFiServer { | ||
public: | ||
|
||
ArduinoWiFiServer(const IPAddress& addr, uint16_t port) : WiFiServer(addr, port) {} | ||
ArduinoWiFiServer(uint16_t port) : WiFiServer(port) {} | ||
virtual ~ArduinoWiFiServer() {} | ||
|
||
// https://www.arduino.cc/en/Reference/EthernetServerAccept | ||
WiFiClient accept() {return WiFiServer::available();} | ||
|
||
// https://www.arduino.cc/en/Reference/WiFiServerAvailable | ||
WiFiClient available() { | ||
|
||
// update connected clients | ||
for (uint8_t i = 0; i < MAX_MONITORED_CLIENTS; i++) { | ||
if (!connectedClients[i]) { | ||
connectedClients[i] = accept(); | ||
} | ||
} | ||
// find next client with data available | ||
for (uint8_t i = 0; i < MAX_MONITORED_CLIENTS; i++) { | ||
if (index == MAX_MONITORED_CLIENTS) { | ||
index = 0; | ||
} | ||
WiFiClient& client = connectedClients[index]; | ||
index++; | ||
if (client.available()) | ||
return client; | ||
} | ||
return WiFiClient(); // no client with data found | ||
} | ||
|
||
virtual size_t write(uint8_t b) override { | ||
return write(&b, 1); | ||
} | ||
|
||
virtual size_t write(const uint8_t *buf, size_t size) override { | ||
size_t ret = 0; | ||
for (uint8_t i = 0; i < MAX_MONITORED_CLIENTS; i++) { | ||
WiFiClient& client = connectedClients[i]; | ||
if (client) { | ||
ret = client.write(buf, size); | ||
} | ||
} | ||
return ret; | ||
} | ||
|
||
using Print::write; | ||
|
||
virtual void flush() { | ||
for (uint8_t i = 0; i < MAX_MONITORED_CLIENTS; i++) { | ||
if (connectedClients[i]) { | ||
connectedClients[i].flush(); | ||
} | ||
} | ||
} | ||
|
||
#ifdef ESP8266 | ||
operator bool() {return (status() == LISTEN);} | ||
#endif | ||
|
||
private: | ||
WiFiClient connectedClients[MAX_MONITORED_CLIENTS]; | ||
uint8_t index = 0; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters