using open-drain for power on signal, added option for sleep time.
This commit is contained in:
parent
3cd3051149
commit
b0e9dfea36
|
@ -13,6 +13,7 @@ cp src/secrets.h.template src/secrets.h
|
|||
nano src/secrets.h
|
||||
```
|
||||
If you wish to change GPIO pins, please, do it in ``src/src.info``
|
||||
|
||||
Flash the sketch in your board
|
||||
|
||||
2. Connect pin STATUS_PIN to anything in your server that has voltage when the server is running (usually some led on the forward panel)
|
||||
|
|
18
src/src.ino
18
src/src.ino
|
@ -10,6 +10,7 @@
|
|||
|
||||
#define STATUS_PIN D5
|
||||
#define WAKE_PIN D6
|
||||
#define SLEEP_TIME 5 // seconds
|
||||
|
||||
static bool wifi_lost = false;
|
||||
static bool server_is_off = false;
|
||||
|
@ -17,23 +18,22 @@ static bool server_is_off = false;
|
|||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect();
|
||||
|
||||
Serial.println("Connecting to a Wi-Fi network");
|
||||
|
||||
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||||
while (WiFi.status() == WL_IDLE_STATUS) delay(100);
|
||||
while (WiFi.status() == WL_IDLE_STATUS) delay(1000);
|
||||
|
||||
Serial.println("Wi-Fi connected");
|
||||
|
||||
pinMode(STATUS_PIN, INPUT);
|
||||
pinMode(WAKE_PIN, OUTPUT);
|
||||
pinMode(WAKE_PIN, INPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
wifi_lost = WiFi.status() == 1 || WiFi.status() == 5 || WiFi.status() == 7;
|
||||
wifi_lost = WiFi.status() == WL_NO_SSID_AVAIL || WiFi.status() == WL_CONNECTION_LOST || WiFi.status() == 7;
|
||||
server_is_off = digitalRead(STATUS_PIN) != HIGH;
|
||||
|
||||
Serial.println("Checking the status");
|
||||
|
@ -46,13 +46,15 @@ void loop() {
|
|||
Serial.println("The power seems to be down. Waiting for the power to restore and send turn on signal to the server.");
|
||||
// Wait untill Wi-Fi is available (i.e. the power is back)
|
||||
while (WiFi.status() != WL_CONNECTED) delay(100);
|
||||
digitalWrite(WAKE_PIN, HIGH);
|
||||
pinMode(WAKE_PIN, OUTPUT);
|
||||
delay(100);
|
||||
digitalWrite(WAKE_PIN, LOW);
|
||||
pinMode(WAKE_PIN, INPUT);
|
||||
Serial.println("Signal sent");
|
||||
} else {
|
||||
Serial.println("Everyting's okay, sleeping 5 secs");
|
||||
Serial.print("Everyting's okay, sleeping ");
|
||||
Serial.print(SLEEP_TIME);
|
||||
Serial.println(" secs.");
|
||||
}
|
||||
|
||||
delay(5000);
|
||||
delay(SLEEP_TIME * 1000);
|
||||
}
|
Loading…
Reference in New Issue