1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #include <ESP8266WiFi.h>
- #include <WiFiManager.h>
- #include <ArduinoJson.h>
- #include <LittleFS.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);
- #include <ESP8266mDNS.h>
- String MDNS_NAME = "espwol";
- 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");
-
- if (!MDNS.begin(MDNS_NAME)){
- Serial.println("[ERROR] mDNS start failed. Skipping.");
- }else{
- Serial.println("[INFO] mDNS started. Connect to your webstick using http://" + MDNS_NAME + ".local");
- MDNS.addService("http", "tcp", 80);
- }
-
-
- registerServeEndpoints();
- server.begin();
- Serial.println("[INFO] HTTP server started");
- }
- void loop() {
- server.handleClient();
- handleCustomButtonEvents();
- Serial.print(hddLedState);
- Serial.print(",");
- Serial.println(pwrLedState);
- }
|