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() {
|
||||
Serial.begin(115200); // initialize serial communications
|
||||
// Initialisation
|
||||
Serial.begin(115200);
|
||||
DEBUG_PRINT(F("\n\r"));
|
||||
matrix.fillScreen(LOW); //clr screen
|
||||
|
||||
matrix.fillScreen(LOW); // clear screen
|
||||
initOTA();
|
||||
SPIFFS.begin();
|
||||
|
||||
for (int i=0; i<numberOfHorizontalDisplays; i++){
|
||||
DEBUG_PRINT(F("Changing orientation of display #"));
|
||||
DEBUG_PRINTLN(i);
|
||||
matrix.setRotation(i, 1);
|
||||
}
|
||||
DEBUG_PRINT(numberOfHorizontalDisplays);
|
||||
DEBUG_PRINTLN(F(" displays configurated..."));
|
||||
|
||||
// Initialise Wi-Fi
|
||||
display_message("Wi-Fi");
|
||||
WiFiManager wifiManager;
|
||||
String hostname(HOSTNAME);
|
||||
hostname += String(ESP.getChipId(), HEX);
|
||||
WiFi.hostname(hostname);
|
||||
|
||||
#ifndef DEBUG_WifiM
|
||||
wifiManager.setDebugOutput(false); // no debug
|
||||
#endif
|
||||
|
||||
#ifndef DEBUG_WifiM
|
||||
wifiManager.setDebugOutput(false); // no debug
|
||||
#endif
|
||||
wifiManager.setTimeout(180);
|
||||
wifiManager.setAPCallback(configModeCallback);
|
||||
if(!wifiManager.autoConnect("LibreMetric")) {
|
||||
@ -105,57 +105,60 @@ void setup() {
|
||||
delay(180000);
|
||||
}
|
||||
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..."));
|
||||
display_message("OK");
|
||||
delay(10*wait);
|
||||
DEBUG_PRINTLN(WiFi.localIP());
|
||||
|
||||
// First sync with NTP
|
||||
configTime(timezone * 3600, dstOffset * 3600, ntpServer); // First sync of time with (S)NTP
|
||||
|
||||
#ifdef DEBUG_TELNET
|
||||
// Start the Telnet server
|
||||
telnetServer.begin();
|
||||
telnetServer.setNoDelay(true);
|
||||
#endif
|
||||
// Initialise Telnet Server for debugging purposes
|
||||
#ifdef DEBUG_TELNET
|
||||
telnetServer.begin();
|
||||
telnetServer.setNoDelay(true);
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Initialise web server
|
||||
server.begin();
|
||||
DEBUG_PRINTLN(F("Webserver started..."));
|
||||
DEBUG_PRINT(numberOfHorizontalDisplays);
|
||||
DEBUG_PRINTLN(F(" displays configurated..."));
|
||||
|
||||
server.on("/", GetMessage);
|
||||
if (!MDNS.begin("ESP8266")) {
|
||||
DEBUG_PRINTLN("Error setting up MDNS responder!");
|
||||
while(1) {
|
||||
delay(1000);
|
||||
delay(10*wait);
|
||||
}
|
||||
}
|
||||
|
||||
// Initialise mDNS
|
||||
DEBUG_PRINTLN("mDNS responder started");
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
|
||||
|
||||
// Startup OK
|
||||
display_message(WiFi.localIP().toString());
|
||||
message = "Bienvenue !";
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
#ifdef DEBUG_TELNET
|
||||
// Handle Telnet connection for debugging
|
||||
handleTelnet();
|
||||
#endif
|
||||
// Webserver's first
|
||||
server.handleClient();
|
||||
matrix.fillScreen(LOW);
|
||||
|
||||
// Getting and parsing the time
|
||||
time_t now = time(nullptr);
|
||||
String time = String(ctime(&now));
|
||||
time.trim();
|
||||
time.substring(11,19).toCharArray(time_value, 10);
|
||||
int seconds = time.substring(17,19).toInt();
|
||||
|
||||
// Displaying the time on the LED matrix
|
||||
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
|
||||
}
|
||||
matrix.write(); // Send bitmap to display
|
||||
|
||||
// Parsing and displaying args from webserver
|
||||
if (message != "") {
|
||||
display_message(message); // Display the message
|
||||
DEBUG_PRINT(F("Message envoyé à LibreMetric : "));
|
||||
@ -168,15 +171,17 @@ void loop() {
|
||||
matrix.setIntensity(brightness);
|
||||
brightness = 16;
|
||||
}
|
||||
yield();
|
||||
ArduinoOTA.handle();
|
||||
yield();
|
||||
|
||||
#ifdef DEBUG_TELNET
|
||||
// Handle Telnet connection for debugging
|
||||
handleTelnet();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Function for displaying all messages
|
||||
void display_message(String message){
|
||||
if (width * message.length() - spacer > matrix.width()) {
|
||||
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.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){
|
||||
for ( int i = 0 ; i < width * message.length() + matrix.width() - spacer; i++ ) {
|
||||
matrix.fillScreen(LOW);
|
||||
|
2
config.h
2
config.h
@ -1,5 +1,5 @@
|
||||
// Enable console output via telnet
|
||||
// #define DEBUG_TELNET
|
||||
#define DEBUG_TELNET
|
||||
|
||||
|
||||
// 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