change telnet init & add telnethandle code

master
JbLb 8 years ago
parent 0958aa2838
commit 2b5b57448a

@ -13,7 +13,7 @@
#include <time.h>
#include <ArduinoOTA.h>
// in a terminal: telnet arilux.local
// in a terminal: telnet esp IP
#ifdef DEBUG_TELNET
WiFiServer telnetServer(23);
WiFiClient telnetClient;
@ -64,16 +64,31 @@ String message, webpage;
ESP8266WebServer server(PORT);
Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);
///////////////////////////////////////////////////////////////////////////
// TELNET
///////////////////////////////////////////////////////////////////////////
/*
Function called to handle Telnet clients
https://www.youtube.com/watch?v=j9yW10OcahI
*/
#ifdef DEBUG_TELNET
void handleTelnet(void) {
if (telnetServer.hasClient()) {
if (!telnetClient || !telnetClient.connected()) {
if (telnetClient) {
telnetClient.stop();
}
telnetClient = telnetServer.available();
} else {
telnetServer.available().stop();
}
}
}
#endif
void setup() {
Serial.begin(115200); // initialize serial communications
#ifdef DEBUG_TELNET
// Start the Telnet server
telnetServer.begin();
telnetServer.setNoDelay(true);
#endif
WiFiManager wifiManager;
wifiManager.setTimeout(180);
if(!wifiManager.autoConnect("LibreMetric")) {
@ -86,6 +101,12 @@ void setup() {
DEBUG_PRINTLN(F("WiFi connected..."));
DEBUG_PRINTLN(WiFi.localIP());
configTime(timezone * 3600, dstOffset * 3600, ntpServer); // First sync of time with (S)NTP
#ifdef DEBUG_TELNET
// Start the Telnet server
telnetServer.begin();
telnetServer.setNoDelay(true);
#endif
//----------------------------------------------------------------------
server.begin();
@ -114,7 +135,11 @@ void setup() {
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
DEBUG_PRINTF("progress: %u%%\r", (progress/(total/100)));
});
// OTA error
// OTA onEnd
ArduinoOTA.onEnd([](){
DEBUG_PRINTLN("OTA ended, let\'s restart");
});
// OTA error handle
ArduinoOTA.onError([](ota_error_t error) {
DEBUG_PRINT("ArduinoOTA Error[");
DEBUG_PRINT(error);

Loading…
Cancel
Save