|
|
|
|
@ -11,28 +11,9 @@
|
|
|
|
|
#include <Adafruit_GFX.h>
|
|
|
|
|
#include <Max72xxPanel.h> // https://github.com/markruys/arduino-Max72xxPanel
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <ArduinoOTA.h>
|
|
|
|
|
|
|
|
|
|
// in a terminal: telnet esp IP
|
|
|
|
|
#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
|
|
|
|
|
#include "OTAsetup.h"
|
|
|
|
|
#include "d_helper.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//################# DISPLAY CONNECTIONS ################
|
|
|
|
|
@ -64,35 +45,16 @@ 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
|
|
|
|
|
DEBUG_PRINT("\n\r");
|
|
|
|
|
matrix.fillScreen(LOW); //clr screen
|
|
|
|
|
DEBUG_PRINT(F("\n\r"));
|
|
|
|
|
matrix.fillScreen(LOW); //clr screen
|
|
|
|
|
|
|
|
|
|
initOTA();
|
|
|
|
|
|
|
|
|
|
for (int i=0; i<numberOfHorizontalDisplays; i++){
|
|
|
|
|
DEBUG_PRINT("Changing orientation of display #");
|
|
|
|
|
DEBUG_PRINT(F("Changing orientation of display #"));
|
|
|
|
|
DEBUG_PRINTLN(i);
|
|
|
|
|
matrix.setRotation(i, 1);
|
|
|
|
|
}
|
|
|
|
|
@ -100,7 +62,9 @@ void setup() {
|
|
|
|
|
display_message("Wifi");
|
|
|
|
|
|
|
|
|
|
WiFiManager wifiManager;
|
|
|
|
|
#ifndef DEBUG_WifiM
|
|
|
|
|
wifiManager.setDebugOutput(false); // no debug
|
|
|
|
|
#endif
|
|
|
|
|
wifiManager.setTimeout(180);
|
|
|
|
|
if(!wifiManager.autoConnect("LibreMetric")) {
|
|
|
|
|
DEBUG_PRINTLN(F("failed to connect and timeout occurred"));
|
|
|
|
|
@ -126,38 +90,11 @@ void setup() {
|
|
|
|
|
matrix.setIntensity(brightness);
|
|
|
|
|
brightness=16;
|
|
|
|
|
DEBUG_PRINT(numberOfHorizontalDisplays);
|
|
|
|
|
DEBUG_PRINTLN(" displays configurated...");
|
|
|
|
|
DEBUG_PRINTLN(F(" displays configurated..."));
|
|
|
|
|
|
|
|
|
|
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 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();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
|
@ -177,16 +114,16 @@ void loop() {
|
|
|
|
|
}
|
|
|
|
|
matrix.write(); // Send bitmap to display
|
|
|
|
|
if (message != "") {
|
|
|
|
|
DEBUG_PRINT("On envoi \"");
|
|
|
|
|
DEBUG_PRINT(F("On envoi \""));
|
|
|
|
|
DEBUG_PRINT(message);
|
|
|
|
|
DEBUG_PRINTLN("\" à LibreMetric");
|
|
|
|
|
DEBUG_PRINTLN(F("\" à LibreMetric"));
|
|
|
|
|
display_message(message); // Display the message
|
|
|
|
|
DEBUG_PRINT("Message envoyé à LibreMetric : ");
|
|
|
|
|
DEBUG_PRINT(F("Message envoyé à LibreMetric : "));
|
|
|
|
|
DEBUG_PRINTLN(message);
|
|
|
|
|
message = "";
|
|
|
|
|
}
|
|
|
|
|
if (brightness <= 15) {
|
|
|
|
|
DEBUG_PRINT("Nouvelle luminosité : ");
|
|
|
|
|
DEBUG_PRINT(F("Nouvelle luminosité : "));
|
|
|
|
|
DEBUG_PRINTLN(brightness);
|
|
|
|
|
matrix.setIntensity(brightness);
|
|
|
|
|
brightness = 16;
|
|
|
|
|
|