Add OTA programing & setup debug chanel ( telnet/serial)

master
JbLb 8 years ago
parent 2fae401427
commit 0958aa2838

@ -1,3 +1,6 @@
// global config
#include "config.h"
//################# LIBRARIES ##########################
#include <ESP8266WiFi.h>
@ -8,6 +11,29 @@
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>
#include <time.h>
#include <ArduinoOTA.h>
// 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<numberOfHorizontalDisplays; i++){
Serial.print("Changing orientation of display #");
Serial.println(i);
DEBUG_PRINTLN(i);
matrix.setRotation(i, 1);
}
server.on("/", GetMessage);
message = "Bienvenue !";
// Set hostname and start OTA
ArduinoOTA.setHostname("Horloge");
// 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 error
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();
}
void loop() {
#ifdef DEBUG_TELNET
// Handle Telnet connection for debugging
handleTelnet();
#endif
server.handleClient();
matrix.fillScreen(LOW);
time_t now = time(nullptr);
String time = String(ctime(&now));
//Serial.println(time);
time.trim();
time.substring(11,19).toCharArray(time_value, 10);
for (int i = 0; i <= 4; i++) {
@ -84,20 +146,23 @@ void loop() {
}
matrix.write(); // Send bitmap to display
if (message != "") {
Serial.print("On envoi \"");
Serial.print(message);
Serial.println("\" à LibreMetric");
DEBUG_PRINT("On envoi \"");
DEBUG_PRINT(message);
DEBUG_PRINTLN("\" à LibreMetric");
display_message(message); // Display the message
Serial.print("Message envoyé à LibreMetric : ");
Serial.println(message);
DEBUG_PRINT("Message envoyé à LibreMetric : ");
DEBUG_PRINTLN(message);
message = "";
}
if (brightness <= 15) {
Serial.print("Nouvelle luminosité : ");
Serial.println(brightness);
DEBUG_PRINT("Nouvelle luminosité : ");
DEBUG_PRINTLN(brightness);
matrix.setIntensity(brightness);
brightness = 16;
}
yield();
ArduinoOTA.handle();
yield();
}
void display_message(String message){

@ -0,0 +1,2 @@
// Enable console output via telnet
// #define DEBUG_TELNET
Loading…
Cancel
Save