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!
#include "TelnetServer.h"
TelnetServer telnet(23);
void setup() {
telnet.start();
}
void loop()
telnet.process();
}
void setup() {
// we should add all command handlers before start method invoked
telnet.add(new LedBuiltInOnCommand());
telnet.start();
}
#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");
}
};