Enhancing global code and comments
This commit is contained in:
parent
70831df21d
commit
771feec8c2
@ -72,29 +72,29 @@ void configModeCallback (WiFiManager *myWiFiManager) { // AP config mode
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200); // initialize serial communications
|
// Initialisation
|
||||||
|
Serial.begin(115200);
|
||||||
DEBUG_PRINT(F("\n\r"));
|
DEBUG_PRINT(F("\n\r"));
|
||||||
matrix.fillScreen(LOW); //clr screen
|
matrix.fillScreen(LOW); // clear screen
|
||||||
|
|
||||||
initOTA();
|
initOTA();
|
||||||
SPIFFS.begin();
|
SPIFFS.begin();
|
||||||
|
|
||||||
for (int i=0; i<numberOfHorizontalDisplays; i++){
|
for (int i=0; i<numberOfHorizontalDisplays; i++){
|
||||||
DEBUG_PRINT(F("Changing orientation of display #"));
|
DEBUG_PRINT(F("Changing orientation of display #"));
|
||||||
DEBUG_PRINTLN(i);
|
DEBUG_PRINTLN(i);
|
||||||
matrix.setRotation(i, 1);
|
matrix.setRotation(i, 1);
|
||||||
}
|
}
|
||||||
|
DEBUG_PRINT(numberOfHorizontalDisplays);
|
||||||
|
DEBUG_PRINTLN(F(" displays configurated..."));
|
||||||
|
|
||||||
|
// Initialise Wi-Fi
|
||||||
display_message("Wi-Fi");
|
display_message("Wi-Fi");
|
||||||
WiFiManager wifiManager;
|
WiFiManager wifiManager;
|
||||||
String hostname(HOSTNAME);
|
String hostname(HOSTNAME);
|
||||||
hostname += String(ESP.getChipId(), HEX);
|
hostname += String(ESP.getChipId(), HEX);
|
||||||
WiFi.hostname(hostname);
|
WiFi.hostname(hostname);
|
||||||
|
#ifndef DEBUG_WifiM
|
||||||
#ifndef DEBUG_WifiM
|
wifiManager.setDebugOutput(false); // no debug
|
||||||
wifiManager.setDebugOutput(false); // no debug
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
wifiManager.setTimeout(180);
|
wifiManager.setTimeout(180);
|
||||||
wifiManager.setAPCallback(configModeCallback);
|
wifiManager.setAPCallback(configModeCallback);
|
||||||
if(!wifiManager.autoConnect("LibreMetric")) {
|
if(!wifiManager.autoConnect("LibreMetric")) {
|
||||||
@ -105,57 +105,60 @@ void setup() {
|
|||||||
delay(180000);
|
delay(180000);
|
||||||
}
|
}
|
||||||
matrix.fillScreen(LOW);
|
matrix.fillScreen(LOW);
|
||||||
// At this stage the WiFi manager will have successfully connected to a network, or if not will try again in 180-seconds
|
|
||||||
DEBUG_PRINTLN(F("WiFi connected..."));
|
DEBUG_PRINTLN(F("WiFi connected..."));
|
||||||
display_message("OK");
|
display_message("OK");
|
||||||
delay(10*wait);
|
delay(10*wait);
|
||||||
DEBUG_PRINTLN(WiFi.localIP());
|
DEBUG_PRINTLN(WiFi.localIP());
|
||||||
|
|
||||||
|
// First sync with NTP
|
||||||
configTime(timezone * 3600, dstOffset * 3600, ntpServer); // First sync of time with (S)NTP
|
configTime(timezone * 3600, dstOffset * 3600, ntpServer); // First sync of time with (S)NTP
|
||||||
|
|
||||||
#ifdef DEBUG_TELNET
|
// Initialise Telnet Server for debugging purposes
|
||||||
// Start the Telnet server
|
#ifdef DEBUG_TELNET
|
||||||
telnetServer.begin();
|
telnetServer.begin();
|
||||||
telnetServer.setNoDelay(true);
|
telnetServer.setNoDelay(true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
// Initialise web server
|
||||||
server.begin();
|
server.begin();
|
||||||
DEBUG_PRINTLN(F("Webserver started..."));
|
DEBUG_PRINTLN(F("Webserver started..."));
|
||||||
DEBUG_PRINT(numberOfHorizontalDisplays);
|
|
||||||
DEBUG_PRINTLN(F(" displays configurated..."));
|
|
||||||
|
|
||||||
server.on("/", GetMessage);
|
server.on("/", GetMessage);
|
||||||
if (!MDNS.begin("ESP8266")) {
|
if (!MDNS.begin("ESP8266")) {
|
||||||
DEBUG_PRINTLN("Error setting up MDNS responder!");
|
DEBUG_PRINTLN("Error setting up MDNS responder!");
|
||||||
while(1) {
|
while(1) {
|
||||||
delay(1000);
|
delay(10*wait);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialise mDNS
|
||||||
DEBUG_PRINTLN("mDNS responder started");
|
DEBUG_PRINTLN("mDNS responder started");
|
||||||
MDNS.addService("http", "tcp", 80);
|
MDNS.addService("http", "tcp", 80);
|
||||||
|
|
||||||
|
// Startup OK
|
||||||
display_message(WiFi.localIP().toString());
|
display_message(WiFi.localIP().toString());
|
||||||
message = "Bienvenue !";
|
message = "Bienvenue !";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
#ifdef DEBUG_TELNET
|
// Webserver's first
|
||||||
// Handle Telnet connection for debugging
|
|
||||||
handleTelnet();
|
|
||||||
#endif
|
|
||||||
server.handleClient();
|
server.handleClient();
|
||||||
matrix.fillScreen(LOW);
|
matrix.fillScreen(LOW);
|
||||||
|
|
||||||
|
// Getting and parsing the time
|
||||||
time_t now = time(nullptr);
|
time_t now = time(nullptr);
|
||||||
String time = String(ctime(&now));
|
String time = String(ctime(&now));
|
||||||
time.trim();
|
time.trim();
|
||||||
time.substring(11,19).toCharArray(time_value, 10);
|
time.substring(11,19).toCharArray(time_value, 10);
|
||||||
int seconds = time.substring(17,19).toInt();
|
int seconds = time.substring(17,19).toInt();
|
||||||
|
|
||||||
|
// Displaying the time on the LED matrix
|
||||||
for (int i = 0; i <= 4; i++) {
|
for (int i = 0; i <= 4; i++) {
|
||||||
if (i != 2 || seconds % 2 == 0) matrix.drawChar(i*6+2,0, time_value[i], HIGH,LOW,1); // H
|
if (i != 2 || seconds % 2 == 0) matrix.drawChar(i*6+2,0, time_value[i], HIGH,LOW,1); // H
|
||||||
}
|
}
|
||||||
matrix.write(); // Send bitmap to display
|
matrix.write(); // Send bitmap to display
|
||||||
|
|
||||||
|
// Parsing and displaying args from webserver
|
||||||
if (message != "") {
|
if (message != "") {
|
||||||
display_message(message); // Display the message
|
display_message(message); // Display the message
|
||||||
DEBUG_PRINT(F("Message envoyé à LibreMetric : "));
|
DEBUG_PRINT(F("Message envoyé à LibreMetric : "));
|
||||||
@ -168,15 +171,17 @@ void loop() {
|
|||||||
matrix.setIntensity(brightness);
|
matrix.setIntensity(brightness);
|
||||||
brightness = 16;
|
brightness = 16;
|
||||||
}
|
}
|
||||||
yield();
|
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
yield();
|
|
||||||
|
|
||||||
#ifdef DEBUG_TELNET
|
#ifdef DEBUG_TELNET
|
||||||
// Handle Telnet connection for debugging
|
// Handle Telnet connection for debugging
|
||||||
handleTelnet();
|
handleTelnet();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Function for displaying all messages
|
||||||
void display_message(String message){
|
void display_message(String message){
|
||||||
if (width * message.length() - spacer > matrix.width()) {
|
if (width * message.length() - spacer > matrix.width()) {
|
||||||
display_message_long(message);
|
display_message_long(message);
|
||||||
@ -189,9 +194,12 @@ void display_message(String message){
|
|||||||
matrix.drawChar(x + (i * width), y, message[i], HIGH, LOW, 1); // HIGH LOW means foreground ON, background OFF, reverse these to invert the display!
|
matrix.drawChar(x + (i * width), y, message[i], HIGH, LOW, 1); // HIGH LOW means foreground ON, background OFF, reverse these to invert the display!
|
||||||
}
|
}
|
||||||
matrix.write(); // Send bitmap to display
|
matrix.write(); // Send bitmap to display
|
||||||
delay(4000);
|
delay(20*wait);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function for displaying only long messages (longer than LED matrix length)
|
||||||
|
// This function is called only by the display_message function
|
||||||
void display_message_long(String message){
|
void display_message_long(String message){
|
||||||
for ( int i = 0 ; i < width * message.length() + matrix.width() - spacer; i++ ) {
|
for ( int i = 0 ; i < width * message.length() + matrix.width() - spacer; i++ ) {
|
||||||
matrix.fillScreen(LOW);
|
matrix.fillScreen(LOW);
|
||||||
|
2
config.h
2
config.h
@ -1,5 +1,5 @@
|
|||||||
// Enable console output via telnet
|
// Enable console output via telnet
|
||||||
// #define DEBUG_TELNET
|
#define DEBUG_TELNET
|
||||||
|
|
||||||
|
|
||||||
// Enable wifimanager debug
|
// Enable wifimanager debug
|
||||||
|
118
data/index.html
Normal file
118
data/index.html
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html lang='fr'>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=utf-8'>
|
||||||
|
<title>Envoi de messages - LibreMetric</title>
|
||||||
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
|
||||||
|
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
|
||||||
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: 'Open Sans', sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1,
|
||||||
|
h2,
|
||||||
|
h3,
|
||||||
|
h4,
|
||||||
|
h5,
|
||||||
|
h6 {
|
||||||
|
font-weight: 300;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
strong {
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
#wrapper {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 600px;
|
||||||
|
margin: 0 auto;
|
||||||
|
text-align: center;
|
||||||
|
padding: 30px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-head-image {}
|
||||||
|
|
||||||
|
.page-head-image img {
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#form-trabalhe {
|
||||||
|
margin-top: 30px;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
font-weight: normal;
|
||||||
|
margin-top: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
border: 2px solid #CCC !important;
|
||||||
|
height: 35px;
|
||||||
|
border-radius: 3px;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-group-addon {
|
||||||
|
border: 2px solid #CCC !important;
|
||||||
|
border-right: 0px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
border: 0;
|
||||||
|
border-radius: 3px;
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group {
|
||||||
|
margin-bottom: 0;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<nav class="navbar navbar-toggleable-md navbar-inverse bg-inverse fixed-top">
|
||||||
|
<a class="navbar-brand" href="#">LibreMetric v0.1b</a>
|
||||||
|
<a href='javascript:location.reload(true);' class='btn-success btn-lg md-only'>Reload</a>
|
||||||
|
</nav>
|
||||||
|
<div id="wrapper" class="container">
|
||||||
|
<br /><br /><br /><br /><br />
|
||||||
|
<h1>LibreMetric v0.1b</h1>
|
||||||
|
|
||||||
|
<form id="form-work" class="" name="form-work" action="http://ipaddress" method="post">
|
||||||
|
<fieldset>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<label class="control-label" for="message">Message</label>
|
||||||
|
<input name="message" class="form-control" placeholder="Tapez votre message ici…" type="text">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<label class="control-label" for="brightness">Luminosité</label>
|
||||||
|
<input name="brightness" class="form-control" placeholder="de 0 à 15" type="text">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<button type="submit" class="btn btn-primary btn-lg btn-block info">Envoyer</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
</divs>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user