diff --git a/README.md b/README.md index 7898a58..94f5ada 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,9 @@ The library creates a TelnetStream object, which can be used the same way as Ser TelnetStream.h can be included not only in the ino file, but in cpp files of the sketch or in libraries to add debug prints for troubleshooting. -TelnetStream works as it is with esp8266 and esp32 WiFi library, with the Ethernet, EthernetENC and UIPEthernet library, with WiFiNINA, WiFi101 and with WiFiEspAT library. +Version 1.2.0 introduced TelnetPrint object, a simpler and smaller alternative to TelnetStream. Basically it is only EthernetServer or WiFiServer instanced for use anywhere in your sketch or libraries. + +TelnetStream/TelnetPrint works as it is with esp8266 and esp32 WiFi library, with the Ethernet, EthernetENC and UIPEthernet library, with WiFiNINA, WiFi101 and with WiFiEspAT library. The library is in Library Manager. You can install it there. diff --git a/examples/TelnetPrintEthTest/TelnetPrintEthTest.ino b/examples/TelnetPrintEthTest/TelnetPrintEthTest.ino new file mode 100644 index 0000000..8ec03eb --- /dev/null +++ b/examples/TelnetPrintEthTest/TelnetPrintEthTest.ino @@ -0,0 +1,55 @@ +#include +#include +#include + +byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; +IPAddress myIP(192, 168, 1, 177); + +void setup() { + + Serial.begin(115200); + + Ethernet.init(10); + Ethernet.begin(mac, myIP); + + //TelnetPrint = NetServer(2323); // uncomment to change port + TelnetPrint.begin(); + + Serial.println("Test started"); +} + +void loop() { + NetClient client = TelnetPrint.available(); + if (client) { + int c = client.read(); + switch (c) { + case 'C': + client.println("bye bye"); + client.flush(); + client.stop(); + break; + default: + Serial.write(c); + } + } + + static unsigned long next; + if (millis() - next > 5000) { + next = millis(); + log(); + } +} + +void log() { + static int i = 0; + + char timeStr[20]; + sprintf(timeStr, "%02d-%02d-%02d %02d:%02d:%02d", year(), month(), day(), hour(), minute(), second()); + + TelnetPrint.print(i++); + TelnetPrint.print(" "); + TelnetPrint.print(timeStr); + TelnetPrint.print(" A0: "); + TelnetPrint.println(analogRead(A0)); +} + diff --git a/library.properties b/library.properties index fac08b3..b3e6599 100755 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TelnetStream -version=1.1.0 +version=1.2.0 author=Juraj Andrassy maintainer=Juraj Andrassy sentence=Stream implementation over telnet for OTA debuging @@ -7,4 +7,5 @@ paragraph= category=Communication url=https://github.com/jandrassy/TelnetStream architectures=* -includes=TelnetStream.h +includes=TelnetStream.h,TelnetPrint.h +dot_a_linkage=true diff --git a/src/NetTypes.h b/src/NetTypes.h new file mode 100644 index 0000000..b72ba34 --- /dev/null +++ b/src/NetTypes.h @@ -0,0 +1,61 @@ +/* +Copyright (C) 2020 Juraj Andrassy +repository https://github.com/jandrassy + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +#ifndef _NETTYPES_H_ +#define _NETTYPES_H_ + +#include // to include MCU specific includes for networking library + +#if __has_include() +#include +#define NetClient EthernetClient +#define NetServer EthernetServerPrint + +#elif __has_include() +#include +#define NetClient EthernetClient +#define NetServer EthernetServer + +#elif defined(ESP8266) +#include +#include "ArduinoWiFiServer.h" +#define NetClient WiFiClient +#define NetServer ArduinoWiFiServer + +#elif defined(ESP32) +#include +#include "ArduinoWiFiServer.h" +#define NetClient WiFiClient +#define NetServer ArduinoWiFiServer + +#elif __has_include() +#include +#define NetClient WiFiClient +#define NetServer WiFiServer + +#elif __has_include() +#include +#define NetClient WiFiClient +#define NetServer WiFiServerPrint +#else +#include +#define NetClient WiFiClient +#define NetServer WiFiServer +#endif + +#endif diff --git a/src/TelnetPrint.cpp b/src/TelnetPrint.cpp new file mode 100644 index 0000000..d8be34a --- /dev/null +++ b/src/TelnetPrint.cpp @@ -0,0 +1,3 @@ +#include "TelnetPrint.h" + +NetServer TelnetPrint(23); diff --git a/src/TelnetPrint.h b/src/TelnetPrint.h new file mode 100644 index 0000000..2f4b261 --- /dev/null +++ b/src/TelnetPrint.h @@ -0,0 +1,8 @@ +#ifndef _TELNETPRINT_H_ +#define _TELNETPRINT_H_ + +#include "NetTypes.h" + +extern NetServer TelnetPrint; + +#endif diff --git a/src/TelnetStream.cpp b/src/TelnetStream.cpp index 7250a8d..fe785e4 100644 --- a/src/TelnetStream.cpp +++ b/src/TelnetStream.cpp @@ -1,4 +1,3 @@ -#include // to include MCU specific includes for networking library #include "TelnetStream.h" TelnetStreamClass::TelnetStreamClass(uint16_t port) :server(port) { @@ -28,7 +27,7 @@ boolean TelnetStreamClass::disconnected() { if (!server) return true; #endif - + if (!client || !client.available()) { client = server.available(); // try to get next client with data } diff --git a/src/TelnetStream.h b/src/TelnetStream.h index 83be093..74de8cf 100644 --- a/src/TelnetStream.h +++ b/src/TelnetStream.h @@ -19,32 +19,7 @@ repository https://github.com/jandrassy #ifndef _TELNETSTREAM_H_ #define _TELNETSTREAM_H_ -#if __has_include() -#include -#define NetClient EthernetClient -#define NetServer EthernetServer -#elif defined(ESP8266) -#include -#define NetClient WiFiClient -#elif __has_include() -#include -#define NetClient WiFiClient -#define NetServer WiFiServer -#else -#include -#define NetClient WiFiClient -#define NetServer WiFiServer -#endif - -// special server types -#if defined(ESP32) || defined(ESP8266) -#include "ArduinoWiFiServer.h" -#define NetServer ArduinoWiFiServer -#elif defined(_WIFI_ESP_AT_H_) // from WiFi.h -#define NetServer WiFiServerPrint -#elif __has_include() -#define NetServer EthernetServerPrint -#endif +#include "NetTypes.h" class TelnetStreamClass : public Stream {