{"action":"created","issue":{"url":"https://api.github.com/repos/esp8266/Arduino/issues/1169","labels_url":"https://api.github.com/repos/esp8266/Arduino/issues/1169/labels{/name}","comments_url":"https://api.github.com/repos/esp8266/Arduino/issues/1169/comments","events_url":"https://api.github.com/repos/esp8266/Arduino/issues/1169/events","html_url":"https://github.com/esp8266/Arduino/issues/1169","id":120744844,"number":1169,"title":"WiFi Telnet Server for Serial Monitor use - provided","user":{"login":"rudi48","id":6186606,"avatar_url":"https://avatars.githubusercontent.com/u/6186606?v=3","gravatar_id":"","url":"https://api.github.com/users/rudi48","html_url":"https://github.com/rudi48","followers_url":"https://api.github.com/users/rudi48/followers","following_url":"https://api.github.com/users/rudi48/following{/other_user}","gists_url":"https://api.github.com/users/rudi48/gists{/gist_id}","starred_url":"https://api.github.com/users/rudi48/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rudi48/subscriptions","organizations_url":"https://api.github.com/users/rudi48/orgs","repos_url":"https://api.github.com/users/rudi48/repos","events_url":"https://api.github.com/users/rudi48/events{/privacy}","received_events_url":"https://api.github.com/users/rudi48/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-07T10:42:50Z","updated_at":"2015-12-07T19:51:36Z","closed_at":null,"body":"Hello,\r\nI needed for the **stand alone operation** application debugging information. \r\nFor that purpose I thought, that a **Telnet connection** would be the right choice. \r\nUnfortunately I did not found any example for that. \r\nSo, I had to find out. The result is shown in the source listing on this page. \r\nThe program was tested with success with the following **Telnet Clients**:\r\n * telnet (Linux NetKit 0.17) Linux Ubuntu 14.04 32Bit\r\n * PuTTY version 0.63, Windows 7 64Bit\r\n * telnet Mac OS X 10.11.1 \r\n\r\n```C\r\n// File: TelnetServer.ino for ESP8266 NodeMCU\r\n// 2015-12-07 Rudolf Reuter www.rudiswiki.de/wiki9 (search for \"wifi\")\r\n//\r\n// Developed for debug purpose, use like the Arduino Serial Monitor.\r\n//\r\n// If the Telnet session is lost, depending on the Telnet client,\r\n// you need to press RESET on the NodeMCU and restart the Telnet client.\r\n/*\r\n *   This library is free software; you can redistribute it and/or\r\n  modify it under the terms of the GNU Lesser General Public\r\n  License as published by the Free Software Foundation; either\r\n  version 2.1 of the License, or (at your option) any later version.\r\n\r\n  This library is distributed in the hope that it will be useful,\r\n  but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r\n  Lesser General Public License for more details.\r\n\r\n  You should have received a copy of the GNU Lesser General Public\r\n  License along with this library; if not, write to the Free Software\r\n  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r\n */\r\n\r\n#include <ESP8266WiFi.h>\r\n\r\n// Set these to your desired softAP credentials. They are not configurable at runtime.\r\nconst char *ssid = \"..........\";\r\nconst char *password = \"..........\";\r\n\r\nboolean debug = false;  // true = more messages\r\n//boolean debug = true;\r\n\r\n// LED is needed for failure signalling\r\nconst short int BUILTIN_LED2 = 16;  //GPIO16 on NodeMCU (ESP-12)\r\n\r\nunsigned long startTime = millis();\r\n\r\n// provide text for the WiFi status\r\nconst char *str_status[]= {\r\n  \"WL_IDLE_STATUS\",\r\n  \"WL_NO_SSID_AVAIL\",\r\n  \"WL_SCAN_COMPLETED\",\r\n  \"WL_CONNECTED\",\r\n  \"WL_CONNECT_FAILED\",\r\n  \"WL_CONNECTION_LOST\",\r\n  \"WL_DISCONNECTED\"\r\n};\r\n\r\n// provide text for the WiFi mode\r\nconst char *str_mode[]= { \"WIFI_OFF\", \"WIFI_STA\", \"WIFI_AP\", \"WIFI_AP_STA\" };\r\n\r\n//----------------------- WiFi handling\r\nvoid connectWifi() {\r\n  Serial.print(\"Connecting as wifi client to SSID: \");\r\n  Serial.println(ssid);\r\n\r\n  // use in case of mode problem\r\n  WiFi.disconnect();\r\n  // switch to Station mode\r\n  if (WiFi.getMode() != WIFI_STA) {\r\n    WiFi.mode(WIFI_STA);\r\n  }\r\n\r\n  WiFi.begin ( ssid, password );\r\n\r\n  if (debug ) WiFi.printDiag(Serial);\r\n\r\n  // ... Give ESP 10 seconds to connect to station.\r\n  unsigned long startTime = millis();\r\n  while (WiFi.status() != WL_CONNECTED && millis() - startTime < 10000) {\r\n    delay(500);\r\n    Serial.print(\".\");\r\n  }\r\n  Serial.println(\"\");\r\n  // Check connection\r\n  if (WiFi.status() == WL_CONNECTED) {\r\n    Serial.print(\"WiFi connected; IP address: \");\r\n    Serial.println(WiFi.localIP());\r\n  } else {\r\n    Serial.print(\"WiFi connect failed to ssid: \");\r\n    Serial.println(ssid);\r\n    Serial.print(\"WiFi password <\");\r\n    Serial.print(password);\r\n    Serial.println(\">\");\r\n    Serial.println(\"Check for wrong typing!\");\r\n  }\r\n}  // connectWiFi()\r\n\r\nvoid signalError() {  // loop endless with LED blinking in case of error\r\n  while(1) {\r\n      digitalWrite(BUILTIN_LED2, LOW);\r\n      delay(300); // ms\r\n      digitalWrite(BUILTIN_LED2, HIGH);\r\n      delay(300); // ms\r\n  }\r\n}\r\n\r\n// declare telnet server (do NOT put in setup())\r\nconst uint16_t aport = 23; // standard port\r\nWiFiServer TelnetServer(aport);\r\nWiFiClient TelnetClient;\r\n\r\nvoid setup() {\r\n  delay(1000);\r\n  Serial.begin(115200);\r\n  delay(1000);\r\n  Serial.println(\"Sync,Sync,Sync,Sync,Sync\");\r\n  delay(500);\r\n  Serial.println();\r\n  // signal start\r\n  pinMode(BUILTIN_LED2, OUTPUT);\r\n  digitalWrite(BUILTIN_LED2, LOW);\r\n  delay(100); // ms\r\n  digitalWrite(BUILTIN_LED2, HIGH);\r\n  delay(300); // ms\r\n\r\n  Serial.print(\"Chip ID: 0x\");\r\n  Serial.println(ESP.getChipId(), HEX);\r\n\r\n  Serial.println ( \"Connect to Router requested\" );\r\n  connectWifi();\r\n  if (WiFi.status() == WL_CONNECTED) {\r\n    Serial.print(\"WiFi mode: \");\r\n    Serial.println(str_mode[WiFi.getMode()]);\r\n    Serial.print ( \"Status: \" );\r\n    Serial.println (str_status[WiFi.status()]);\r\n    // signal WiFi connect\r\n    digitalWrite(BUILTIN_LED2, LOW);\r\n    delay(300); // ms\r\n    digitalWrite(BUILTIN_LED2, HIGH);      \r\n  } else {\r\n    Serial.println(\"\");\r\n    Serial.println(\"WiFi connect failed, push RESET button.\");\r\n    signalError();\r\n  }\r\n\r\n  TelnetServer.begin();\r\n  TelnetServer.setNoDelay(true);\r\n} // setup()\r\n\r\n\r\nvoid loop() {\r\n  if (millis() - startTime > 2000) { // run every 2000 ms\r\n    startTime = millis();\r\n    if (!TelnetClient) {  // otherwise it works only once\r\n        TelnetClient = TelnetServer.available();\r\n    }\r\n    if (TelnetClient.connected()) {\r\n      TelnetClient.print(\"Telnet Test, millis: \");\r\n      TelnetClient.println(millis());\r\n    } else {\r\n      Serial.println(\"Please connect Telnet Client, exit with ^] and 'quit'\");\r\n    }\r\n  }\r\n}\r\n```\r\nRegards, Rudolf\r\n"},"comment":{"url":"https://api.github.com/repos/esp8266/Arduino/issues/comments/162639601","html_url":"https://github.com/esp8266/Arduino/issues/1169#issuecomment-162639601","issue_url":"https://api.github.com/repos/esp8266/Arduino/issues/1169","id":162639601,"user":{"login":"drmpf","id":5945337,"avatar_url":"https://avatars.githubusercontent.com/u/5945337?v=3","gravatar_id":"","url":"https://api.github.com/users/drmpf","html_url":"https://github.com/drmpf","followers_url":"https://api.github.com/users/drmpf/followers","following_url":"https://api.github.com/users/drmpf/following{/other_user}","gists_url":"https://api.github.com/users/drmpf/gists{/gist_id}","starred_url":"https://api.github.com/users/drmpf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drmpf/subscriptions","organizations_url":"https://api.github.com/users/drmpf/orgs","repos_url":"https://api.github.com/users/drmpf/repos","events_url":"https://api.github.com/users/drmpf/events{/privacy}","received_events_url":"https://api.github.com/users/drmpf/received_events","type":"User","site_admin":false},"created_at":"2015-12-07T19:51:36Z","updated_at":"2015-12-07T19:51:36Z","body":"You could also try a serial to WiFi bridge like my\r\nhttp://www.forward.com.au/pfod/CheapWifiShield/ESP2866_01_WiFi_Shield/index.html\r\nwhich has webpage config to enter your network parameters and the ip and port to listen on.\r\nJust set port 23 for telent."}}