123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- #include <ESP8266WiFi.h>
- #include <WiFiManager.h>
- #include <ESP8266mDNS.h>
- #include <ArduinoJson.h>
- #include <LittleFS.h>
- #include <WiFiUdp.h>
- #include <WakeOnLan.h>
- #define BTN_INPUT D0
- #define BTN_LED D7
- #define PWR_BTN D6
- #define RST_BTN D5
- #define HDD_LED D2
- #define PWR_LED D1
- WiFiManager wifiManager;
- ESP8266WebServer server(80);
- WiFiUDP UDP;
- WakeOnLan WOL(UDP);
- #include <ESP8266mDNS.h>
- String MDNS_NAME = "espwol";
- const char* DB_PATH = "/conf.txt";
- bool hddLedState = 0;
- bool pwrLedState = 0;
- bool customBtnPressed = true;
- int val = 0;
- void handleRoot();
- void handleNotFound();
- void registerServeEndpoints();
- void handleCustomButtonEvents();
- void setup() {
- Serial.begin(115200);
- delay(100);
-
-
- wifiManager.setClass("invert");
- wifiManager.autoConnect("ESP-WakeOnLan");
- Serial.println("[INFO] Connected to WiFi!");
-
- pinMode(PWR_LED, INPUT);
- pinMode(HDD_LED, INPUT);
- pinMode(PWR_BTN, OUTPUT);
- pinMode(RST_BTN, OUTPUT);
- pinMode(BTN_INPUT, INPUT);
- pinMode(BTN_LED, OUTPUT);
-
- if(!LittleFS.begin()){
- Serial.println("[ERROR] An Error has occurred while mounting LittleFS");
- return;
- }
- Serial.println("[INFO] LittleFS started");
-
- String deviceMAC = WiFi.macAddress();
- deviceMAC.replace(":", "");
- MDNS_NAME = MDNS_NAME + "-" + deviceMAC;
- if (!MDNS.begin(MDNS_NAME)){
- Serial.println("[ERROR] mDNS start failed. Skipping.");
- }else{
- Serial.println("[INFO] mDNS started. Connect to your device using http://" + MDNS_NAME + ".local");
- MDNS.addService("http", "tcp", 80);
- }
-
- WOL.setRepeat(3, 100);
- WOL.calculateBroadcastAddress(WiFi.localIP(), WiFi.subnetMask());
-
-
- registerServeEndpoints();
- server.begin();
- Serial.println("[INFO] HTTP server started");
- }
- void loop() {
- server.handleClient();
- handleCustomButtonEvents();
- updateFrontPanelLEDStatus();
- MDNS.update();
- }
|