Adding telnet for remote debugging purpose
This commit is contained in:
parent
ceb16d97c5
commit
bf253506f2
@ -1,3 +1,6 @@
|
||||
// global config
|
||||
|
||||
#include "config.h"
|
||||
|
||||
//################# LIBRARIES ##########################
|
||||
#include <ESP8266WiFi.h>
|
||||
@ -8,6 +11,8 @@
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Max72xxPanel.h>
|
||||
#include <time.h>
|
||||
#include "d_helper.h"
|
||||
|
||||
|
||||
//################# DISPLAY CONNECTIONS ################
|
||||
// LED Matrix Pin -> ESP8266 Pin
|
||||
@ -54,6 +59,12 @@ void setup() {
|
||||
Serial.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();
|
||||
Serial.println(F("Webserver started..."));
|
||||
@ -73,6 +84,10 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
#ifdef DEBUG_TELNET
|
||||
// Handle Telnet connection for debugging
|
||||
handleTelnet();
|
||||
#endif
|
||||
server.handleClient();
|
||||
matrix.fillScreen(LOW);
|
||||
time_t now = time(nullptr);
|
||||
|
31
OTAsetup.cpp
Normal file
31
OTAsetup.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
#include "OTAsetup.h"
|
||||
|
||||
void initOTA(){
|
||||
// Set hostname and start OTA
|
||||
ArduinoOTA.setHostname("LibreMetric");
|
||||
// Start of OTA
|
||||
ArduinoOTA.onStart([]() {
|
||||
DEBUG_PRINTLN("OTA Beginning!");
|
||||
});
|
||||
// progress of OTA
|
||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
||||
DEBUG_PRINTF("progress: %u%%\r", (progress/(total/100)));
|
||||
});
|
||||
// OTA onEnd
|
||||
ArduinoOTA.onEnd([](){
|
||||
DEBUG_PRINTLN("\nOTA ended, let\'s restart");
|
||||
});
|
||||
// OTA error handle
|
||||
ArduinoOTA.onError([](ota_error_t error) {
|
||||
DEBUG_PRINT("ArduinoOTA Error[");
|
||||
DEBUG_PRINT(error);
|
||||
DEBUG_PRINT("]: ");
|
||||
if (error == OTA_AUTH_ERROR) DEBUG_PRINTLN("Auth Failed");
|
||||
else if (error == OTA_BEGIN_ERROR) DEBUG_PRINTLN("Begin Failed");
|
||||
else if (error == OTA_CONNECT_ERROR) DEBUG_PRINTLN("Connect Failed");
|
||||
else if (error == OTA_RECEIVE_ERROR) DEBUG_PRINTLN("Receive Failed");
|
||||
else if (error == OTA_END_ERROR) DEBUG_PRINTLN("End Failed");
|
||||
});
|
||||
ArduinoOTA.begin();
|
||||
}
|
10
OTAsetup.h
Normal file
10
OTAsetup.h
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
#ifndef OTAsetup_h
|
||||
#define OTAsetup_h
|
||||
|
||||
#include <ArduinoOTA.h>
|
||||
#include "d_helper.h"
|
||||
|
||||
void initOTA();
|
||||
|
||||
#endif
|
6
config.h
Normal file
6
config.h
Normal file
@ -0,0 +1,6 @@
|
||||
// Enable console output via telnet
|
||||
// #define DEBUG_TELNET
|
||||
|
||||
|
||||
// Enable wifimanager debug
|
||||
// #define DEBUG_WifiM
|
31
d_helper.cpp
Normal file
31
d_helper.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
// debug helper
|
||||
|
||||
#include "d_helper.h"
|
||||
|
||||
// in a terminal: telnet esp IP
|
||||
#ifdef DEBUG_TELNET
|
||||
WiFiServer telnetServer(23);
|
||||
WiFiClient telnetClient;
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
21
d_helper.h
Normal file
21
d_helper.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef D_helper_h
|
||||
#define D_helper_h
|
||||
|
||||
void handleTelnet(void);
|
||||
|
||||
// ################# Macros for debugging ################
|
||||
#ifdef DEBUG_TELNET
|
||||
#define DEBUG_PRINT(x) telnetClient.print(x)
|
||||
#define DEBUG_PRINTF(x,y) telnetClient.printf(x,y)
|
||||
#define DEBUG_PRINT_WITH_FMT(x, fmt) telnetClient.print(x, fmt)
|
||||
#define DEBUG_PRINTLN(x) telnetClient.println(x)
|
||||
#define DEBUG_PRINTLN_WITH_FMT(x, fmt) telnetClient.println(x, fmt)
|
||||
#else
|
||||
#define DEBUG_PRINT(x) Serial.print(x)
|
||||
#define DEBUG_PRINTF(x,y) Serial.printf(x,y)
|
||||
#define DEBUG_PRINT_WITH_FMT(x, fmt) Serial.print(x, fmt)
|
||||
#define DEBUG_PRINTLN(x) Serial.println(x)
|
||||
#define DEBUG_PRINTLN_WITH_FMT(x, fmt) Serial.println(x, fmt)
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user