Created
July 31, 2019 18:02
-
-
Save williamtoader/e02a704a8127276fd5745a6c61648c55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <WiFiClient.h> | |
#include <WiFiServer.h> | |
#include <ESP8266WebServer.h> | |
#define ASSID "HelixLink" | |
#define APSK "********" | |
const char *ssid = ASSID; | |
const char *password = APSK; | |
// the router's gateway address: | |
IPAddress gateway(192, 168, 0, 1); | |
// the subnet: | |
IPAddress subnet(255, 255, 255, 0); | |
//the IP address is dependent on your network | |
IPAddress ip(192, 168, 0, 1); | |
WiFiServer server(23); | |
WiFiClient Telnet; | |
void handleTelnet(){ | |
if (server.hasClient()){ | |
// client is connected | |
if (!Telnet || !Telnet.connected()){ | |
if(Telnet) Telnet.stop(); // client disconnected | |
Telnet = server.available(); // ready for new client | |
} else { | |
server.available().stop(); // have client, block new conections | |
} | |
} | |
if (Telnet && Telnet.connected() && Telnet.available()){ | |
if(Telnet.available()){ | |
String str = Telnet.readStringUntil('\n'); | |
Serial.println(str); | |
} | |
} | |
if(Telnet && Telnet.connected() && Serial.available()>0){ | |
String str = Serial.readStringUntil('\n'); | |
Telnet.println(str); | |
Telnet.flush(); | |
} | |
} | |
void setup() { | |
WiFi.mode(WIFI_AP); | |
WiFi.softAP(ssid,password); | |
WiFi.softAPConfig(ip, gateway, subnet); | |
server.begin(); | |
Serial.begin(9600); | |
Serial.println(); | |
Serial.println("OK"); | |
} | |
void loop() { | |
handleTelnet(); | |
//delay(30); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment