Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: JAndrassy/TelnetStream
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.3.0
Choose a base ref
...
head repository: JAndrassy/TelnetStream
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Jul 20, 2024

  1. Verified

    This commit was signed with the committer’s verified signature.
    snyk-bot Snyk bot
    Copy the full SHA
    044ef73 View commit details

Commits on Aug 2, 2024

  1. NetTypes - WiFiEspAT v2 support

    and EthernetEspAT support (#elif moved above "has Ethernet.h|)
    JAndrassy committed Aug 2, 2024
    Copy the full SHA
    d59b586 View commit details

Commits on Aug 3, 2024

  1. Copy the full SHA
    ac640b8 View commit details
Showing with 101 additions and 8 deletions.
  1. +88 −0 examples/TelnetStreamSerialEthTest/TelnetStreamSerialEthTest.ino
  2. +2 −3 examples/TelnetStreamSerialWiFiTest/TelnetStreamSerialWiFiTest.ino
  3. +11 −5 src/NetTypes.h
88 changes: 88 additions & 0 deletions examples/TelnetStreamSerialEthTest/TelnetStreamSerialEthTest.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include <EthernetEspAT.h>
#include <TimeLib.h>
#include <TelnetStream.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

void setup() {

Serial.begin(115200);
while (!Serial);

Serial1.begin(115200);
Ethernet.init(Serial1);

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
}
}

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());
}

WiFi.sntp("us.pool.ntp.org");
Serial.println("Waiting for SNTP");
while (!Ethernet.getTime()) {
delay(1000);
Serial.print('.');
}
setTime(Ethernet.getTime());

IPAddress ip = Ethernet.localIP();
Serial.println();
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));
TelnetStream.flush();
}
Original file line number Diff line number Diff line change
@@ -2,8 +2,6 @@
#include <TimeLib.h>
#include <TelnetStream.h>

const int8_t TIME_ZONE = 2; // UTC + 2

void setup() {
Serial.begin(115200);

@@ -25,7 +23,7 @@ void setup() {
}
Serial.println();

WiFi.sntp(TIME_ZONE, "us.pool.ntp.org");
WiFi.sntp("us.pool.ntp.org");

Serial.println("Waiting for SNTP");
// while (!WiFi.getTime()) {
@@ -71,4 +69,5 @@ void log() {
TelnetStream.print(timeStr);
TelnetStream.print(" A0: ");
TelnetStream.println(analogRead(A0));
TelnetStream.flush();
}
16 changes: 11 additions & 5 deletions src/NetTypes.h
Original file line number Diff line number Diff line change
@@ -53,6 +53,17 @@ repository https://github.com/jandrassy
#define NetClient EthernetClient
#define NetServer ArduinoEthernetServer

#elif __has_include(<WiFiEspAT.h>)
#include <WiFiEspAT.h>
#define NetClient WiFiClient
#if WIFIESPAT_LIB_VERSION < 2
#define NetServer WiFiServerPrint
#else
#include <NetApiHelpers.h>
#include <ArduinoWiFiServer.h>
#define NetServer ArduinoWiFiServer
#endif

#elif __has_include(<Ethernet.h>)
#include <Ethernet.h>
#define NetClient EthernetClient
@@ -68,11 +79,6 @@ repository https://github.com/jandrassy
#define NetClient WiFiClient
#define NetServer WiFiServer

#elif __has_include(<WiFiEspAT.h>)
#include <WiFiEspAT.h>
#define NetClient WiFiClient
#define NetServer WiFiServerPrint

#elif (defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED)) || (defined(ARDUINO_ARCH_MBED) && !defined(ARDUINO_ARCH_MBED_NANO))
#include <WiFi.h>
#include <NetApiHelpers.h>