Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8755571ef4 | ||
| 4d7656e936 | |||
|
|
130ee5f5d0 | ||
|
|
dabb003733 | ||
|
|
e43dbf1349 | ||
|
|
fac228f186 | ||
|
|
3d1271abb7 | ||
|
|
e9ddf016c9 | ||
|
|
45c40e002c | ||
|
|
caa6f3a833 | ||
|
|
a3959376e3 | ||
|
|
05cdb44ab5 | ||
|
|
60755333bf | ||
|
|
f5eaa4cc26 |
@@ -1,9 +1,10 @@
|
||||
//Test if Alarm was triggerd and start Alarm, test if Alarm Time should be changed (Summer/Winter Time)
|
||||
void run_alarm(long currentMillis){
|
||||
if (test_alarm())
|
||||
{
|
||||
Serial.println("Start Alarm");
|
||||
write_log("Start Alarm");
|
||||
start_wake_light(currentMillis);
|
||||
setAlarmTimer(15);
|
||||
setAlarmTimer(wakeup_time + 5);
|
||||
}
|
||||
else{
|
||||
if (run_wake_up(currentMillis)){
|
||||
@@ -12,7 +13,7 @@ void run_alarm(long currentMillis){
|
||||
}
|
||||
//Test if Summer->Winter time change (this should also change the Alarm times!)
|
||||
bool dst = summertime_EU(y,M,d,h,1);
|
||||
//Serial.println(String(dst) + ":" + String(summer));
|
||||
//write_log(String(dst) + ":" + String(summer));
|
||||
if (dst != summer)
|
||||
{
|
||||
summer = dst;
|
||||
@@ -22,14 +23,15 @@ void run_alarm(long currentMillis){
|
||||
}
|
||||
}
|
||||
|
||||
//Stop Alarm if timeout reached
|
||||
void stop_alarm(){
|
||||
Serial.println("Stop Alarm");
|
||||
write_log("Stop Alarm");
|
||||
stop_wake_light();
|
||||
stop_alarm_beep();
|
||||
setAlarmTimer(0);
|
||||
}
|
||||
|
||||
|
||||
//Set Alarm Timeout to stop alarm if nobody is at home
|
||||
void setAlarmTimer(int Minutes){
|
||||
if (Minutes == 0)
|
||||
{
|
||||
@@ -42,6 +44,7 @@ void setAlarmTimer(int Minutes){
|
||||
}
|
||||
}
|
||||
|
||||
//Test if timeout reached
|
||||
void handleSleep(long intervall, long currentMillis){
|
||||
if(time_on < 0){
|
||||
return;
|
||||
@@ -53,7 +56,7 @@ void handleSleep(long intervall, long currentMillis){
|
||||
}
|
||||
|
||||
//####################################################################################################
|
||||
|
||||
//Turn Alarm on/off
|
||||
void switch_alarm_mode(){
|
||||
bool A1 = Clock.checkAlarmEnabled(1);
|
||||
bool A2 = Clock.checkAlarmEnabled(2);
|
||||
@@ -93,7 +96,7 @@ void switch_alarm_mode(){
|
||||
}
|
||||
delay_gui(1000);
|
||||
}
|
||||
|
||||
//Enter Alarm Menu
|
||||
void set_alarm_item(){
|
||||
if (setItem == 0)
|
||||
{
|
||||
@@ -110,7 +113,7 @@ void set_alarm_item(){
|
||||
setItem = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//Get Alarm Info for Display
|
||||
String get_alarm_string(){
|
||||
String alarm_string_1 = "";
|
||||
String alarm_string_2 = "";
|
||||
@@ -132,7 +135,7 @@ String get_alarm_string(){
|
||||
}
|
||||
|
||||
//####################################################################################################
|
||||
|
||||
//Test if Alarm is triggerd
|
||||
bool test_alarm(){
|
||||
bool A1 = Clock.checkIfAlarm(1);
|
||||
bool A2 = Clock.checkIfAlarm(2);
|
||||
@@ -173,7 +176,7 @@ void add_al2_minute(int i){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Save Alarm 1
|
||||
void set_alarm1(){
|
||||
int al1h_utc = al1h;
|
||||
if (summertime_EU(y,M,d,h,1))
|
||||
@@ -188,12 +191,12 @@ void set_alarm1(){
|
||||
byte A1Day, A1Hour, A1Minute, A1Second, AlarmBits;
|
||||
bool A1Dy, A1h12, A1PM;
|
||||
Clock.getA1Time(A1Day, A1Hour, A1Minute, A1Second, AlarmBits, A1Dy, A1h12, A1PM);
|
||||
Serial.println("Alarm1 Set:" + String(A1Day) + ", " + String(A1Hour) + ", " + String(A1Minute) + ", " + String(A1Second) + ", " + String(AlarmBits) + ", " + String(A1Dy) + ", " + String(A1h12) + ", ");
|
||||
write_log("Alarm1 Set:" + String(A1Day) + ", " + String(A1Hour) + ", " + String(A1Minute) + ", " + String(A1Second) + ", " + String(AlarmBits) + ", " + String(A1Dy) + ", " + String(A1h12) + ", ");
|
||||
//display_text("Alarm 1", String(A1Hour) + ":" +String(A1Minute));
|
||||
//delay_gui(1000);
|
||||
}
|
||||
|
||||
|
||||
//Save Alarm 2
|
||||
void set_alarm2(){
|
||||
int al2h_utc = al2h;
|
||||
if (summertime_EU(y,M,d,h,1))
|
||||
@@ -208,7 +211,7 @@ void set_alarm2(){
|
||||
byte A1Day, A1Hour, A1Minute, AlarmBits;
|
||||
bool A1Dy, A1h12, A1PM;
|
||||
Clock.getA2Time(A1Day, A1Hour, A1Minute, AlarmBits, A1Dy, A1h12, A1PM);
|
||||
Serial.println("Alarm2 Set:" + String(A1Day) + ", " + String(A1Hour) + ", " + String(A1Minute) + ", " + String(AlarmBits) + ", " + String(A1Dy) + ", " + String(A1h12) + ", ");
|
||||
write_log("Alarm2 Set:" + String(A1Day) + ", " + String(A1Hour) + ", " + String(A1Minute) + ", " + String(AlarmBits) + ", " + String(A1Dy) + ", " + String(A1h12) + ", ");
|
||||
//display_text("Alarm 2", String(A1Hour) + ":" +String(A1Minute));
|
||||
//delay_gui(1000);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Including the ESP8266 WiFi library
|
||||
// Including the ESP8266 WiFi library and other dependencies
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiClient.h>
|
||||
@@ -9,12 +9,34 @@
|
||||
#include <SPI.h>
|
||||
#include <DS3231.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#include <ESP8266HTTPUpdateServer.h>;
|
||||
#include <Wire.h>
|
||||
#include <LiquidCrystal_I2C.h> //https://github.com/agnunez/ESP8266-I2C-LCD1602
|
||||
#include <NTPtimeESP.h> //https://github.com/SensorsIot/NTPtimeESP
|
||||
#include <EEPROM.h>
|
||||
|
||||
//Default Settings
|
||||
String Hardware = "0.12";
|
||||
String Software = "0.12";
|
||||
|
||||
String ntp_server = "ntp2.uni-augsburg.de";
|
||||
bool ntp_update = true;
|
||||
int wakeup_time = 10;
|
||||
String message_text = "";
|
||||
//ConfigData (WiFi Name and Pin-Numbers)
|
||||
const String NodeName = "LichtWecker";
|
||||
|
||||
//Pin Taster
|
||||
const int pinTime = 3; //Pin fuer Toggle_Power und Einstellen der Uhrzeit (Lang)
|
||||
const int pinSet = 0; //Pin fuer Sleep und Zeit_Einstellung im Alarm/Time Set Mode
|
||||
const int pinAlarm = 2; //Pin fuer Alarm An/Aus und setzen der Alarmzeiten (Lang)
|
||||
//Pin Relay
|
||||
const int outBeep = 9;
|
||||
|
||||
|
||||
// Set web server port number to 80
|
||||
ESP8266WebServer server(80);
|
||||
ESP8266HTTPUpdateServer httpUpdater;
|
||||
//LED Band Setup
|
||||
#define FASTLED_ESP8266_RAW_PIN_ORDER
|
||||
#include "FastLED.h"
|
||||
@@ -25,32 +47,19 @@
|
||||
#define CLOCK_PIN 13
|
||||
// This is an array of leds. One item for each led in your strip.
|
||||
CRGB leds[NUM_LEDS];
|
||||
|
||||
//RealTimeClock
|
||||
RTClib RTC;
|
||||
DS3231 Clock;
|
||||
//NTP Setup
|
||||
NTPtime NTPch("ntp2.uni-augsburg.de"); // Choose server pool as required
|
||||
|
||||
NTPtime NTPch(ntp_server); // Choose server pool as required
|
||||
//Display
|
||||
LiquidCrystal_I2C lcd(0x3f, 16, 2);
|
||||
|
||||
//ConfigData (WiFi Name and Pin-Numbers)
|
||||
const String NodeName = "LichtWecker";
|
||||
//Pin Taster
|
||||
const int pinTime = 3; //Pin fuer Toggle_Power und Einstellen der Uhrzeit (Lang)
|
||||
const int pinSet = 0; //Pin fuer Sleep und Zeit_Einstellung im Alarm/Time Set Mode
|
||||
const int pinAlarm = 2; //Pin fuer Alarm An/Aus und setzen der Alarmzeiten (Lang)
|
||||
|
||||
//Pin Relay
|
||||
const int outBeep = 9;
|
||||
|
||||
//Helpers
|
||||
//To know if connected to wifi or not:
|
||||
bool wifi_connected = false;
|
||||
|
||||
//For Summertime change notification (change alarmtime) this should be saved in the EEPROM!
|
||||
bool summer = false;
|
||||
|
||||
//Alarm Started?
|
||||
bool alarm_started = false;
|
||||
long startTime = 0;
|
||||
@@ -64,7 +73,6 @@ int al2m = 0;
|
||||
//Alarm run Counter
|
||||
long time_on = -1;
|
||||
int minutes_sleep = -1;
|
||||
|
||||
//Current Date and Time from RTC
|
||||
int h = 0;
|
||||
int m = 0;
|
||||
@@ -74,24 +82,24 @@ int M = 0;
|
||||
int y = 0;
|
||||
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
|
||||
String dow = "-";
|
||||
|
||||
|
||||
//Current Menu Item
|
||||
int setItem = 0;
|
||||
|
||||
//Display is not updated (for block_gui Secondes)
|
||||
long block_gui = -1;
|
||||
|
||||
//Counting Mills
|
||||
long previousMillis = 0;
|
||||
|
||||
//If not Connected to Wifi
|
||||
void configModeCallback (WiFiManager *myWiFiManager) {
|
||||
//if you used auto generated SSID, print it
|
||||
//Serial.println(myWiFiManager->getConfigPortalSSID());
|
||||
//write_log(myWiFiManager->getConfigPortalSSID());
|
||||
display_text("Wifi: Licht","PW: Wecker");
|
||||
}
|
||||
|
||||
//Initial Code
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(10);
|
||||
|
||||
//Setup Display
|
||||
// Initialise the LCD
|
||||
lcd.begin(4,5); // sda=0, scl=2
|
||||
@@ -159,9 +167,9 @@ void setup() {
|
||||
delay(5000);
|
||||
}
|
||||
if (wifiManager.autoConnect("Licht", "Wecker")){
|
||||
Serial.println("WiFi connected");
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
write_log("WiFi connected");
|
||||
write_log("IP address: ");
|
||||
write_log(WiFi.localIP().toString());
|
||||
wifi_connected = true;
|
||||
display_text("IP address",WiFi.localIP().toString());
|
||||
delay(5000);
|
||||
@@ -169,9 +177,9 @@ void setup() {
|
||||
else{
|
||||
WiFi.mode(WIFI_OFF);
|
||||
}
|
||||
display_text("Licht Wecker","SW: 0.04");
|
||||
display_text("Licht Wecker","SW: " + Software);
|
||||
delay(1000);
|
||||
display_text("Licht Wecker","HW: 0.10");
|
||||
display_text("Licht Wecker","HW: " + Hardware);
|
||||
delay(1000);
|
||||
display_text("Licht Wecker","");
|
||||
|
||||
@@ -193,7 +201,7 @@ void setup() {
|
||||
al1h = A1Hour;
|
||||
}
|
||||
al1m = A1Minute;
|
||||
Serial.println("Alarm1 Set:" + String(A1Day) + ", " + String(A1Hour) + ", " + String(A1Minute) + ", " + String(AlarmBits) + ", " + String(A1Dy) + ", " + String(A1h12) + ", ");
|
||||
write_log("Alarm1 Set:" + String(A1Day) + ", " + String(A1Hour) + ", " + String(A1Minute) + ", " + String(AlarmBits) + ", " + String(A1Dy) + ", " + String(A1h12) + ", ");
|
||||
|
||||
Clock.getA2Time(A1Day, A1Hour, A1Minute, AlarmBits, A1Dy, A1h12, A1PM);
|
||||
if (summer)
|
||||
@@ -204,7 +212,7 @@ void setup() {
|
||||
al2h = A1Hour;
|
||||
}
|
||||
al2m = A1Minute;
|
||||
Serial.println("Alarm2 Set:" + String(A1Day) + ", " + String(A1Hour) + ", " + String(A1Minute) + ", " + String(AlarmBits) + ", " + String(A1Dy) + ", " + String(A1h12) + ", ");
|
||||
write_log("Alarm2 Set:" + String(A1Day) + ", " + String(A1Hour) + ", " + String(A1Minute) + ", " + String(AlarmBits) + ", " + String(A1Dy) + ", " + String(A1h12) + ", ");
|
||||
|
||||
show_green();
|
||||
update_time_from_web();
|
||||
@@ -213,65 +221,54 @@ void setup() {
|
||||
|
||||
previousMillis = millis();
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
//OTA
|
||||
// No authentication by default
|
||||
|
||||
ArduinoOTA.setPassword(NodeName.c_str());
|
||||
ArduinoOTA.setHostname(NodeName.c_str());
|
||||
|
||||
ArduinoOTA.onStart([]() {
|
||||
Serial.println("Start");
|
||||
});
|
||||
ArduinoOTA.onEnd([]() {
|
||||
Serial.println("\nEnd");
|
||||
});
|
||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
||||
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
|
||||
});
|
||||
ArduinoOTA.onError([](ota_error_t error) {
|
||||
Serial.printf("Error[%u]: ", error);
|
||||
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
|
||||
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
|
||||
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
|
||||
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
|
||||
else if (error == OTA_END_ERROR) Serial.println("End Failed");
|
||||
});
|
||||
ArduinoOTA.begin();
|
||||
//-------------------------------------------------
|
||||
update_time_from_web();
|
||||
|
||||
setup_webserver();
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
//OTA
|
||||
ArduinoOTA.handle();
|
||||
//OTA
|
||||
|
||||
//Handle web requests
|
||||
handle_webserver();
|
||||
unsigned long currentMillis = millis();
|
||||
unsigned long intervall = currentMillis - previousMillis;
|
||||
|
||||
update_display(currentMillis,intervall);
|
||||
|
||||
//Test Input-Pin pressed
|
||||
test_pin();
|
||||
//Handle Sleep Timer timeout
|
||||
handleSleep(intervall, currentMillis);
|
||||
//Test time every hour
|
||||
if(m == 1 && s == 30)
|
||||
{
|
||||
update_time_from_web();
|
||||
}
|
||||
//Delay for Wifi Tasks
|
||||
delay(100);
|
||||
}
|
||||
|
||||
void update_display(){
|
||||
unsigned long currentMillis = millis();
|
||||
unsigned long intervall = currentMillis - previousMillis;
|
||||
update_display(currentMillis,intervall);
|
||||
}
|
||||
|
||||
void update_display(unsigned long currentMillis, unsigned long intervall){
|
||||
//Unblock Display (if block_gui was set)
|
||||
release_gui(currentMillis);
|
||||
|
||||
// put your main code here, to run repeatedly:
|
||||
if(setItem == 0){
|
||||
//Run normal
|
||||
update_Time();
|
||||
run_alarm(currentMillis);
|
||||
if (block_gui < 0)
|
||||
show_current_time(intervall,currentMillis);
|
||||
}
|
||||
else{
|
||||
//Show Menu
|
||||
show_time_infos(intervall,currentMillis);
|
||||
previousMillis = currentMillis;
|
||||
}
|
||||
test_pin();
|
||||
handleSleep(intervall, currentMillis);
|
||||
if(m == 1 && s == 30)
|
||||
{
|
||||
update_time_from_web();
|
||||
}
|
||||
delay(100);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//Show current Time and Date on display
|
||||
void show_current_time(long intervall, long currentMillis){
|
||||
if(intervall > 16000){
|
||||
previousMillis = currentMillis;
|
||||
@@ -45,7 +46,7 @@ void show_time_infos(long intervall, long currentMillis){
|
||||
|
||||
|
||||
//####################################################################################################
|
||||
//Setup
|
||||
//Enter Time Menu
|
||||
void switch_set_item(){
|
||||
setItem = setItem + 1;
|
||||
if(setItem > 6)
|
||||
@@ -111,7 +112,7 @@ void update_Time(){
|
||||
}
|
||||
|
||||
dow = daysOfTheWeek[Clock.getDoW()];
|
||||
//Serial.println(String(h) + ":" + String(m) + ":" + String(s) + " - " + String(d) + "." + String(M) + "." + String(y) + " | DST: " + String(summertime_EU(y,M,d,h,1)));
|
||||
//write_log(String(h) + ":" + String(m) + ":" + String(s) + " - " + String(d) + "." + String(M) + "." + String(y) + " | DST: " + String(summertime_EU(y,M,d,h,1)));
|
||||
}
|
||||
|
||||
//###################################################################################################################################
|
||||
@@ -119,7 +120,7 @@ void update_Time(){
|
||||
void display_year(int Day, int Month, int Year){
|
||||
display_text("Jahr", String(Year));
|
||||
}
|
||||
|
||||
int current_Sec = 0;
|
||||
void display_time(int Stunde, int Minute, int Sekunde){
|
||||
String Min = String(Minute);
|
||||
String Stu = String(Stunde);
|
||||
@@ -167,9 +168,19 @@ void display_time(int Stunde, int Minute, int Sekunde){
|
||||
/*else if (Sekunde % 2 == 0){
|
||||
display_text(Stu + ":" + Min, get_alarm_string());
|
||||
}*/
|
||||
else if(message_text != ""){
|
||||
display_text(Stu + ":" + Min + ":" + Sek, message_text);
|
||||
setBrightnes(true);
|
||||
if (alarm_started == false){
|
||||
if (Sekunde % 2 == 0 && Sekunde != current_Sec){
|
||||
set_color(0, 0, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
display_text(Stu + ":" + Min + ":" + Sek, get_alarm_string());
|
||||
}
|
||||
current_Sec = Sekunde;
|
||||
}
|
||||
|
||||
void display_date(int Day, int Month, int Year){
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//Start Wakeup sound
|
||||
void run_wake_up_beep(long currentMillis){
|
||||
if (alarm_started == true)
|
||||
{
|
||||
@@ -10,10 +11,12 @@ void run_wake_up_beep(long currentMillis){
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
//Stop Sound
|
||||
void stop_alarm_beep(){
|
||||
beepOff();
|
||||
}
|
||||
//############################################################################################
|
||||
//Helpers
|
||||
|
||||
void toggle_alarm_beep(){
|
||||
int currentState = digitalRead(outBeep);
|
||||
@@ -28,7 +31,7 @@ void toggle_alarm_beep(){
|
||||
void beepOff(){
|
||||
int currentState = digitalRead(outBeep);
|
||||
if (currentState != LOW){
|
||||
Serial.println("ALARM");
|
||||
//write_log("ALARM");
|
||||
digitalWrite(outBeep, LOW);
|
||||
}
|
||||
}
|
||||
@@ -36,7 +39,7 @@ void beepOff(){
|
||||
void beepOn(){
|
||||
int currentState = digitalRead(outBeep);
|
||||
if (currentState != HIGH){
|
||||
Serial.println("ALARM");
|
||||
//write_log("ALARM");
|
||||
digitalWrite(outBeep, HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
|
||||
//Helpers
|
||||
String current_string = "";
|
||||
|
||||
//Display Text
|
||||
void display_text(String text1, String text2){
|
||||
if (current_string != text1 + text2){
|
||||
//Serial.println("Display:");
|
||||
//write_log("Display:");
|
||||
lcd.clear();
|
||||
lcd.setCursor(freespace(text1), 0);
|
||||
lcd.print(text1);
|
||||
//Serial.println(text1);
|
||||
//write_log(text1);
|
||||
lcd.setCursor(freespace(text2), 1);
|
||||
lcd.print(text2);
|
||||
//Serial.println(text2);
|
||||
//write_log(text2);
|
||||
//ledMatrix.clear();
|
||||
//ledMatrix.setText(text);
|
||||
//ledMatrix.drawText();
|
||||
@@ -18,11 +19,11 @@ void display_text(String text1, String text2){
|
||||
current_string = text1 + text2;
|
||||
}
|
||||
}
|
||||
|
||||
//Calculate space
|
||||
int freespace(String text){
|
||||
if (text.length() > 14)
|
||||
{
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
else{
|
||||
int freespace = 16 - text.length();
|
||||
|
||||
@@ -4,13 +4,22 @@ uint addr = 0;
|
||||
|
||||
struct {
|
||||
bool summertime = false;
|
||||
bool ntp_update = true;
|
||||
int wakeup_time = 10;
|
||||
char ntp_server[22] = "ntp2.uni-augsburg.de";
|
||||
} data;
|
||||
|
||||
void write_eeprom(){
|
||||
EEPROM.begin(512);
|
||||
EEPROM.begin(1024);
|
||||
// load EEPROM data into RAM, see it
|
||||
data.summertime = summer;
|
||||
Serial.println("Writing to EEPROM: "+String(data.summertime));
|
||||
data.ntp_update = ntp_update;
|
||||
data.wakeup_time = wakeup_time;
|
||||
ntp_server.toCharArray(data.ntp_server,22);
|
||||
write_log("Writing to EEPROM: "+String(data.summertime));
|
||||
write_log("Writing to EEPROM: "+String(data.ntp_update));
|
||||
write_log("Writing to EEPROM: "+String(data.wakeup_time));
|
||||
write_log("Writing to EEPROM: "+String(data.ntp_server));
|
||||
// replace values in EEPROM
|
||||
EEPROM.put(addr,data);
|
||||
EEPROM.commit();
|
||||
@@ -18,10 +27,25 @@ void write_eeprom(){
|
||||
}
|
||||
|
||||
bool get_eeprom(){
|
||||
EEPROM.begin(512);
|
||||
EEPROM.begin(1024);
|
||||
EEPROM.get(addr,data);
|
||||
Serial.println("Found: "+String(data.summertime));
|
||||
write_log("Read: "+String(data.summertime));
|
||||
write_log("Read: "+String(data.ntp_update));
|
||||
write_log("Read: "+String(data.wakeup_time));
|
||||
write_log("Read: "+String(data.ntp_update));
|
||||
EEPROM.end();
|
||||
summer = data.summertime;
|
||||
ntp_update = data.ntp_update;
|
||||
wakeup_time = data.wakeup_time;
|
||||
ntp_server = data.ntp_server;
|
||||
}
|
||||
|
||||
|
||||
void reset_eeprom(){
|
||||
summer = false;
|
||||
ntp_update = true;
|
||||
wakeup_time = 10;
|
||||
ntp_server = "ntp2.uni-augsburg.de";
|
||||
write_eeprom();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ void show_white(){
|
||||
leds[i] = CRGB::White;
|
||||
}
|
||||
FastLED.show();
|
||||
Serial.println("Light: WHITE");
|
||||
//write_log("Light: WHITE");
|
||||
}
|
||||
|
||||
//Show LED Colors
|
||||
@@ -19,7 +19,7 @@ void show_black(){
|
||||
leds[i] = CRGB::Black;
|
||||
}
|
||||
FastLED.show();
|
||||
//Serial.println("Light: BLACK");
|
||||
//write_log("Light: BLACK");
|
||||
}
|
||||
|
||||
//Show LED Colors
|
||||
@@ -31,9 +31,9 @@ void show_green(){
|
||||
leds[i] = CRGB::Green;
|
||||
}
|
||||
FastLED.show();
|
||||
Serial.println("Light: GREEN");
|
||||
write_log("Light: GREEN");
|
||||
}
|
||||
|
||||
//Set LED Color to RGB Value
|
||||
void set_color(int r, int g, int b){
|
||||
FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RBG>(leds, NUM_LEDS);
|
||||
for(int i=0; i < NUM_LEDS; i = i+1 )
|
||||
@@ -41,24 +41,30 @@ void set_color(int r, int g, int b){
|
||||
leds[i].setRGB( r, g, b);
|
||||
}
|
||||
FastLED.show();
|
||||
Serial.println("Light: ");
|
||||
Serial.println(r);
|
||||
Serial.println(b);
|
||||
Serial.println(g);
|
||||
//write_log("Light: ");
|
||||
//write_log(String(r));
|
||||
//write_log(String(b));
|
||||
//write_log(String(g));
|
||||
}
|
||||
|
||||
//Run Color movement for Alarm
|
||||
bool run_wake_up(long currentMillis){
|
||||
if (alarm_started == true)
|
||||
{
|
||||
long delta = (currentMillis - startTime)/1000;
|
||||
if (delta < 220){
|
||||
set_color(30 + int(delta), int(delta)/4, 0);
|
||||
long max_wake_time = wakeup_time *60; //Calculate Wakeuptime in Seconds
|
||||
int maxvalue = int(220/(max_wake_time/3));
|
||||
|
||||
if (delta < (max_wake_time/3)){
|
||||
int color_time = delta * maxvalue;
|
||||
set_color(30 + int(color_time), int(color_time)/4, 0);
|
||||
}
|
||||
else if(delta < 405){
|
||||
set_color(255, int(delta - 220)+55, int((delta - 220)/4));
|
||||
else if((delta < ((max_wake_time/3)*2))){
|
||||
int color_time = (delta - (max_wake_time/3)) * maxvalue;
|
||||
set_color(255, int(color_time)+30, int((color_time)/4));
|
||||
}
|
||||
else if(delta < 605){
|
||||
set_color(255, 255, int((delta - 405))+55);
|
||||
else if(delta < max_wake_time){
|
||||
int color_time = (delta - ((max_wake_time/3)*2)) * maxvalue;
|
||||
set_color(255, 255, int((color_time))+30);
|
||||
}
|
||||
else{
|
||||
if (delta % 2 == 0){
|
||||
@@ -78,7 +84,7 @@ bool run_wake_up(long currentMillis){
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//Toggle Light Full/Off
|
||||
void switch_lamp(){
|
||||
if(lamp_on == false){
|
||||
lamp_on = true;
|
||||
@@ -89,7 +95,7 @@ void switch_lamp(){
|
||||
show_black();
|
||||
}
|
||||
}
|
||||
|
||||
//Start Alarm Light
|
||||
void start_wake_light(long currentMillis){
|
||||
if (alarm_started == false)
|
||||
{
|
||||
@@ -98,7 +104,7 @@ void start_wake_light(long currentMillis){
|
||||
set_color(30, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//Turn of Alarm Light
|
||||
void stop_wake_light(){
|
||||
if (alarm_started == true)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//Code to update time from the web
|
||||
void update_time_from_web(){
|
||||
//Serial.println(wifi_connected);
|
||||
if (wifi_connected == true)
|
||||
//write_log(wifi_connected);
|
||||
if (wifi_connected == true && ntp_update == true)
|
||||
{
|
||||
strDateTime dateTime;
|
||||
// first parameter: Time zone in floating point (for India); second parameter: 1 for European summer time; 2 for US daylight saving time; 0 for no DST adjustment; (contributed by viewwer, not tested by me)
|
||||
@@ -17,7 +17,7 @@ void update_time_from_web(){
|
||||
byte actualMonth = dateTime.month;
|
||||
byte actualday =dateTime.day;
|
||||
byte actualdayofWeek = dateTime.dayofWeek;
|
||||
if (actualMinute != m && actualday != 7 && actualMonth != 2 && actualyear != 2036){
|
||||
if (actualMinute != m && actualday != 7 && actualMonth != 2 && actualyear != 2036 && actualHour != 0){
|
||||
h = actualHour;
|
||||
m = actualMinute;
|
||||
s = actualsecond;
|
||||
@@ -25,7 +25,8 @@ void update_time_from_web(){
|
||||
M = actualMonth;
|
||||
d = actualday;
|
||||
set_clock();
|
||||
Serial.println("Time Updated!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
write_log("Time Updated!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
write_log(String(h) + ":" + String(m) + " - " + String(d) + "." + String(M) + "." + String(y));
|
||||
display_text("Update Time","");
|
||||
delay_gui(1000);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
//Test if button pressed
|
||||
void test_pin(){
|
||||
handle_Time_switch();
|
||||
handle_Set_switch();
|
||||
handle_Alarm_switch();
|
||||
}
|
||||
|
||||
|
||||
//If Alarm switch pressed
|
||||
void handle_Alarm_switch(){
|
||||
int state = digitalRead(pinAlarm);
|
||||
if(state == LOW && setItem == 0) {
|
||||
@@ -19,9 +20,15 @@ void handle_Alarm_switch(){
|
||||
{
|
||||
stop_alarm();
|
||||
}
|
||||
else{
|
||||
//Delete Message
|
||||
if(message_text != ""){
|
||||
message_text = "";
|
||||
}
|
||||
else{
|
||||
switch_alarm_mode();
|
||||
}
|
||||
}
|
||||
delay(200);
|
||||
}
|
||||
}
|
||||
@@ -31,19 +38,29 @@ void handle_Alarm_switch(){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//If Set switch pressed
|
||||
void handle_Set_switch(){
|
||||
int state = digitalRead(pinSet);
|
||||
if (state == LOW && setItem > 0){
|
||||
set_time();
|
||||
delay(200);
|
||||
}
|
||||
else if (state == LOW && setItem == 0){
|
||||
else if(state == LOW && setItem == 0) {
|
||||
int presstime = get_pin_delay(pinSet);
|
||||
if (presstime > 10){
|
||||
//Do some Stuff here
|
||||
|
||||
delay(200);
|
||||
wait_to_release(pinSet);
|
||||
}
|
||||
else{
|
||||
switch_lamp();
|
||||
delay(200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//If Time switch pressed
|
||||
void handle_Time_switch(){
|
||||
int state = digitalRead(pinTime);
|
||||
if(state == LOW && setItem == 0) {
|
||||
@@ -64,24 +81,27 @@ void handle_Time_switch(){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Helper for long-press
|
||||
int get_pin_delay(int pin){
|
||||
int state = digitalRead(pin);
|
||||
int delay_count = 0;
|
||||
while(state == LOW && delay_count < 11)
|
||||
{
|
||||
state = digitalRead(pin);
|
||||
update_display();
|
||||
delay(100);
|
||||
delay_count = delay_count +1;
|
||||
}
|
||||
return delay_count;
|
||||
}
|
||||
|
||||
//Helper for long-press
|
||||
void wait_to_release(int pin){
|
||||
int state = digitalRead(pin);
|
||||
while(state == LOW)
|
||||
{
|
||||
state = digitalRead(pin);
|
||||
update_display();
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
180
LichtWecker/webserver.ino
Normal file
180
LichtWecker/webserver.ino
Normal file
@@ -0,0 +1,180 @@
|
||||
//Helpers
|
||||
String logfile = "";
|
||||
//Webserver
|
||||
//###################################################################################
|
||||
|
||||
void setup_webserver(){
|
||||
httpUpdater.setup(&server, "Licht", "Wecker");
|
||||
|
||||
server.on("/log", []() { //Define the handling function for the path
|
||||
|
||||
server.send(200, "text/plain", logfile);
|
||||
|
||||
});
|
||||
|
||||
server.on("/", handleRootPath); //Associate the handler function to the path
|
||||
server.begin(); //Start the server
|
||||
}
|
||||
|
||||
void handle_webserver(){
|
||||
server.handleClient(); //Handling of incoming requests
|
||||
}
|
||||
|
||||
|
||||
//Layout
|
||||
//###################################################################################
|
||||
|
||||
String Meta = "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1\"><meta charset=\"UTF-8\">";
|
||||
String CSS = "<style>.card {box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);background-color: white;transition: 0.3s;margin: 0.2rem;padding: 0.4rem;padding-top: 0.5rem;display: inline-block;display: -webkit-inline-block;text-align:center;flex: 1;-webkit-flex: 1 1 250px;}.cardcontainer {box-sizing: border-box;display:flex;flex-wrap: wrap;display: -webkit-flex;-webkit-flex-wrap: wrap;overflow:auto;}#footer {border-top: 3px solid darkblue;-webkit-justify-content: space-around;display: absolute;justify-content: space-around;}</style>";
|
||||
String Header = "<!DOCTYPE html><html><head>" + Meta + CSS + "<title>Lichtwecker</title></head><body style=\"text-align:left;margin: 0px;padding: 0px;\"><div id=\"header\" style=\"background-color: blue;margin: 0px;padding: 0px;color: white;border: 0.2em solid blue;text-align: center;\"><h1 style=\"margin:0px;padding:0px\">Licht Wecker</h1></div><div id=\"content\" style=\"font-size:1.2em;margin:0.5em;\" class=\"cardcontainer\">";
|
||||
String Footer = "</div><br><br><div id=\"footer\">Not for Sale, Prototyp by <a href=\"http://christian.mittring-mering.de/\">CHM</a>, Hardware: " + Hardware + ", Software: "+ Software +"</div></body></html> ";
|
||||
String card_start = "<div class=\"card\">";
|
||||
String card_end = "</div>";
|
||||
|
||||
void handleRootPath() { //Handler for the rooth path
|
||||
handleArgs();
|
||||
}
|
||||
|
||||
//############################################################
|
||||
//WebPage Args
|
||||
void handleArgs(){
|
||||
for (int i = 0; i < server.args(); i++) {
|
||||
//write_log(server.argName(i) +" : " +server.arg(i));
|
||||
if(server.argName(i) == "ntp"){
|
||||
if(server.arg(i) == "true"){
|
||||
if (ntp_update != true){
|
||||
ntp_update = true;
|
||||
write_eeprom();
|
||||
}
|
||||
}
|
||||
else if (server.arg(i) == "false"){
|
||||
if (ntp_update != false){
|
||||
ntp_update = false;
|
||||
write_eeprom();
|
||||
}
|
||||
}
|
||||
redirect();
|
||||
break;
|
||||
}
|
||||
else if (server.argName(i) == "ntp_server"){
|
||||
if (server.arg(i) != ""){
|
||||
ntp_server = server.arg(i);
|
||||
write_eeprom();
|
||||
}
|
||||
redirect();
|
||||
break;
|
||||
}
|
||||
else if(server.argName(i) == "wakeup_time"){
|
||||
if (server.arg(i) != ""){
|
||||
wakeup_time = server.arg(i).toInt();
|
||||
write_eeprom();
|
||||
}
|
||||
redirect();
|
||||
break;
|
||||
}
|
||||
else if(server.argName(i) == "a1"){
|
||||
if(server.arg(i) == "true"){
|
||||
Clock.turnOnAlarm(1);
|
||||
}
|
||||
else if (server.arg(i) == "false"){
|
||||
Clock.turnOffAlarm(1);
|
||||
}
|
||||
redirect();
|
||||
break;
|
||||
}
|
||||
else if(server.argName(i) == "a2"){
|
||||
if(server.arg(i) == "true"){
|
||||
Clock.turnOnAlarm(2);
|
||||
}
|
||||
else if (server.arg(i) == "false"){
|
||||
Clock.turnOffAlarm(2);
|
||||
}
|
||||
redirect();
|
||||
break;
|
||||
}
|
||||
else if(server.argName(i) == "al1h" && server.argName(i +1) == "al1m"){
|
||||
al1h = server.arg(i).toInt();
|
||||
al1m = server.arg(i+1).toInt();
|
||||
set_alarm1();
|
||||
redirect();
|
||||
break;
|
||||
}
|
||||
else if(server.argName(i) == "al2h" && server.argName(i +1) == "al2m"){
|
||||
al2h = server.arg(i).toInt();
|
||||
al2m = server.arg(i+1).toInt();
|
||||
set_alarm2();
|
||||
redirect();
|
||||
break;
|
||||
}
|
||||
else if (server.argName(i) == "news"){
|
||||
if (server.arg(i) != ""){
|
||||
message_text = server.arg(i);
|
||||
}
|
||||
redirect();
|
||||
break;
|
||||
}
|
||||
else if(server.argName(i) == "reset" && server.arg(i) == "true"){
|
||||
print_reset();
|
||||
ESP.restart();
|
||||
break;
|
||||
}
|
||||
else if(server.argName(i) == "factory_reset" && server.arg(i) == "true"){
|
||||
reset_eeprom();
|
||||
print_reset();
|
||||
delay(1000);
|
||||
ESP.restart();
|
||||
break;
|
||||
}
|
||||
}
|
||||
print_website();
|
||||
}
|
||||
|
||||
|
||||
//Webpage
|
||||
//###################################################################################
|
||||
|
||||
void print_website(){
|
||||
bool A1 = Clock.checkAlarmEnabled(1);
|
||||
bool A2 = Clock.checkAlarmEnabled(2);
|
||||
String Alarm1 = "<b>Alarm 1:</b> <form action=\"/\" methode=\"get\"><input type=\"number\" name=\"al1h\" value=\"" + String(al1h) + "\">:<input type=\"number\" name=\"al1m\" value=\"" + String(al1m) + "\"><input type=\"submit\" value=\"Speichern\"></form> Sommerzeit: " + getBoolString(summer) + "<br>Aktiv: " + getBoolString(A1) + "<br><a href=\"?a1=true\">Aktivieren</a> " + " <a href=\"?a1=false\">Deaktivieren</a>";
|
||||
String Alarm2 = "<b>Alarm 2:</b> <form action=\"/\" methode=\"get\"><input type=\"number\" name=\"al2h\" value=\"" + String(al2h) + "\">:<input type=\"number\" name=\"al2m\" value=\"" + String(al2m) + "\"><input type=\"submit\" value=\"Speichern\"></form> Sommerzeit: " + getBoolString(summer) + "<br>Aktiv: " + getBoolString(A2) + "<br><a href=\"?a2=true\">Aktivieren</a> " + " <a href=\"?a2=false\">Deaktivieren</a>";
|
||||
String Weckzeit = "<b>Weckdauer (Minuten):</b> <form action=\"/\" methode=\"get\"><input type=\"number\" name=\"wakeup_time\" value=\"" + String(wakeup_time) + "\"><input type=\"submit\" value=\"Speichern\"></form>";
|
||||
String Alarm = "<h3>Alarm</h3>" + Alarm1 + "<br><br>" + Alarm2 + "<br><br>" + Weckzeit;
|
||||
String Zeit = "<br><h3>Zeit</h3>" + String(h) + ":" + String(m) + ":" + String(s) + " - " + String(d) + "." + String(M) + "." + String(y) + " | DST: " + String(summertime_EU(y,M,d,h,1));
|
||||
String News = "<br><h3>Nachricht</h3>Diese Nachricht wird auf dem Display angezeigt!<br><form action=\"/\" methode=\"get\"><input type=\"text\" name=\"news\" value=\"" + String(message_text) + "\"><input type=\"submit\" value=\"Speichern\"></form><br>";
|
||||
String NTP = "<br><h3>NTP</h3><b>Server:</b> <form action=\"/\" methode=\"get\"><input type=\"text\" name=\"ntp_server\" value=\"" + String(ntp_server) + "\"><input type=\"submit\" value=\"Speichern\"></form><br>stündliches Zeit Update: " + getBoolString(ntp_update) + "<br><a href=\"?ntp=true\">Aktivieren</a> " + " <a href=\"?ntp=false\">Deaktivieren</a>";
|
||||
String Reboot = "<br><h3>System:</h3><a href=\"?reset=true\">Neustart</a><br><br><a href=\"update\">Software Update Modus</a><br><br><a href=\"?factory_reset=true\">Werkseinstellungen</a><br><br><a href=\"log\">Log</a>";
|
||||
String Body = card_start + Alarm + card_end + card_start + News + card_end + card_start + NTP + card_end + card_start + Reboot + card_end;
|
||||
server.send(200, "text/html", Header + Body + Footer);
|
||||
}
|
||||
|
||||
void print_reset(){
|
||||
String Body = "<div class=\"card\">Neustart... <a href=\"/\">Neu laden</a></div>";
|
||||
server.send(200, "text/html", Header + Body + Footer);
|
||||
delay(500);
|
||||
}
|
||||
|
||||
void redirect(){
|
||||
String redirect = "<head><meta http-equiv=\"refresh\" content=\"0; URL=/\" /></head>";
|
||||
server.send(200, "text/html", redirect);
|
||||
delay(50);
|
||||
}
|
||||
//Helpers
|
||||
//####################################################################################
|
||||
String getBoolString(bool value){
|
||||
if(value)
|
||||
{
|
||||
return "Ja";
|
||||
}
|
||||
return "Nein";
|
||||
}
|
||||
|
||||
|
||||
void write_log(String text){
|
||||
Serial.println(text);
|
||||
logfile = logfile + String(text) + "\r\n";
|
||||
if (logfile.length() > 140000) {
|
||||
logfile = logfile.substring((logfile.length()-100000));
|
||||
}
|
||||
}
|
||||
|
||||
BIN
LichtWeckerAnleitung.docx
Normal file
BIN
LichtWeckerAnleitung.docx
Normal file
Binary file not shown.
24
README.md
24
README.md
@@ -1,3 +1,27 @@
|
||||
# Licht_Wecker
|
||||
|
||||
Licht Wecker für die Bradls
|
||||
|
||||
## Verwendete Bauteile:
|
||||
NodeMcu ESP8266
|
||||
I2C LCD Display 1602
|
||||
DS3231 Real Time Clock Modul
|
||||
30 WS2801 LED’s
|
||||
MP3 Sound Modul 3W
|
||||
|
||||
## Pin-Verschaltung:
|
||||
### Taster (geschaltet gegen GND):
|
||||
TIME: GPIO 3
|
||||
SET: GPIO 0
|
||||
ALARM: GPIO 2
|
||||
### Sound Modul (5V Spannungsversorung über Transistor)
|
||||
GPIO 9
|
||||
### LCD:
|
||||
SDA: GPIO 4
|
||||
SDC: GPIO 5
|
||||
### DS3231:
|
||||
SDA: GPIO 4
|
||||
SDC: GPIO 5
|
||||
### WS2801:
|
||||
DATA_PIN: GPIO 14
|
||||
CLOCK_PIN: GPIO 13
|
||||
|
||||
Reference in New Issue
Block a user