// global config
#include "config.h"
//################# LIBRARIES ##########################
#include
#include
#include // https://github.com/tzapu/WiFiManager
#include
#include
#include
#include
#include
#include
// 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
//################# DISPLAY CONNECTIONS ################
// LED Matrix Pin -> ESP8266 Pin
// Vcc -> 3v (3V on NodeMCU 3V3 on WEMOS)
// Gnd -> Gnd (G on NodeMCU)
// DIN -> D7 (Same Pin for WEMOS)
// CS -> D4 (Same Pin for WEMOS)
// CLK -> D5 (Same Pin for WEMOS)
//################ PROGRAM SETTINGS ####################
String version = "0.1b";
int PORT = 80;
int wait = 50;
int spacer = 1;
int width = 5 + spacer;
String SITE_WIDTH = "1000";
int timezone = 1;
int dstOffset = 1;
const char* ntpServer = "fr.pool.ntp.org";
int brightness = 2;
int pinCS = D4;
int numberOfHorizontalDisplays = 4;
int numberOfVerticalDisplays = 1;
//################## INITIALIZING ######################
char time_value[20];
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
for (int i=0; i= 0 && letter >= 0 ) {
if ( letter < message.length() ) {
matrix.drawChar(x, y, message[letter], HIGH, LOW, 1); // HIGH LOW means foreground ON, background OFF, reverse these to invert the display!
}
letter--;
x -= width;
}
matrix.write(); // Send bitmap to display
delay(wait);
}
}
void GetMessage() {
webpage = "";
append_page_header();
String IPaddress = WiFi.localIP().toString();
webpage += "
";
webpage += "
";
append_page_footer();
if (server.args() > 0 ) { // Arguments were received
for ( uint8_t i = 0; i <= server.args(); i++ ) {
String Argument_Name = server.argName(i);
String client_response = server.arg(i);
if (Argument_Name == "message") message = client_response;
if (Argument_Name == "brightness") brightness = client_response.toInt();
}
}
server.send(200, "text/html", webpage); // Send a response to the client to enter their inputs, if needed, Enter=defaults
}
void append_page_header() {
webpage = F("");
webpage += "";
webpage += F("Envoi de messages - LibreMetricLibreMetric ");
webpage += version+"
";
}
void append_page_footer(){ // Saves repeating many lines of code for HTML page footers
webpage += F("");
webpage += F("");
}