|
|
@ -1,6 +1,8 @@
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include <FS.h> //this needs to be first, or it all crashes and burns...
|
|
|
|
#include <FS.h> //this needs to be first, or it all crashes and burns...
|
|
|
|
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
|
|
|
|
#include <ESP8266WiFi.h>
|
|
|
|
|
|
|
|
#include <NTPClient.h> //https://github.com/esp8266/Arduino
|
|
|
|
|
|
|
|
#include <WiFiUdp.h>
|
|
|
|
|
|
|
|
|
|
|
|
//needed for library
|
|
|
|
//needed for library
|
|
|
|
#include <DNSServer.h>
|
|
|
|
#include <DNSServer.h>
|
|
|
@ -11,6 +13,19 @@
|
|
|
|
#include <SPI.h>
|
|
|
|
#include <SPI.h>
|
|
|
|
#include "SevenSegmentClock.h"
|
|
|
|
#include "SevenSegmentClock.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NTP
|
|
|
|
|
|
|
|
WiFiUDP ntpUDP;
|
|
|
|
|
|
|
|
// You can specify the time server pool and the offset (in seconds, can be
|
|
|
|
|
|
|
|
// changed later with setTimeOffset() ). Additionaly you can specify the
|
|
|
|
|
|
|
|
// update interval (in milliseconds, can be changed using setUpdateInterval() ).
|
|
|
|
|
|
|
|
NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define MODE_DEMO 1
|
|
|
|
|
|
|
|
#define MODE_REALCLOCK 2
|
|
|
|
|
|
|
|
#define MODE_FASTCLOCK 3
|
|
|
|
|
|
|
|
static int appMode = MODE_REAL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const char *appName = "FastclockClient7Seg";
|
|
|
|
static const char *appName = "FastclockClient7Seg";
|
|
|
|
|
|
|
|
|
|
|
@ -38,7 +53,8 @@ static struct ColorSelection {
|
|
|
|
{ 2, SevenSegmentClock::Blue, "blue" },
|
|
|
|
{ 2, SevenSegmentClock::Blue, "blue" },
|
|
|
|
{ 3, SevenSegmentClock::Red, "red" },
|
|
|
|
{ 3, SevenSegmentClock::Red, "red" },
|
|
|
|
{ 4, SevenSegmentClock::Green, "green" },
|
|
|
|
{ 4, SevenSegmentClock::Green, "green" },
|
|
|
|
{ 5, SevenSegmentClock::White, "white" }
|
|
|
|
{ 5, SevenSegmentClock::White, "white" },
|
|
|
|
|
|
|
|
{ 6, SevenSegmentClock::Yellow, "yellow" }
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const String getColorName(uint8_t color) {
|
|
|
|
static const String getColorName(uint8_t color) {
|
|
|
@ -174,13 +190,19 @@ const char _SCRIPT[] PROGMEM = "<script>function c(l){document.getEleme
|
|
|
|
const char _HEAD_END[] PROGMEM = "</head><body><div style='text-align:left;display:inline-block;min-width:260px;'>";
|
|
|
|
const char _HEAD_END[] PROGMEM = "</head><body><div style='text-align:left;display:inline-block;min-width:260px;'>";
|
|
|
|
const char _PORTAL_OPTIONS[] PROGMEM = "<form action=\"/wifi\" method=\"get\"><button>Configure WiFi</button></form><br/><form action=\"/0wifi\" method=\"get\"><button>Configure WiFi (No Scan)</button></form><br/><form action=\"/i\" method=\"get\"><button>Info</button></form><br/><form action=\"/r\" method=\"post\"><button>Reset</button></form>";
|
|
|
|
const char _PORTAL_OPTIONS[] PROGMEM = "<form action=\"/wifi\" method=\"get\"><button>Configure WiFi</button></form><br/><form action=\"/0wifi\" method=\"get\"><button>Configure WiFi (No Scan)</button></form><br/><form action=\"/i\" method=\"get\"><button>Info</button></form><br/><form action=\"/r\" method=\"post\"><button>Reset</button></form>";
|
|
|
|
const char _ITEM[] PROGMEM = "<div><a href='#p' onclick='c(this)'>{v}</a> <span class='q {i}'>{r}%</span></div>";
|
|
|
|
const char _ITEM[] PROGMEM = "<div><a href='#p' onclick='c(this)'>{v}</a> <span class='q {i}'>{r}%</span></div>";
|
|
|
|
const char _FORM_START[] PROGMEM = "<form method='get' action='configsave'><label for='n'>Fastclock name</label><input id='n' name='n' length=32 placeholder='clock name'><br/>";
|
|
|
|
const char _FORM_START[] PROGMEM = "<form method='get' action='configsave'>";
|
|
|
|
|
|
|
|
const char _FORM_CLOCKNAME[] PROGMEM = "<label for='n'>Fastclock name</label><input id='n' name='n' length=32 placeholder='clock name'><br/>";
|
|
|
|
|
|
|
|
const char _FORM_CLOCKMODE_HEADLINE[] PROGMEM = "<br/>Clock mode:<br/>";
|
|
|
|
|
|
|
|
const char _FORM_CLOCKMODE_DEMO[] PROGMEM = "<input class='r' id='md' name='m' type='radio' value='demo' {check}><label for='md'>Demo</label><br/>";
|
|
|
|
|
|
|
|
const char _FORM_CLOCKMODE_REAL[] PROGMEM = "<input class='r' id='mr' name='m' type='radio' value='real' {check}><label for='md'>Real Clock</label><br/>";
|
|
|
|
|
|
|
|
const char _FORM_CLOCKMODE_FAST[] PROGMEM = "<input class='r' id='mf' name='m' type='radio' value='fast' {check}><label for='md'>Fast Clock</label><br/>";
|
|
|
|
const char _FORM_PARAM[] PROGMEM = "<br/><input id='{i}' name='{n}' maxlength={l} placeholder='{p}' value='{v}' {c}>";
|
|
|
|
const char _FORM_PARAM[] PROGMEM = "<br/><input id='{i}' name='{n}' maxlength={l} placeholder='{p}' value='{v}' {c}>";
|
|
|
|
const char _FORM_COLOR_HEADLINE[] PROGMEM = "<br/>Display color:<br/>";
|
|
|
|
const char _FORM_COLOR_HEADLINE[] PROGMEM = "<br/>Display color:<br/>";
|
|
|
|
const char _FORM_COLOR_BLUE[] PROGMEM = "<input class='r' id='cb' name='c' type='radio' value='blue' {check}><label for='cb'>Blue</label><br/>";
|
|
|
|
const char _FORM_COLOR_BLUE[] PROGMEM = "<input class='r' id='cb' name='c' type='radio' value='blue' {check}><label for='cb'>Blue</label><br/>";
|
|
|
|
const char _FORM_COLOR_RED[] PROGMEM = "<input class='r' id='cr' name='c' type='radio' value='red' {check}><label for='cr'>Red</label><br/>";
|
|
|
|
const char _FORM_COLOR_RED[] PROGMEM = "<input class='r' id='cr' name='c' type='radio' value='red' {check}><label for='cr'>Red</label><br/>";
|
|
|
|
const char _FORM_COLOR_GREEN[] PROGMEM = "<input class='r' id='cg' name='c' type='radio' value='green' {check}><label for='cg'>Green</label><br/>";
|
|
|
|
const char _FORM_COLOR_GREEN[] PROGMEM = "<input class='r' id='cg' name='c' type='radio' value='green' {check}><label for='cg'>Green</label><br/>";
|
|
|
|
const char _FORM_COLOR_WHITE[] PROGMEM = "<input class='r' id='cw' name='c' type='radio' value='white' {check}><label for='cw'>White</label><br/>";
|
|
|
|
const char _FORM_COLOR_WHITE[] PROGMEM = "<input class='r' id='cw' name='c' type='radio' value='white' {check}><label for='cw'>White</label><br/>";
|
|
|
|
|
|
|
|
const char _FORM_COLOR_YELLOW[] PROGMEM = "<input class='r' id='cy' name='c' type='radio' value='yellow' {check}><label for='cy'>Yellow</label><br/>";
|
|
|
|
const char _FORM_BRIGHTNESS[] PROGMEM = "<br/><label for='b'>Brightness:</label><input id='b' name='b' type='range' min='10' max='255' value='{bright}'><br/>";
|
|
|
|
const char _FORM_BRIGHTNESS[] PROGMEM = "<br/><label for='b'>Brightness:</label><input id='b' name='b' type='range' min='10' max='255' value='{bright}'><br/>";
|
|
|
|
const char _FORM_END[] PROGMEM = "<br/><button type='submit'>save</button></form>";
|
|
|
|
const char _FORM_END[] PROGMEM = "<br/><button type='submit'>save</button></form>";
|
|
|
|
const char _SCAN_LINK[] PROGMEM = "<br/><div class=\"c\"><a href=\"/wifi\">Scan</a></div>";
|
|
|
|
const char _SCAN_LINK[] PROGMEM = "<br/><div class=\"c\"><a href=\"/wifi\">Scan</a></div>";
|
|
|
@ -203,6 +225,17 @@ void appConfig() {
|
|
|
|
page += String(F("<h3>Clock Options</h3>"));
|
|
|
|
page += String(F("<h3>Clock Options</h3>"));
|
|
|
|
//page += FPSTR(_PORTAL_OPTIONS);
|
|
|
|
//page += FPSTR(_PORTAL_OPTIONS);
|
|
|
|
page += FPSTR(_FORM_START);
|
|
|
|
page += FPSTR(_FORM_START);
|
|
|
|
|
|
|
|
page += FPSTR(_FORM_CLOCKMODE_HEADLINE);
|
|
|
|
|
|
|
|
input = FPSTR(_FORM_CLOCKMODE_DEMO);
|
|
|
|
|
|
|
|
input.replace("{check}", (appMode == MODE_DEMO) ? "checked" : "");
|
|
|
|
|
|
|
|
page += input;
|
|
|
|
|
|
|
|
input = FPSTR(_FORM_CLOCKMODE_REAL);
|
|
|
|
|
|
|
|
input.replace("{check}", (appMode == MODE_REALCLOCK) ? "checked" : "");
|
|
|
|
|
|
|
|
page += input;
|
|
|
|
|
|
|
|
input = FPSTR(_FORM_CLOCKMODE_FAST);
|
|
|
|
|
|
|
|
input.replace("{check}", (appMode == MODE_FASTCLOCK) ? "checked" : "");
|
|
|
|
|
|
|
|
page += input;
|
|
|
|
|
|
|
|
page += FPSTR(_FORM_CLOCKNAME);
|
|
|
|
page += FPSTR(_FORM_COLOR_HEADLINE);
|
|
|
|
page += FPSTR(_FORM_COLOR_HEADLINE);
|
|
|
|
input = FPSTR(_FORM_COLOR_BLUE);
|
|
|
|
input = FPSTR(_FORM_COLOR_BLUE);
|
|
|
|
input.replace("{check}", (clockColor == SevenSegmentClock::Blue) ? "checked" : "");
|
|
|
|
input.replace("{check}", (clockColor == SevenSegmentClock::Blue) ? "checked" : "");
|
|
|
@ -213,6 +246,9 @@ void appConfig() {
|
|
|
|
input = FPSTR(_FORM_COLOR_GREEN);
|
|
|
|
input = FPSTR(_FORM_COLOR_GREEN);
|
|
|
|
input.replace("{check}", (clockColor == SevenSegmentClock::Green) ? "checked" : "");
|
|
|
|
input.replace("{check}", (clockColor == SevenSegmentClock::Green) ? "checked" : "");
|
|
|
|
page += input;
|
|
|
|
page += input;
|
|
|
|
|
|
|
|
input = FPSTR(_FORM_COLOR_YELLOW);
|
|
|
|
|
|
|
|
input.replace("{check}", (clockColor == SevenSegmentClock::Yellow) ? "checked" : "");
|
|
|
|
|
|
|
|
page += input;
|
|
|
|
input = FPSTR(_FORM_COLOR_WHITE);
|
|
|
|
input = FPSTR(_FORM_COLOR_WHITE);
|
|
|
|
input.replace("{check}", (clockColor == SevenSegmentClock::White) ? "checked" : "");
|
|
|
|
input.replace("{check}", (clockColor == SevenSegmentClock::White) ? "checked" : "");
|
|
|
|
page += input;
|
|
|
|
page += input;
|
|
|
@ -245,6 +281,16 @@ void appConfigSave() {
|
|
|
|
SevenSegmentClock::Color colorHandle = getColorHandleByName(server->arg("c"));
|
|
|
|
SevenSegmentClock::Color colorHandle = getColorHandleByName(server->arg("c"));
|
|
|
|
sevenSegmentClock.setColor(colorHandle);
|
|
|
|
sevenSegmentClock.setColor(colorHandle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (server->hasArg("m")) {
|
|
|
|
|
|
|
|
Serial.print("setting clock mode to "); Serial.println(server->arg("m"));
|
|
|
|
|
|
|
|
if (server->arg("m").equals("real")) appMode = MODE_REALCLOCK;
|
|
|
|
|
|
|
|
else if (server->arg("m").equals("fast")) appMode = MODE_FASTCLOCK;
|
|
|
|
|
|
|
|
else if (server->arg("m").equals("demo")) appMode = MODE_DEMO;
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
Serial.println("ERROR: Unknown application mode, going into demo mode");
|
|
|
|
|
|
|
|
appMode = MODE_DEMO;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
page.replace("{v}", "7Seg Config");
|
|
|
|
page.replace("{v}", "7Seg Config");
|
|
|
|
page += FPSTR(_SCRIPT);
|
|
|
|
page += FPSTR(_SCRIPT);
|
|
|
|
page += FPSTR(_STYLE);
|
|
|
|
page += FPSTR(_STYLE);
|
|
|
@ -352,6 +398,8 @@ void setup() {
|
|
|
|
pinMode(POWER_OFF_PIN, INPUT);
|
|
|
|
pinMode(POWER_OFF_PIN, INPUT);
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
setupWifiConnection();
|
|
|
|
setupWifiConnection();
|
|
|
|
|
|
|
|
Serial.println("Starting NTP Client");
|
|
|
|
|
|
|
|
timeClient.begin();
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println("Have following configuration:");
|
|
|
|
Serial.println("Have following configuration:");
|
|
|
|
Serial.print(" Clock name: "); Serial.println(clockName);
|
|
|
|
Serial.print(" Clock name: "); Serial.println(clockName);
|
|
|
@ -372,15 +420,29 @@ int hours = 0, minutes = 0;
|
|
|
|
uint32_t nextUpdate_ms = 0;
|
|
|
|
uint32_t nextUpdate_ms = 0;
|
|
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
void loop() {
|
|
|
|
if (millis() > nextUpdate_ms) {
|
|
|
|
timeClient.update();
|
|
|
|
nextUpdate_ms = millis() + 1000;
|
|
|
|
|
|
|
|
minutes++;
|
|
|
|
//Serial.println(timeClient.getFormattedTime());
|
|
|
|
if (minutes > 99) { minutes = 0; }
|
|
|
|
|
|
|
|
if (minutes % 5 == 0) hours++;
|
|
|
|
switch (appMode) {
|
|
|
|
if (hours > 99) hours = 0;
|
|
|
|
case MODE_DEMO:
|
|
|
|
sevenSegmentClock.displayTime(hours, minutes);
|
|
|
|
if (millis() > nextUpdate_ms) {
|
|
|
|
if (hours % 4 == 0) sevenSegmentClock.setBlinkMode(SevenSegmentClock::SeperatorBlinking); else sevenSegmentClock.setBlinkMode(SevenSegmentClock::NoBlinking);
|
|
|
|
nextUpdate_ms = millis() + 1000;
|
|
|
|
|
|
|
|
minutes++;
|
|
|
|
|
|
|
|
if (minutes > 99) { minutes = 0; }
|
|
|
|
|
|
|
|
if (minutes % 5 == 0) hours++;
|
|
|
|
|
|
|
|
if (hours > 99) hours = 0;
|
|
|
|
|
|
|
|
sevenSegmentClock.displayTime(hours, minutes);
|
|
|
|
|
|
|
|
if (hours % 4 == 0) sevenSegmentClock.setBlinkMode(SevenSegmentClock::SeperatorBlinking); else sevenSegmentClock.setBlinkMode(SevenSegmentClock::NoBlinking);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MODE_REALCLOCK:
|
|
|
|
|
|
|
|
sevenSegmentClock.displayTime(timeClient.getHours(), timeClient.getMinutes());
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MODE_FASTCLOCK:
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sevenSegmentClock.displayUpdate();
|
|
|
|
sevenSegmentClock.displayUpdate();
|
|
|
|
server->handleClient();
|
|
|
|
server->handleClient();
|
|
|
|
}
|
|
|
|
}
|
|
|
|