1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- /*
- 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 <WiFiManager.h>
- #include <ArduinoJson.h>
- #include <ESP8266WiFi.h>
- #include <ESP8266mDNS.h>
- #include <ESP8266WebServer.h>
- #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();
- }
|