Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4644f9ba3e | ||
|
|
d00e92a202 | ||
|
|
05830876eb | ||
|
|
8755571ef4 | ||
| 4d7656e936 | |||
|
|
130ee5f5d0 | ||
|
|
dabb003733 | ||
|
|
e43dbf1349 | ||
|
|
fac228f186 | ||
|
|
3d1271abb7 | ||
|
|
e9ddf016c9 |
@@ -1,3 +1,4 @@
|
|||||||
|
//Test if Alarm was triggerd and start Alarm, test if Alarm Time should be changed (Summer/Winter Time)
|
||||||
void run_alarm(long currentMillis){
|
void run_alarm(long currentMillis){
|
||||||
if (test_alarm())
|
if (test_alarm())
|
||||||
{
|
{
|
||||||
@@ -22,6 +23,7 @@ void run_alarm(long currentMillis){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Stop Alarm if timeout reached
|
||||||
void stop_alarm(){
|
void stop_alarm(){
|
||||||
write_log("Stop Alarm");
|
write_log("Stop Alarm");
|
||||||
stop_wake_light();
|
stop_wake_light();
|
||||||
@@ -29,7 +31,7 @@ void stop_alarm(){
|
|||||||
setAlarmTimer(0);
|
setAlarmTimer(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Set Alarm Timeout to stop alarm if nobody is at home
|
||||||
void setAlarmTimer(int Minutes){
|
void setAlarmTimer(int Minutes){
|
||||||
if (Minutes == 0)
|
if (Minutes == 0)
|
||||||
{
|
{
|
||||||
@@ -42,6 +44,7 @@ void setAlarmTimer(int Minutes){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Test if timeout reached
|
||||||
void handleSleep(long intervall, long currentMillis){
|
void handleSleep(long intervall, long currentMillis){
|
||||||
if(time_on < 0){
|
if(time_on < 0){
|
||||||
return;
|
return;
|
||||||
@@ -53,7 +56,7 @@ void handleSleep(long intervall, long currentMillis){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//####################################################################################################
|
//####################################################################################################
|
||||||
|
//Turn Alarm on/off
|
||||||
void switch_alarm_mode(){
|
void switch_alarm_mode(){
|
||||||
bool A1 = Clock.checkAlarmEnabled(1);
|
bool A1 = Clock.checkAlarmEnabled(1);
|
||||||
bool A2 = Clock.checkAlarmEnabled(2);
|
bool A2 = Clock.checkAlarmEnabled(2);
|
||||||
@@ -93,7 +96,7 @@ void switch_alarm_mode(){
|
|||||||
}
|
}
|
||||||
delay_gui(1000);
|
delay_gui(1000);
|
||||||
}
|
}
|
||||||
|
//Enter Alarm Menu
|
||||||
void set_alarm_item(){
|
void set_alarm_item(){
|
||||||
if (setItem == 0)
|
if (setItem == 0)
|
||||||
{
|
{
|
||||||
@@ -110,7 +113,7 @@ void set_alarm_item(){
|
|||||||
setItem = 0;
|
setItem = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Get Alarm Info for Display
|
||||||
String get_alarm_string(){
|
String get_alarm_string(){
|
||||||
String alarm_string_1 = "";
|
String alarm_string_1 = "";
|
||||||
String alarm_string_2 = "";
|
String alarm_string_2 = "";
|
||||||
@@ -132,7 +135,7 @@ String get_alarm_string(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//####################################################################################################
|
//####################################################################################################
|
||||||
|
//Test if Alarm is triggerd
|
||||||
bool test_alarm(){
|
bool test_alarm(){
|
||||||
bool A1 = Clock.checkIfAlarm(1);
|
bool A1 = Clock.checkIfAlarm(1);
|
||||||
bool A2 = Clock.checkIfAlarm(2);
|
bool A2 = Clock.checkIfAlarm(2);
|
||||||
@@ -173,7 +176,7 @@ void add_al2_minute(int i){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Save Alarm 1
|
||||||
void set_alarm1(){
|
void set_alarm1(){
|
||||||
int al1h_utc = al1h;
|
int al1h_utc = al1h;
|
||||||
if (summertime_EU(y,M,d,h,1))
|
if (summertime_EU(y,M,d,h,1))
|
||||||
@@ -193,7 +196,7 @@ void set_alarm1(){
|
|||||||
//delay_gui(1000);
|
//delay_gui(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Save Alarm 2
|
||||||
void set_alarm2(){
|
void set_alarm2(){
|
||||||
int al2h_utc = al2h;
|
int al2h_utc = al2h;
|
||||||
if (summertime_EU(y,M,d,h,1))
|
if (summertime_EU(y,M,d,h,1))
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Including the ESP8266 WiFi library
|
// Including the ESP8266 WiFi library and other dependencies
|
||||||
#include <ESP8266HTTPClient.h>
|
#include <ESP8266HTTPClient.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <WiFiClient.h>
|
#include <WiFiClient.h>
|
||||||
@@ -15,14 +15,28 @@
|
|||||||
#include <NTPtimeESP.h> //https://github.com/SensorsIot/NTPtimeESP
|
#include <NTPtimeESP.h> //https://github.com/SensorsIot/NTPtimeESP
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
|
|
||||||
String Hardware = "0.11";
|
//Default Settings
|
||||||
String Software = "0.09";
|
String Hardware = "0.12";
|
||||||
|
String Software = "0.14";
|
||||||
|
|
||||||
String ntp_server = "ntp2.uni-augsburg.de";
|
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
|
// Set web server port number to 80
|
||||||
ESP8266WebServer server(80);
|
ESP8266WebServer server(80);
|
||||||
ESP8266HTTPUpdateServer httpUpdater;
|
ESP8266HTTPUpdateServer httpUpdater;
|
||||||
|
|
||||||
//LED Band Setup
|
//LED Band Setup
|
||||||
#define FASTLED_ESP8266_RAW_PIN_ORDER
|
#define FASTLED_ESP8266_RAW_PIN_ORDER
|
||||||
#include "FastLED.h"
|
#include "FastLED.h"
|
||||||
@@ -33,35 +47,19 @@ ESP8266HTTPUpdateServer httpUpdater;
|
|||||||
#define CLOCK_PIN 13
|
#define CLOCK_PIN 13
|
||||||
// This is an array of leds. One item for each led in your strip.
|
// This is an array of leds. One item for each led in your strip.
|
||||||
CRGB leds[NUM_LEDS];
|
CRGB leds[NUM_LEDS];
|
||||||
|
|
||||||
//RealTimeClock
|
//RealTimeClock
|
||||||
RTClib RTC;
|
RTClib RTC;
|
||||||
DS3231 Clock;
|
DS3231 Clock;
|
||||||
//NTP Setup
|
//NTP Setup
|
||||||
NTPtime NTPch(ntp_server); // Choose server pool as required
|
NTPtime NTPch(ntp_server); // Choose server pool as required
|
||||||
|
|
||||||
//Display
|
//Display
|
||||||
LiquidCrystal_I2C lcd(0x3f, 16, 2);
|
LiquidCrystal_I2C lcd(0x3f, 16, 2);
|
||||||
|
|
||||||
//ConfigData (WiFi Name and Pin-Numbers)
|
//Helpers
|
||||||
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;
|
|
||||||
|
|
||||||
//To know if connected to wifi or not:
|
//To know if connected to wifi or not:
|
||||||
bool wifi_connected = false;
|
bool wifi_connected = false;
|
||||||
|
|
||||||
bool ntp_update = true;
|
|
||||||
int wakeup_time = 10;
|
|
||||||
|
|
||||||
//For Summertime change notification (change alarmtime) this should be saved in the EEPROM!
|
//For Summertime change notification (change alarmtime) this should be saved in the EEPROM!
|
||||||
bool summer = false;
|
bool summer = false;
|
||||||
|
|
||||||
//Alarm Started?
|
//Alarm Started?
|
||||||
bool alarm_started = false;
|
bool alarm_started = false;
|
||||||
long startTime = 0;
|
long startTime = 0;
|
||||||
@@ -75,7 +73,6 @@ int al2m = 0;
|
|||||||
//Alarm run Counter
|
//Alarm run Counter
|
||||||
long time_on = -1;
|
long time_on = -1;
|
||||||
int minutes_sleep = -1;
|
int minutes_sleep = -1;
|
||||||
|
|
||||||
//Current Date and Time from RTC
|
//Current Date and Time from RTC
|
||||||
int h = 0;
|
int h = 0;
|
||||||
int m = 0;
|
int m = 0;
|
||||||
@@ -85,24 +82,24 @@ int M = 0;
|
|||||||
int y = 0;
|
int y = 0;
|
||||||
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
|
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
|
||||||
String dow = "-";
|
String dow = "-";
|
||||||
|
//Current Menu Item
|
||||||
|
|
||||||
int setItem = 0;
|
int setItem = 0;
|
||||||
|
//Display is not updated (for block_gui Secondes)
|
||||||
long block_gui = -1;
|
long block_gui = -1;
|
||||||
|
//Counting Mills
|
||||||
long previousMillis = 0;
|
long previousMillis = 0;
|
||||||
|
|
||||||
|
//If not Connected to Wifi
|
||||||
void configModeCallback (WiFiManager *myWiFiManager) {
|
void configModeCallback (WiFiManager *myWiFiManager) {
|
||||||
//if you used auto generated SSID, print it
|
//if you used auto generated SSID, print it
|
||||||
//write_log(myWiFiManager->getConfigPortalSSID());
|
//write_log(myWiFiManager->getConfigPortalSSID());
|
||||||
display_text("Wifi: Licht","PW: Wecker");
|
display_text("Wifi: Licht","PW: Wecker");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Initial Code
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(10);
|
delay(10);
|
||||||
|
|
||||||
//Setup Display
|
//Setup Display
|
||||||
// Initialise the LCD
|
// Initialise the LCD
|
||||||
lcd.begin(4,5); // sda=0, scl=2
|
lcd.begin(4,5); // sda=0, scl=2
|
||||||
@@ -231,29 +228,47 @@ void setup() {
|
|||||||
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
//Handle web requests
|
||||||
handle_webserver();
|
handle_webserver();
|
||||||
unsigned long currentMillis = millis();
|
unsigned long currentMillis = millis();
|
||||||
unsigned long intervall = currentMillis - previousMillis;
|
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);
|
release_gui(currentMillis);
|
||||||
|
|
||||||
// put your main code here, to run repeatedly:
|
|
||||||
if(setItem == 0){
|
if(setItem == 0){
|
||||||
|
//Run normal
|
||||||
update_Time();
|
update_Time();
|
||||||
run_alarm(currentMillis);
|
run_alarm(currentMillis);
|
||||||
if (block_gui < 0)
|
if (block_gui < 0)
|
||||||
show_current_time(intervall,currentMillis);
|
show_current_time(intervall,currentMillis);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
//Show Menu
|
||||||
show_time_infos(intervall,currentMillis);
|
show_time_infos(intervall,currentMillis);
|
||||||
previousMillis = 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){
|
void show_current_time(long intervall, long currentMillis){
|
||||||
if(intervall > 16000){
|
if(intervall > 16000){
|
||||||
previousMillis = currentMillis;
|
previousMillis = currentMillis;
|
||||||
@@ -45,7 +46,7 @@ void show_time_infos(long intervall, long currentMillis){
|
|||||||
|
|
||||||
|
|
||||||
//####################################################################################################
|
//####################################################################################################
|
||||||
//Setup
|
//Enter Time Menu
|
||||||
void switch_set_item(){
|
void switch_set_item(){
|
||||||
setItem = setItem + 1;
|
setItem = setItem + 1;
|
||||||
if(setItem > 6)
|
if(setItem > 6)
|
||||||
@@ -119,7 +120,7 @@ void update_Time(){
|
|||||||
void display_year(int Day, int Month, int Year){
|
void display_year(int Day, int Month, int Year){
|
||||||
display_text("Jahr", String(Year));
|
display_text("Jahr", String(Year));
|
||||||
}
|
}
|
||||||
|
int current_Sec = 0;
|
||||||
void display_time(int Stunde, int Minute, int Sekunde){
|
void display_time(int Stunde, int Minute, int Sekunde){
|
||||||
String Min = String(Minute);
|
String Min = String(Minute);
|
||||||
String Stu = String(Stunde);
|
String Stu = String(Stunde);
|
||||||
@@ -167,9 +168,19 @@ void display_time(int Stunde, int Minute, int Sekunde){
|
|||||||
/*else if (Sekunde % 2 == 0){
|
/*else if (Sekunde % 2 == 0){
|
||||||
display_text(Stu + ":" + Min, get_alarm_string());
|
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{
|
else{
|
||||||
display_text(Stu + ":" + Min + ":" + Sek, get_alarm_string());
|
display_text(Stu + ":" + Min + ":" + Sek, get_alarm_string());
|
||||||
}
|
}
|
||||||
|
current_Sec = Sekunde;
|
||||||
}
|
}
|
||||||
|
|
||||||
void display_date(int Day, int Month, int Year){
|
void display_date(int Day, int Month, int Year){
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
//Start Wakeup sound
|
||||||
void run_wake_up_beep(long currentMillis){
|
void run_wake_up_beep(long currentMillis){
|
||||||
if (alarm_started == true)
|
if (alarm_started == true)
|
||||||
{
|
{
|
||||||
@@ -10,10 +11,12 @@ void run_wake_up_beep(long currentMillis){
|
|||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Stop Sound
|
||||||
void stop_alarm_beep(){
|
void stop_alarm_beep(){
|
||||||
beepOff();
|
beepOff();
|
||||||
}
|
}
|
||||||
|
//############################################################################################
|
||||||
|
//Helpers
|
||||||
|
|
||||||
void toggle_alarm_beep(){
|
void toggle_alarm_beep(){
|
||||||
int currentState = digitalRead(outBeep);
|
int currentState = digitalRead(outBeep);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
//Helpers
|
||||||
String current_string = "";
|
String current_string = "";
|
||||||
|
|
||||||
|
//Display Text
|
||||||
void display_text(String text1, String text2){
|
void display_text(String text1, String text2){
|
||||||
if (current_string != text1 + text2){
|
if (current_string != text1 + text2){
|
||||||
//write_log("Display:");
|
//write_log("Display:");
|
||||||
@@ -18,11 +19,11 @@ void display_text(String text1, String text2){
|
|||||||
current_string = text1 + text2;
|
current_string = text1 + text2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Calculate space
|
||||||
int freespace(String text){
|
int freespace(String text){
|
||||||
if (text.length() > 14)
|
if (text.length() > 14)
|
||||||
{
|
{
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
int freespace = 16 - text.length();
|
int freespace = 16 - text.length();
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ void show_green(){
|
|||||||
FastLED.show();
|
FastLED.show();
|
||||||
write_log("Light: GREEN");
|
write_log("Light: GREEN");
|
||||||
}
|
}
|
||||||
|
//Set LED Color to RGB Value
|
||||||
void set_color(int r, int g, int b){
|
void set_color(int r, int g, int b){
|
||||||
FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RBG>(leds, NUM_LEDS);
|
FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RBG>(leds, NUM_LEDS);
|
||||||
for(int i=0; i < NUM_LEDS; i = i+1 )
|
for(int i=0; i < NUM_LEDS; i = i+1 )
|
||||||
@@ -46,7 +46,7 @@ void set_color(int r, int g, int b){
|
|||||||
//write_log(String(b));
|
//write_log(String(b));
|
||||||
//write_log(String(g));
|
//write_log(String(g));
|
||||||
}
|
}
|
||||||
|
//Run Color movement for Alarm
|
||||||
bool run_wake_up(long currentMillis){
|
bool run_wake_up(long currentMillis){
|
||||||
if (alarm_started == true)
|
if (alarm_started == true)
|
||||||
{
|
{
|
||||||
@@ -84,7 +84,7 @@ bool run_wake_up(long currentMillis){
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
//Toggle Light Full/Off
|
||||||
void switch_lamp(){
|
void switch_lamp(){
|
||||||
if(lamp_on == false){
|
if(lamp_on == false){
|
||||||
lamp_on = true;
|
lamp_on = true;
|
||||||
@@ -95,7 +95,7 @@ void switch_lamp(){
|
|||||||
show_black();
|
show_black();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Start Alarm Light
|
||||||
void start_wake_light(long currentMillis){
|
void start_wake_light(long currentMillis){
|
||||||
if (alarm_started == false)
|
if (alarm_started == false)
|
||||||
{
|
{
|
||||||
@@ -104,7 +104,7 @@ void start_wake_light(long currentMillis){
|
|||||||
set_color(30, 0, 0);
|
set_color(30, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Turn of Alarm Light
|
||||||
void stop_wake_light(){
|
void stop_wake_light(){
|
||||||
if (alarm_started == true)
|
if (alarm_started == true)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
|
//Test if button pressed
|
||||||
void test_pin(){
|
void test_pin(){
|
||||||
handle_Time_switch();
|
handle_Time_switch();
|
||||||
handle_Set_switch();
|
handle_Set_switch();
|
||||||
handle_Alarm_switch();
|
handle_Alarm_switch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//If Alarm switch pressed
|
||||||
void handle_Alarm_switch(){
|
void handle_Alarm_switch(){
|
||||||
int state = digitalRead(pinAlarm);
|
int state = digitalRead(pinAlarm);
|
||||||
if(state == LOW && setItem == 0) {
|
if(state == LOW && setItem == 0) {
|
||||||
@@ -19,9 +20,15 @@ void handle_Alarm_switch(){
|
|||||||
{
|
{
|
||||||
stop_alarm();
|
stop_alarm();
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
//Delete Message
|
||||||
|
if(message_text != ""){
|
||||||
|
message_text = "";
|
||||||
|
}
|
||||||
else{
|
else{
|
||||||
switch_alarm_mode();
|
switch_alarm_mode();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
delay(200);
|
delay(200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,7 +38,7 @@ void handle_Alarm_switch(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//If Set switch pressed
|
||||||
void handle_Set_switch(){
|
void handle_Set_switch(){
|
||||||
int state = digitalRead(pinSet);
|
int state = digitalRead(pinSet);
|
||||||
if (state == LOW && setItem > 0){
|
if (state == LOW && setItem > 0){
|
||||||
@@ -39,11 +46,21 @@ void handle_Set_switch(){
|
|||||||
delay(200);
|
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();
|
switch_lamp();
|
||||||
delay(200);
|
delay(200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//If Time switch pressed
|
||||||
void handle_Time_switch(){
|
void handle_Time_switch(){
|
||||||
int state = digitalRead(pinTime);
|
int state = digitalRead(pinTime);
|
||||||
if(state == LOW && setItem == 0) {
|
if(state == LOW && setItem == 0) {
|
||||||
@@ -64,24 +81,27 @@ void handle_Time_switch(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Helper for long-press
|
||||||
int get_pin_delay(int pin){
|
int get_pin_delay(int pin){
|
||||||
int state = digitalRead(pin);
|
int state = digitalRead(pin);
|
||||||
int delay_count = 0;
|
int delay_count = 0;
|
||||||
while(state == LOW && delay_count < 11)
|
while(state == LOW && delay_count < 11)
|
||||||
{
|
{
|
||||||
state = digitalRead(pin);
|
state = digitalRead(pin);
|
||||||
|
update_display();
|
||||||
delay(100);
|
delay(100);
|
||||||
delay_count = delay_count +1;
|
delay_count = delay_count +1;
|
||||||
}
|
}
|
||||||
return delay_count;
|
return delay_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Helper for long-press
|
||||||
void wait_to_release(int pin){
|
void wait_to_release(int pin){
|
||||||
int state = digitalRead(pin);
|
int state = digitalRead(pin);
|
||||||
while(state == LOW)
|
while(state == LOW)
|
||||||
{
|
{
|
||||||
state = digitalRead(pin);
|
state = digitalRead(pin);
|
||||||
|
update_display();
|
||||||
delay(100);
|
delay(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
//Helpers
|
||||||
String logfile = "";
|
String logfile = "";
|
||||||
//Webserver
|
//Webserver
|
||||||
//###################################################################################
|
//###################################################################################
|
||||||
@@ -52,6 +53,7 @@ void handleArgs(){
|
|||||||
write_eeprom();
|
write_eeprom();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
redirect();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (server.argName(i) == "ntp_server"){
|
else if (server.argName(i) == "ntp_server"){
|
||||||
@@ -59,6 +61,7 @@ void handleArgs(){
|
|||||||
ntp_server = server.arg(i);
|
ntp_server = server.arg(i);
|
||||||
write_eeprom();
|
write_eeprom();
|
||||||
}
|
}
|
||||||
|
redirect();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if(server.argName(i) == "wakeup_time"){
|
else if(server.argName(i) == "wakeup_time"){
|
||||||
@@ -66,6 +69,7 @@ void handleArgs(){
|
|||||||
wakeup_time = server.arg(i).toInt();
|
wakeup_time = server.arg(i).toInt();
|
||||||
write_eeprom();
|
write_eeprom();
|
||||||
}
|
}
|
||||||
|
redirect();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if(server.argName(i) == "a1"){
|
else if(server.argName(i) == "a1"){
|
||||||
@@ -75,6 +79,7 @@ void handleArgs(){
|
|||||||
else if (server.arg(i) == "false"){
|
else if (server.arg(i) == "false"){
|
||||||
Clock.turnOffAlarm(1);
|
Clock.turnOffAlarm(1);
|
||||||
}
|
}
|
||||||
|
redirect();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if(server.argName(i) == "a2"){
|
else if(server.argName(i) == "a2"){
|
||||||
@@ -84,18 +89,28 @@ void handleArgs(){
|
|||||||
else if (server.arg(i) == "false"){
|
else if (server.arg(i) == "false"){
|
||||||
Clock.turnOffAlarm(2);
|
Clock.turnOffAlarm(2);
|
||||||
}
|
}
|
||||||
|
redirect();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if(server.argName(i) == "al1h" && server.argName(i +1) == "al1m"){
|
else if(server.argName(i) == "al1h" && server.argName(i +1) == "al1m"){
|
||||||
al1h = server.arg(i).toInt();
|
al1h = server.arg(i).toInt();
|
||||||
al1m = server.arg(i+1).toInt();
|
al1m = server.arg(i+1).toInt();
|
||||||
set_alarm1();
|
set_alarm1();
|
||||||
|
redirect();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if(server.argName(i) == "al2h" && server.argName(i +1) == "al2m"){
|
else if(server.argName(i) == "al2h" && server.argName(i +1) == "al2m"){
|
||||||
al2h = server.arg(i).toInt();
|
al2h = server.arg(i).toInt();
|
||||||
al2m = server.arg(i+1).toInt();
|
al2m = server.arg(i+1).toInt();
|
||||||
set_alarm2();
|
set_alarm2();
|
||||||
|
redirect();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (server.argName(i) == "news"){
|
||||||
|
if (server.arg(i) != ""){
|
||||||
|
message_text = server.arg(i);
|
||||||
|
}
|
||||||
|
redirect();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if(server.argName(i) == "reset" && server.arg(i) == "true"){
|
else if(server.argName(i) == "reset" && server.arg(i) == "true"){
|
||||||
@@ -126,9 +141,10 @@ void print_website(){
|
|||||||
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 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 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 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 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 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><br><br><a href=\"https://homemanager.mittring-mering.de/git/chm/Licht_Wecker\">Weitere Informationen</a><br><br><a href=\"http://christian.mittring-mering.de/index.php?page=kontakt\">Support</a>";
|
||||||
String Body = card_start + Alarm + card_end + card_start + Zeit + card_end + card_start + NTP + card_end + card_start + Reboot + card_end;
|
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);
|
server.send(200, "text/html", Header + Body + Footer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,6 +154,11 @@ void print_reset(){
|
|||||||
delay(500);
|
delay(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void redirect(){
|
||||||
|
String redirect = "<head><meta http-equiv=\"refresh\" content=\"0; URL=/\" /></head>";
|
||||||
|
server.send(200, "text/html", redirect);
|
||||||
|
delay(50);
|
||||||
|
}
|
||||||
//Helpers
|
//Helpers
|
||||||
//####################################################################################
|
//####################################################################################
|
||||||
String getBoolString(bool value){
|
String getBoolString(bool value){
|
||||||
|
|||||||
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
|
||||||
|
|
||||||
Licht Wecker für die Bradls
|
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