LennartHennigs / ESPTelnet

ESP library that allows you to setup a telnet server for debugging.
MIT License
215 stars 35 forks source link
arduino debugging esp32 esp8266 esp8266-arduino telnet

ESPTelnet

ESP8266/ESP32 library that allows you to setup a telnet server.

Description

Use this library to set up a the telnet server to communicate status messages or debug / error log output. This is especially useful when you don't have a serial connection to the ESP.

It has been tested with ESP8266 and ESP32 devices.

To see the latest changes to the library please take a look at the Changelog.

If you find this library helpful please consider giving it a ⭐️ at GitHub and/or buy me a ☕️. Thanks!

How To Use

Starting / Stopping

Callback Handlers

Output and Input

Using stream functions

Using ANSI Escape Sequences 🆕

Using it to Debug Code

The Loop

Examples

Notes

Class Definition

These are the constructors and the member functions the library provides:

ESPTelnet Definition

    ESPTelnet();

    bool begin(uint16_t port = 23, bool checkConnection = true);
    void loop();
    void stop();

    void print(const String &str);
    void println(const String &str);
    void print(const char c);
    void println(const char c);
    void print(unsigned char b, int base);
    void println(unsigned char b, int base);
    void print(int n, int base);
    void println(int n, int base);
    void print(unsigned int n, int base);
    void println(unsigned int n, int base);
    void print(const Printable& x);
    void println(const Printable& x);
    void println();
    size_t printf(const char *format, ...);

    String getIP() const;
    String getLastAttemptIP() const;

    bool isConnected();
    void setKeepAliveInterval(int ms);
    int getKeepAliveInterval();

    bool isLineModeSet();
    void setLineMode(bool value = true);

    char getNewlineCharacter();
    void setNewlineCharacter(char value = '\n');

    void onConnect(CallbackFunction f);
    void onConnectionAttempt(CallbackFunction f);
    void onReconnect(CallbackFunction f);
    void onDisconnect(CallbackFunction f);
    void onInputReceived(CallbackFunction f);

    void disconnectClient(bool triggerEvent = true);

ESPTelnetStream Definition

    ESPTelnetStream();

    bool begin(uint16_t port = 23, bool checkConnection = true);
    void loop();
    void stop();

    int available();
    int read();
    int peek();
    void flush();
    size_t write(uint8_t);

    String getIP() const;
    String getLastAttemptIP() const;

    bool isConnected();
    void setKeepAliveInterval(int ms);
    int getKeepAliveInterval();

    void onConnect(CallbackFunction f);
    void onConnectionAttempt(CallbackFunction f);
    void onReconnect(CallbackFunction f);
    void onDisconnect(CallbackFunction f);
    void onInputReceived(CallbackFunction f);

    void disconnectClient(bool triggerEvent = true);

Installation

Open the Arduino IDE choose "Sketch > Include Library" and search for "ESPTelnet". Or download the ZIP archive, and choose "Sketch > Include Library > Add .ZIP Library..." and select the downloaded file.

The "ESPTelnet" library is also available on the PlatformIO registry and can be included by adding the following line to the leb_deps option of the platformio.ini file:

   lennarthennigs/ESP Telnet@^2.2.2

License

MIT License

Copyright (c) 2018-2024 Lennart Hennigs

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.