-
Notifications
You must be signed in to change notification settings - Fork 0
/
ESP_Telnet.ino
88 lines (69 loc) · 2.19 KB
/
ESP_Telnet.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* ------------------------------------------------- */
#include "ESPTelnetStream.h"
/* ------------------------------------------------- */
#define SERIAL_SPEED 115200
#define INFRA_SSID "BT-Q6CTR8"
#define INFRA_PSWD "c531a3d358"
//const char noecho[]={0xFF,0xFD,0x2D,0}; // IAC DO SUPPRESS-LOCAL-ECHO Required for Windows telnet client.
const uint8_t noecho[]={0xFF,0xFB,0x01,0}; // IAC WILL ECHO Seems to work for most clients
/*
IAC DO SUPPRESS-LOCAL-ECHO
The sender of this command, generally a host computer, REQUESTS that a
client NVT terminal suspend the local echoing of text typed on its
keyboard. This request makes good sense only when the NVT and host are
operating in an asymmetric, half-duplex terminal mode with a
co-operating host. The command should have no effect on an NVT terminal
operating in full-duplex mode.
*/
/* ------------------------------------------------- */
ESPTelnetStream telnet;
/* ------------------------------------------------- */
void telnetConnected(String ip) {
Serial.print(ip);
Serial.println(" connected.");
telnet.print((char *)noecho);
}
void telnetDisconnected(String ip) {
Serial.print(ip);
Serial.println(" disconnected.");
}
void telnetReconnect(String ip) {
Serial.print(ip);
Serial.println(" reconnected.");
}
/* ------------------------------------------------- */
void TStart() {
Serial.println("ESP Telnet server");
WiFi.setHostname("EspPDP8");
WiFi.mode(WIFI_STA);
WiFi.begin(INFRA_SSID, INFRA_PSWD);
while(WiFi.status() != WL_CONNECTED) {
delay(100);
}
telnet.onConnect(telnetConnected);
telnet.onDisconnect(telnetDisconnected);
telnet.onReconnect(telnetReconnect);
Serial.print("Telnet.begin: ");
if(telnet.begin()) {
Serial.println("Successful");
} else {
Serial.println("Failed");
}
IPAddress ip = WiFi.localIP();
Serial.print("IP:");
Serial.print(ip);
Serial.println("/EspPDP8");
}
/* ------------------------------------------------- */
void Tloop() {
telnet.loop();
/*
if(Serial.available() > 0) {
telnet.write(Serial.read());
}
if (telnet.available() > 0) {
Serial.print(char(telnet.read()));
}
*/
}
/* ------------------------------------------------- */