Skip to content

Commit

Permalink
TelnetStreamExample.ino has errors that prevent it from compiling
Browse files Browse the repository at this point in the history
Fixes #72
  • Loading branch information
LennartHennigs committed Jan 18, 2025
1 parent c84ddd5 commit fad0695
Showing 1 changed file with 82 additions and 8 deletions.
90 changes: 82 additions & 8 deletions examples/TelnetStreamExample/TelnetStreamExample.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,102 @@
/* ------------------------------------------------- */

#define SERIAL_SPEED 9600
#define INFRA_SSID "MY SSID"
#define INFRA_PSWD "MY PASS"
#define WIFI_SSID "MY SSID"
#define WIFI_PASSWORD "MY PASS"

/* ------------------------------------------------- */

ESPTelnetStream telnet;
IPAddress ip;
uint16_t port = 23;

/* ------------------------------------------------- */

void telnetConnected(String ip) {
bool isConnected() {
return (WiFi.status() == WL_CONNECTED);
}

/* ------------------------------------------------- */

void errorMsg(String error, bool restart = true) {
Serial.println(error);
if (restart) {
Serial.println("Rebooting now...");
delay(2000);
ESP.restart();
delay(2000);
}
}

/* ------------------------------------------------- */

// (optional) callback functions for telnet events
void onTelnetConnect(String ip) {
Serial.print("- Telnet: ");
Serial.print(ip);
Serial.println(" connected.");
Serial.println(" connected");

telnet.println("\nWelcome " + telnet.getIP());
telnet.println("(Use ^] + q to disconnect.)");
}

void telnetDisconnected(String ip) {
/* ------------------------------------------------- */

void onTelnetDisconnect(String ip) {
Serial.print("- Telnet: ");
Serial.print(ip);
Serial.println(" disconnected.");
Serial.println(" disconnected");
}

void telnetReconnect(String ip) {
/* ------------------------------------------------- */

void onTelnetReconnect(String ip) {
Serial.print("- Telnet: ");
Serial.print(ip);
Serial.println(" reconnected.");
Serial.println(" reconnected");
}

/* ------------------------------------------------- */

void onTelnetConnectionAttempt(String ip) {
Serial.print("- Telnet: ");
Serial.print(ip);
Serial.println(" tried to connected");
}

/* ------------------------------------------------- */

void onTelnetInput(String str) {
// checks for a certain command
if (str == "ping") {
telnet.println("> pong");
Serial.println("- Telnet: pong");
// disconnect the client
} else if (str == "bye") {
telnet.println("> disconnecting you...");
telnet.disconnectClient();
} else {
telnet.println(str);
}
}

/* ------------------------------------------------- */

void setupTelnet() {
// passing on functions for various telnet events
telnet.onConnect(onTelnetConnect);
telnet.onConnectionAttempt(onTelnetConnectionAttempt);
telnet.onReconnect(onTelnetReconnect);
telnet.onDisconnect(onTelnetDisconnect);
telnet.onInputReceived(onTelnetInput);

Serial.print("- Telnet: ");
if (telnet.begin(port)) {
Serial.println("running");
} else {
Serial.println("error.");
errorMsg("Will reboot...");
}
}

/* ------------------------------------------------- */
Expand Down

0 comments on commit fad0695

Please sign in to comment.