/* WiFiTelnetToSerial - Example Transparent UART to Telnet Server for esp8266 Copyright (c) 2015 Hristo Gochkov. All rights reserved. This file is part of the ESP8266WiFi library for Arduino environment. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include //how many clients should be able to telnet to this ESP8266 #define MAX_SRV_CLIENTS 1 const char* ssid = "FUNDRAWBOTUX"; const char* password = "ghjkgjkg"; WiFiServer server(23); WiFiClient serverClients[MAX_SRV_CLIENTS]; void setup() { delay(1000); Serial1.begin(57600); //WiFi.begin(ssid, password); WiFi.softAP(ssid, password); delay(1000); Serial1.print("Ready! Use 'telnet "); Serial1.print(WiFi.localIP()); Serial1.println(" 23' to connect"); server.begin(); } void loop() { uint8_t i; // server.handleClient(); //check if there are any new clients if (server.hasClient()){ for(i = 0; i < MAX_SRV_CLIENTS; i++){ //find free/disconnected spot if (!serverClients[i] || !serverClients[i].connected()){ if(serverClients[i]) serverClients[i].stop(); serverClients[i] = server.available(); // Serial1.print("New client: "); Serial1.print(i);Serial1.println(); continue; } } //no free/disconnected spot so reject WiFiClient serverClient = server.available(); //& serverClient.stop(); } //check clients for data for(i = 0; i < MAX_SRV_CLIENTS; i++){ if (serverClients[i] && serverClients[i].connected()){ if(serverClients[i].available()){ //get data from the telnet client and push it to the UART while(serverClients[i].available()) Serial1.write(serverClients[i].read()); } } } delay(1); }