change telnet init & add telnethandle code

master
JbLb 8 years ago
parent 0958aa2838
commit 2b5b57448a

@ -13,7 +13,7 @@
#include <time.h> #include <time.h>
#include <ArduinoOTA.h> #include <ArduinoOTA.h>
// in a terminal: telnet arilux.local // in a terminal: telnet esp IP
#ifdef DEBUG_TELNET #ifdef DEBUG_TELNET
WiFiServer telnetServer(23); WiFiServer telnetServer(23);
WiFiClient telnetClient; WiFiClient telnetClient;
@ -64,16 +64,31 @@ String message, webpage;
ESP8266WebServer server(PORT); ESP8266WebServer server(PORT);
Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays); 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() { void setup() {
Serial.begin(115200); // initialize serial communications Serial.begin(115200); // initialize serial communications
#ifdef DEBUG_TELNET
// Start the Telnet server
telnetServer.begin();
telnetServer.setNoDelay(true);
#endif
WiFiManager wifiManager; WiFiManager wifiManager;
wifiManager.setTimeout(180); wifiManager.setTimeout(180);
if(!wifiManager.autoConnect("LibreMetric")) { if(!wifiManager.autoConnect("LibreMetric")) {
@ -87,6 +102,12 @@ void setup() {
DEBUG_PRINTLN(WiFi.localIP()); DEBUG_PRINTLN(WiFi.localIP());
configTime(timezone * 3600, dstOffset * 3600, ntpServer); // First sync of time with (S)NTP 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(); server.begin();
DEBUG_PRINTLN(F("Webserver started...")); DEBUG_PRINTLN(F("Webserver started..."));
@ -114,7 +135,11 @@ void setup() {
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
DEBUG_PRINTF("progress: %u%%\r", (progress/(total/100))); 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) { ArduinoOTA.onError([](ota_error_t error) {
DEBUG_PRINT("ArduinoOTA Error["); DEBUG_PRINT("ArduinoOTA Error[");
DEBUG_PRINT(error); DEBUG_PRINT(error);

Loading…
Cancel
Save