initial commit
This commit is contained in:
parent
2c16e6a71d
commit
3cd3051149
|
@ -32,3 +32,6 @@
|
||||||
*.out
|
*.out
|
||||||
*.app
|
*.app
|
||||||
|
|
||||||
|
# Secrets
|
||||||
|
|
||||||
|
src/secrets.h
|
||||||
|
|
20
README.md
20
README.md
|
@ -1,3 +1,21 @@
|
||||||
# deadmans_hand
|
# deadmans_hand
|
||||||
|
|
||||||
Simple program for ESP-32 to power up my server in case of power cut
|
Simple program for ESP-32 to power up my server in case of power cut.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
**/!\ WARNING /!\ The author (leca) is not responsible for any damage you've caused to your hardware with your own hand /!\ WARNING /!\\**
|
||||||
|
1. Set up the sketch
|
||||||
|
```bash
|
||||||
|
git clone https://git.foxarmy.org/leca/deadmans_hand
|
||||||
|
cd deadmans_hand
|
||||||
|
cp src/secrets.h.template src/secrets.h
|
||||||
|
# Open the file with your favorite editor and insert Wi-Fi SSID and password.
|
||||||
|
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)
|
||||||
|
3. Connect pin WAKE_PIN to power pin on your motherboard
|
||||||
|
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.
|
|
@ -0,0 +1,8 @@
|
||||||
|
/*
|
||||||
|
* This is a template for secrets.
|
||||||
|
* Copy this file as secrets.h and
|
||||||
|
* adjust it to your needs
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define WIFI_SSID "your_wifi_ssid"
|
||||||
|
#define WIFI_PASSWORD "your_wifi_password"
|
|
@ -0,0 +1,58 @@
|
||||||
|
#include "secrets.h"
|
||||||
|
|
||||||
|
#if defined(ARDUINO_ARCH_ESP32) || defined(ESP32)
|
||||||
|
# include <WiFi.h>
|
||||||
|
#elif defined(ARDUINO_ARCH_ESP8266) || defined(ESP8266)
|
||||||
|
# include <ESP8266WiFi.h>
|
||||||
|
#else
|
||||||
|
# error "Unsupported board, please contact the developer"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define STATUS_PIN D5
|
||||||
|
#define WAKE_PIN D6
|
||||||
|
|
||||||
|
static bool wifi_lost = false;
|
||||||
|
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);
|
||||||
|
|
||||||
|
Serial.println("Wi-Fi connected");
|
||||||
|
|
||||||
|
pinMode(STATUS_PIN, INPUT);
|
||||||
|
pinMode(WAKE_PIN, OUTPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
wifi_lost = WiFi.status() == 1 || WiFi.status() == 5 || WiFi.status() == 7;
|
||||||
|
server_is_off = digitalRead(STATUS_PIN) != HIGH;
|
||||||
|
|
||||||
|
Serial.println("Checking the status");
|
||||||
|
Serial.print("WiFi lost: ");
|
||||||
|
Serial.println(wifi_lost? "true" : "false");
|
||||||
|
Serial.print("Server is off: ");
|
||||||
|
Serial.println(server_is_off? "true" : "false");
|
||||||
|
|
||||||
|
if (wifi_lost && server_is_off) {
|
||||||
|
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);
|
||||||
|
delay(100);
|
||||||
|
digitalWrite(WAKE_PIN, LOW);
|
||||||
|
Serial.println("Signal sent");
|
||||||
|
} else {
|
||||||
|
Serial.println("Everyting's okay, sleeping 5 secs");
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(5000);
|
||||||
|
}
|
Loading…
Reference in New Issue