-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sunrize_Alarm_Clock_v2.ino
91 lines (67 loc) · 1.96 KB
/
Sunrize_Alarm_Clock_v2.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// #include "DHT.h"
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266WiFiMulti.h>
#include "stdlib.h"
#include <Arduino.h>
ESP8266WebServer server(80);
ESP8266WiFiMulti wifiMulti;
#define PIN_PWM D1
#define PIN_DHT D7
#define PIN_BTN D3
//DHT dht(PIN_DHT, DHT11);
/**
* SUNRIZE Version 2
* Réveil en lumière Contrôlé par l'extérieur
*/
//bool btn_active = false;
bool progressive = false; // allumage progressif en cours ?
int progressive_speed = 1000; // millisecondes par incrément
int progressive_step = 25; // incréments par pas
int lastStep = 0;
// ex : augmentation progressive de la lumière de 10 en 10 tous les 20 secondes : progressive_speed = 20, progressive_step = 10
int lastValue = 0;
const char* host = "esp8266-sunrize";
const char* ssid = "***REMOVED***";
const char* password = "***REMOVED***";
void setup(void) {
Serial.begin(115200);
initDHT();
// pinMode(LED_BUILTIN, OUTPUT);
pinMode(PIN_PWM, OUTPUT);
digitalWrite(PIN_PWM, LOW);
pinMode(PIN_BTN, INPUT);
Serial.println("\nBooting Sunrize Server...");
delay(100);
if( !digitalRead( PIN_BTN ) ){
checkReset();
}
WiFi.mode(WIFI_STA);
// WiFi.begin(ssid, password);
wifiMulti.addAP("***REMOVED***", "***REMOVED***");
wifiMulti.addAP("egarden", "r00tG4rd3n");
int connectAttempt = 0, maxAttempts = 10;
while( wifiMulti.run() != WL_CONNECTED ){
Serial.println("Trying to connect, attempt " + String(++connectAttempt) + "/" + String(maxAttempts));
delay(750);
}
if (wifiMulti.run() == WL_CONNECTED) {
routesSetup();
server.begin();
Serial.printf("Ready! Open http://%s.local or ", host);
Serial.println(WiFi.localIP());
initNTP();
} else {
Serial.println("WiFi Failed, rebooting...");
ESP.restart();
}
}
void loop(void) {
readCommand();
server.handleClient();
// updateStatus();
// Serial.println("Status : " + String(status));
handleButton();
handleOutput();
}