/* Home Dynamic System v3 4-way relays Hardware reference design Author: tobychui Compile with Wemos D1 mini board manager This project require LittleFS to store the device configuration json file. Install the LittleFS Uploader plugin here https://github.com/earlephilhower/arduino-esp8266littlefs-plugin */ #include #include #include #include #include #include "LittleFS.h" // Device Configs, required by HDSv3 #define DEVICE_NAME "hds_4xRelay" //The name of this IoT device #define LISTENING_PORT 12110 //The port where this IoT device listen String deviceUUID = ""; //Device UUID is generated base on devcie MAC address // Output shift register pints const int RELAY_1 = D0; const int RELAY_2 = D5; const int RELAY_3 = D6; const int RELAY_4 = D7; bool relayStatus[4] = {false, false, false, false}; //WiFi Related WiFiManager wifiManager; ESP8266WebServer server(LISTENING_PORT); //Update relay status update the relay physical state base on relay status array void updateRelayStatus(){ if (relayStatus[0]){ digitalWrite(RELAY_1, HIGH); }else{ digitalWrite(RELAY_1, LOW); } if (relayStatus[1]){ digitalWrite(RELAY_2, HIGH); }else{ digitalWrite(RELAY_2, LOW); } if (relayStatus[2]){ digitalWrite(RELAY_3, HIGH); }else{ digitalWrite(RELAY_3, LOW); } if (relayStatus[3]){ digitalWrite(RELAY_4, HIGH); }else{ digitalWrite(RELAY_4, LOW); } } void setup() { Serial.begin(115200); //Load device UUID deviceUUID = WiFi.macAddress(); deviceUUID.replace(":", "-"); //Initialize the pins. Set all to low pinMode(RELAY_1, OUTPUT); digitalWrite(RELAY_1, LOW); pinMode(RELAY_2, OUTPUT); digitalWrite(RELAY_2, LOW); pinMode(RELAY_3, OUTPUT); digitalWrite(RELAY_3, LOW); pinMode(RELAY_4, OUTPUT); digitalWrite(RELAY_4, LOW); //Start HDSv2 services initHds3Services(); } void loop() { server.handleClient(); MDNS.update(); }