-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtelnetserver.ino
85 lines (65 loc) · 1.87 KB
/
telnetserver.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
//PLEASE NOTE:
//require ESP8266 >= 2.4.0 https://github.com/esp8266/Arduino/releases/tag/2.4.0-rc1
//for the use of "setRxBufferSize" function
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <Hash.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPUpdateServer.h>
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
ESP8266WebServer httpServer(80);
ESP8266HTTPUpdateServer httpUpdater;
const char* update_path = "/firmware";
const char* update_username = "admin";
const char* update_password = "admin";
#define MAX_SRV_CLIENTS 1
WiFiServer server(23);
WiFiClient serverClient;
int RESET_PIN = 0; // = GPIO0 on nodeMCU
WiFiManager wifiManager;
void setup()
{
Serial.setRxBufferSize(1024); //require ESP8266 >= 2.4.0 https://github.com/esp8266/Arduino/releases/tag/2.4.0-rc1
Serial.begin(115200);
delay(5000); //BOOT WAIT
pinMode(RESET_PIN, INPUT_PULLUP);
wifiManager.autoConnect("ESP8266");
server.begin();
server.setNoDelay(true);
httpUpdater.setup(&httpServer, update_path, update_username, update_password);
httpServer.begin();
WiFi.setSleepMode(WIFI_NONE_SLEEP); // disable WiFi sleep for more performance
}
void loop()
{
if (server.hasClient())
AcceptConnection();
else if (serverClient && serverClient.connected())
ManageConnected();
httpServer.handleClient();
}
void AcceptConnection()
{
if (serverClient && serverClient.connected())
serverClient.stop();
serverClient = server.available();
serverClient.write("ESP8266 Connected!\n");
}
void ManageConnected()
{
size_t rxlen = serverClient.available();
if (rxlen > 0)
{
uint8_t sbuf[rxlen];
serverClient.readBytes(sbuf, rxlen);
Serial.write(sbuf, rxlen);
}
size_t txlen = Serial.available();
if (txlen > 0)
{
uint8_t sbuf[txlen];
Serial.readBytes(sbuf, txlen);
serverClient.write(sbuf, txlen);
}
}