-
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.
- added support for Ethernet, WiFiEspAT and WiFiNINA - added and reworked examples - change port with begin(port) - README
- Loading branch information
Showing
13 changed files
with
423 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,22 @@ | ||
# TelnetStream | ||
Stream implementation over Telnet for ESP8266 and ESP32 Arduino boards package | ||
|
||
The library creates a TelnetStream object, which can be used the same way as Serial, but the output is sent to a connected telnet client. It enables remote logging or debugging. | ||
|
||
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 library, with WiFiNINA and with WiFiEspAT library. | ||
|
||
Output of example: | ||
|
||
``` | ||
juraj@nuc ~ $ telnet 192.168.1.114 | ||
Trying 192.168.1.114... | ||
Connected to 192.168.1.114. | ||
Escape character is '^]'. | ||
54 2020-07-19 16:50:43 A0: 355 | ||
55 2020-07-19 16:50:48 A0: 335 | ||
56 2020-07-19 16:50:53 A0: 223 | ||
C | ||
bye bye | ||
Connection closed by foreign host. | ||
``` |
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,75 @@ | ||
#include <WiFi.h> | ||
#include <TimeLib.h> | ||
#include <TelnetStream.h> | ||
|
||
const long gmtOffset_sec = 3600; | ||
const int daylightOffset_sec = 3600; | ||
|
||
#include "arduino_secrets.h" | ||
///////please enter your sensitive data in the Secret tab/arduino_secrets.h | ||
const char ssid[] = SECRET_SSID; // your network SSID (name) | ||
const char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
Serial.print("Attempting to connect to WPA SSID: "); | ||
Serial.println(ssid); | ||
WiFi.begin(ssid, pass); | ||
if (WiFi.waitForConnectResult() != WL_CONNECTED) { | ||
Serial.println("Failed to connect."); | ||
while (1) { | ||
delay(10); | ||
} | ||
} | ||
|
||
configTime(gmtOffset_sec, daylightOffset_sec, "pool.ntp.org"); | ||
time_t now = time(nullptr); | ||
while (now < SECS_YR_2000) { | ||
delay(100); | ||
now = time(nullptr); | ||
} | ||
setTime(now); | ||
|
||
IPAddress ip = WiFi.localIP(); | ||
Serial.println(); | ||
Serial.println("Connected to WiFi network."); | ||
Serial.print("Connect with Telnet client to "); | ||
Serial.println(ip); | ||
|
||
TelnetStream.begin(); | ||
} | ||
|
||
void loop() { | ||
switch (TelnetStream.read()) { | ||
case 'R': | ||
TelnetStream.stop(); | ||
delay(100); | ||
ESP.restart(); | ||
break; | ||
case 'C': | ||
TelnetStream.println("bye bye"); | ||
TelnetStream.flush(); | ||
TelnetStream.stop(); | ||
break; | ||
} | ||
|
||
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()); | ||
|
||
TelnetStream.print(i++); | ||
TelnetStream.print(" "); | ||
TelnetStream.print(timeStr); | ||
TelnetStream.print(" A0: "); | ||
TelnetStream.println(analogRead(A0)); | ||
} |
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,2 @@ | ||
#define SECRET_SSID "" | ||
#define SECRET_PASS "" |
76 changes: 76 additions & 0 deletions
76
examples/TelnetStreamEsp8266Test/TelnetStreamEsp8266Test.ino
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,76 @@ | ||
#include <ESP8266WiFi.h> | ||
#include <TimeLib.h> | ||
#include <TelnetStream.h> | ||
#include <sntp.h> | ||
#include <TZ.h> | ||
|
||
#define TIME_ZONE TZ_Europe_London | ||
|
||
#include "arduino_secrets.h" | ||
///////please enter your sensitive data in the Secret tab/arduino_secrets.h | ||
const char ssid[] = SECRET_SSID; // your network SSID (name) | ||
const char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
Serial.print("Attempting to connect to WPA SSID: "); | ||
Serial.println(ssid); | ||
WiFi.begin(ssid, pass); | ||
if (WiFi.waitForConnectResult() != WL_CONNECTED) { | ||
Serial.println("Failed to connect."); | ||
while (1) { | ||
delay(10); | ||
} | ||
} | ||
|
||
configTime(TIME_ZONE, "pool.ntp.org"); | ||
time_t now = time(nullptr); | ||
while (now < SECS_YR_2000) { | ||
delay(100); | ||
now = time(nullptr); | ||
} | ||
setTime(now); | ||
|
||
IPAddress ip = WiFi.localIP(); | ||
Serial.println(); | ||
Serial.println("Connected to WiFi network."); | ||
Serial.print("Connect with Telnet client to "); | ||
Serial.println(ip); | ||
|
||
TelnetStream.begin(); | ||
} | ||
|
||
void loop() { | ||
switch (TelnetStream.read()) { | ||
case 'R': | ||
TelnetStream.stop(); | ||
delay(100); | ||
ESP.reset(); | ||
break; | ||
case 'C': | ||
TelnetStream.println("bye bye"); | ||
TelnetStream.flush(); | ||
TelnetStream.stop(); | ||
break; | ||
} | ||
|
||
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()); | ||
|
||
TelnetStream.print(i++); | ||
TelnetStream.print(" "); | ||
TelnetStream.print(timeStr); | ||
TelnetStream.print(" A0: "); | ||
TelnetStream.println(analogRead(A0)); | ||
} |
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,2 @@ | ||
#define SECRET_SSID "" | ||
#define SECRET_PASS "" |
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,63 @@ | ||
#include <Ethernet.h> | ||
#include <NtpClientLib.h> | ||
#include <TelnetStream.h> | ||
|
||
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; | ||
|
||
void setup() { | ||
|
||
Serial.begin(115200); | ||
|
||
Serial.println("Initialize Ethernet with DHCP:"); | ||
if (Ethernet.begin(mac) == 0) { | ||
Serial.println("Failed to configure Ethernet using DHCP"); | ||
// Check for Ethernet hardware present | ||
if (Ethernet.hardwareStatus() == EthernetNoHardware) { | ||
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); | ||
while (true) { | ||
delay(1); // do nothing, no point running without Ethernet hardware | ||
} | ||
} | ||
if (Ethernet.linkStatus() == LinkOFF) { | ||
Serial.println("Ethernet cable is not connected."); | ||
} | ||
while (true) { | ||
delay(1); // do nothing, no point running without Ethernet hardware | ||
} | ||
} else { | ||
Serial.print(" DHCP assigned IP "); | ||
Serial.println(Ethernet.localIP()); | ||
} | ||
|
||
TelnetStream.begin(); | ||
NTP.begin("pool.ntp.org", 1, false); | ||
} | ||
|
||
void loop() { | ||
|
||
switch (TelnetStream.read()) { | ||
case 'C': | ||
TelnetStream.println("bye bye"); | ||
TelnetStream.flush(); | ||
TelnetStream.stop(); | ||
break; | ||
} | ||
|
||
static unsigned long next; | ||
if (millis() - next > 5000) { | ||
next = millis(); | ||
log(); | ||
} | ||
} | ||
|
||
void log() { | ||
static int i = 0; | ||
TelnetStream.print(i++); | ||
TelnetStream.print(" "); | ||
TelnetStream.print(NTP.getTimeDateString()); | ||
TelnetStream.print(" "); | ||
TelnetStream.print("Uptime: "); | ||
TelnetStream.print(NTP.getUptimeString()); | ||
TelnetStream.print(" since "); | ||
TelnetStream.println(NTP.getTimeDateString(NTP.getFirstSync()).c_str()); | ||
} |
75 changes: 75 additions & 0 deletions
75
examples/TelnetStreamSPIWiFiTest/TelnetStreamSPIWiFiTest.ino
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,75 @@ | ||
#include <WiFiNINA.h> | ||
#include <TimeLib.h> | ||
#include <TelnetStream.h> | ||
|
||
const int8_t TIME_ZONE = 2; // UTC + 2 | ||
|
||
#include "arduino_secrets.h" | ||
///////please enter your sensitive data in the Secret tab/arduino_secrets.h | ||
const char ssid[] = SECRET_SSID; // your network SSID (name) | ||
const char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
if (WiFi.status() == WL_NO_MODULE) { | ||
Serial.println(); | ||
Serial.println("Communication with WiFi module failed!"); | ||
// don't continue | ||
while (true); | ||
} | ||
|
||
// waiting for connection to Wifi network set with the SetupWiFiConnection sketch | ||
Serial.println("Waiting for connection to WiFi"); | ||
WiFi.begin(ssid, pass); | ||
while (WiFi.status() != WL_CONNECTED) { | ||
delay(1000); | ||
Serial.print('.'); | ||
} | ||
Serial.println(); | ||
|
||
Serial.println("Waiting for SNTP"); | ||
while (!WiFi.getTime()) { | ||
delay(1000); | ||
Serial.print('.'); | ||
} | ||
setTime(WiFi.getTime()); | ||
|
||
IPAddress ip = WiFi.localIP(); | ||
Serial.println(); | ||
Serial.println("Connected to WiFi network."); | ||
Serial.print("Connect with Telnet client to "); | ||
Serial.println(ip); | ||
|
||
TelnetStream.begin(); | ||
} | ||
|
||
void loop() { | ||
|
||
switch (TelnetStream.read()) { | ||
case 'C': | ||
TelnetStream.println("bye bye"); | ||
TelnetStream.flush(); | ||
TelnetStream.stop(); | ||
break; | ||
} | ||
|
||
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()); | ||
|
||
TelnetStream.print(i++); | ||
TelnetStream.print(" "); | ||
TelnetStream.print(timeStr); | ||
TelnetStream.print(" A0: "); | ||
TelnetStream.println(analogRead(A0)); | ||
} |
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,2 @@ | ||
#define SECRET_SSID "" | ||
#define SECRET_PASS "" |
Oops, something went wrong.