From 0958aa2838232d0e08c03b39d68f563c0959704a Mon Sep 17 00:00:00 2001 From: JbLb Date: Sun, 17 Dec 2017 16:56:26 +0100 Subject: [PATCH] Add OTA programing & setup debug chanel ( telnet/serial) --- LibreMetric.ino | 91 ++++++++++++++++++++++++++++++++++++++++++------- config.h | 2 ++ 2 files changed, 80 insertions(+), 13 deletions(-) create mode 100644 config.h diff --git a/LibreMetric.ino b/LibreMetric.ino index 082bae4..f2d0153 100644 --- a/LibreMetric.ino +++ b/LibreMetric.ino @@ -1,3 +1,6 @@ +// global config + +#include "config.h" //################# LIBRARIES ########################## #include @@ -8,6 +11,29 @@ #include #include #include +#include + +// in a terminal: telnet arilux.local +#ifdef DEBUG_TELNET +WiFiServer telnetServer(23); +WiFiClient telnetClient; +#endif + +// ################# 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 + //################# DISPLAY CONNECTIONS ################ // LED Matrix Pin -> ESP8266 Pin @@ -41,42 +67,78 @@ Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVe 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")) { - Serial.println(F("failed to connect and timeout occurred")); + DEBUG_PRINTLN(F("failed to connect and timeout occurred")); delay(6000); ESP.reset(); //reset and try again delay(180000); } // At this stage the WiFi manager will have successfully connected to a network, or if not will try again in 180-seconds - Serial.println(F("WiFi connected...")); - Serial.println(WiFi.localIP()); + DEBUG_PRINTLN(F("WiFi connected...")); + DEBUG_PRINTLN(WiFi.localIP()); configTime(timezone * 3600, dstOffset * 3600, ntpServer); // First sync of time with (S)NTP //---------------------------------------------------------------------- server.begin(); - Serial.println(F("Webserver started...")); + DEBUG_PRINTLN(F("Webserver started...")); matrix.setIntensity(brightness); brightness=16; Serial.print(numberOfHorizontalDisplays); - Serial.println(" displays configurated..."); + DEBUG_PRINTLN(" displays configurated..."); for (int i=0; i