Skip to content

nelopauselli/esp8266-telnet-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

esp8266-telnet-server

A telnet server on esp8266 open to extend the commands

This code was written using PlatformIO and vscode. Would you like This code to be compatible with the Arduino IDE?... tell me!

Getting started

#include "TelnetServer.h"

TelnetServer telnet(23);
void setup() {
    telnet.start();
}

void loop() 
    telnet.process();
}

Add a custom command handler

void setup() {
    // we should add all command handlers before start method invoked
    telnet.add(new LedBuiltInOnCommand());

    telnet.start();
}

Define a custom command handler (for example: turn on LED_BUILTIN)

#include <Command.h>

class LedBuiltInOnCommand : public Command
{
  public:
    /**
     * try handle command
     */
    bool process(char *line, WiFiClient *socket) override
    {
        if (strcmp(line, "LED BUILTIN ON") == 0)
        {
            digitalWrite(LED_BUILTIN, LOW); // this led on with LOW
            socket->write("OK\r\n"); // send a 'OK' to client
            delay(1);

            return true; // return 'I've handled the command'
        }
        return false; //if command isn't 'LED BUILTIN ON' then try with next handler 
    }

    /**
     * Help about this command handler
     */
    void help(WiFiClient *socket) override
    {
        socket->write("LED BUILTIN ON: turn on LED_BUILTIN\r\n");
    }
};

Telnet client

When connection is success

PuTTY console

When commands are executed

PuTTY console

About

A telnet server on esp8266

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages