using open-drain for power on signal, added option for sleep time.
This commit is contained in:
parent
3cd3051149
commit
b0e9dfea36
|
@ -13,9 +13,10 @@ cp src/secrets.h.template src/secrets.h
|
||||||
nano src/secrets.h
|
nano src/secrets.h
|
||||||
```
|
```
|
||||||
If you wish to change GPIO pins, please, do it in ``src/src.info``
|
If you wish to change GPIO pins, please, do it in ``src/src.info``
|
||||||
|
|
||||||
Flash the sketch in your board
|
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)
|
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)
|
||||||
3. Connect pin WAKE_PIN to power pin on your motherboard
|
3. Connect pin WAKE_PIN to power pin on your motherboard
|
||||||
4. Connect GND to motherboard's ground.
|
4. Connect GND to motherboard's ground.
|
||||||
5. Make sure that the board has some power supply (usually you want to use 18650 Li-ion batteries) to be online when the power is down.
|
5. Make sure that the board has some power supply (usually you want to use 18650 Li-ion batteries) to be online when the power is down.
|
||||||
|
|
18
src/src.ino
18
src/src.ino
|
@ -10,13 +10,13 @@
|
||||||
|
|
||||||
#define STATUS_PIN D5
|
#define STATUS_PIN D5
|
||||||
#define WAKE_PIN D6
|
#define WAKE_PIN D6
|
||||||
|
#define SLEEP_TIME 5 // seconds
|
||||||
|
|
||||||
static bool wifi_lost = false;
|
static bool wifi_lost = false;
|
||||||
static bool server_is_off = false;
|
static bool server_is_off = false;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.disconnect();
|
WiFi.disconnect();
|
||||||
|
@ -24,16 +24,16 @@ void setup() {
|
||||||
Serial.println("Connecting to a Wi-Fi network");
|
Serial.println("Connecting to a Wi-Fi network");
|
||||||
|
|
||||||
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
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");
|
Serial.println("Wi-Fi connected");
|
||||||
|
|
||||||
pinMode(STATUS_PIN, INPUT);
|
pinMode(STATUS_PIN, INPUT);
|
||||||
pinMode(WAKE_PIN, OUTPUT);
|
pinMode(WAKE_PIN, INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
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;
|
server_is_off = digitalRead(STATUS_PIN) != HIGH;
|
||||||
|
|
||||||
Serial.println("Checking the status");
|
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.");
|
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)
|
// Wait untill Wi-Fi is available (i.e. the power is back)
|
||||||
while (WiFi.status() != WL_CONNECTED) delay(100);
|
while (WiFi.status() != WL_CONNECTED) delay(100);
|
||||||
digitalWrite(WAKE_PIN, HIGH);
|
pinMode(WAKE_PIN, OUTPUT);
|
||||||
delay(100);
|
delay(100);
|
||||||
digitalWrite(WAKE_PIN, LOW);
|
pinMode(WAKE_PIN, INPUT);
|
||||||
Serial.println("Signal sent");
|
Serial.println("Signal sent");
|
||||||
} else {
|
} 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