From dc5d5e7f0b9af37c5e36f2c142cac14003da651d Mon Sep 17 00:00:00 2001 From: AP <43411221+KamadoTanjiro-beep@users.noreply.github.com> Date: Sun, 9 Jun 2024 11:09:44 +0530 Subject: [PATCH] Update smartAquariumProto.ino --- smartAquariumProto/smartAquariumProto.ino | 430 ++++++++++++---------- 1 file changed, 230 insertions(+), 200 deletions(-) diff --git a/smartAquariumProto/smartAquariumProto.ino b/smartAquariumProto/smartAquariumProto.ino index 2531ce8..f00ea86 100644 --- a/smartAquariumProto/smartAquariumProto.ino +++ b/smartAquariumProto/smartAquariumProto.ino @@ -197,7 +197,7 @@ unsigned long lastTime1 = 0; const long timerDelay1 = 5000; // check wifi status every 900 m.seconds unsigned long lastTime2 = 0; -const long timerDelay2 = 1000; // send time every 1000 m.seconds +const long timerDelay2 = 800; // send time every 1000 m.seconds // utc offset according to India, please change according to your location const long utcOffsetInSeconds = 19800; @@ -313,9 +313,9 @@ void relayStatusPrinter(); // status flags - -byte OLEDConfig = 0; // Config=1 means auto (based on timer),Config=0 means Manual -byte OLEDStatus = 1, updateTime = 0; // Status = 1 means OLED DISPLAY is ON and reversed for 0 (works only if Config is 0) + +byte OLEDConfig = 0; // Config=1 means auto (based on timer),Config=0 means Manual +byte OLEDStatus = 1, updateTime = 0; // Status = 1 means OLED DISPLAY is ON and reversed for 0 (works only if Config is 0) // oled display off at night timings (needs improvement) #define OLED_OFF 9 // Hour only. In 24 hours mode i.e. 23 for 11 pm @@ -328,7 +328,7 @@ const byte relayPin3 = 13; const byte relayPin4 = 14; // Name (to be shown on webserver) as per relay gpio pins -const String relay1Name = "Filter 1"; +const String relay1Name = "Not Available"; const String relay2Name = "Surface Skimmer"; const String relay3Name = "Filter 2"; const String relay4Name = "Light"; @@ -344,12 +344,12 @@ const String relay4Name = "Light"; // Relay Timing and definitions typedef struct relaystruct { - int onTime,offTime,count; + int onTime, offTime, count; byte config, autoTimer; bool activate; - byte flag,powerSave,psAlt; + byte flag, powerSave, psAlt; String relayState; - unsigned long lastAutoTimer,autoTimerDelay,pslastTime,psTimerDelay,psTimerDelayOn,psTimerDelayOff; + unsigned long lastAutoTimer, autoTimerDelay, pslastTime, psTimerDelay, psTimerDelayOn, psTimerDelayOff; } struct_relay; // timer settings for autotimers @@ -372,30 +372,29 @@ tenth param, relayState is used in webserver to show ON or OFF, Below are CONFIGURATION of relays*/ -struct_relay relay1={1200,1900,1,0,0,false,1,0,2,"ON",0,0,0,0,600000,600000}; -struct_relay relay2={1200,1900,2,2,0,false,0,1,2,"OFF",0,0,0,0,600000,1800000}; -struct_relay relay3={1200,1900,3,0,0,false,1,0,2,"ON",0,0,0,0,600000,600000}; //I am using this for filter, which is crucial thing, hence by default it's ON and in Manual Mode -struct_relay relay4={800,1800,4,1,0,true,0,0,2,"OFF",0,0,0,0,600000,600000}; +struct_relay relay1 = { 1200, 1900, 1, 0, 0, false, 1, 0, 2, "OFF", 0, 0, 0, 0, 600000, 600000 }; +struct_relay relay2 = { 1200, 1900, 2, 2, 0, false, 0, 1, 2, "OFF", 0, 0, 0, 0, 600000, 1800000 }; +struct_relay relay3 = { 1200, 1900, 3, 0, 0, false, 1, 0, 2, "ON", 0, 0, 0, 0, 600000, 600000 }; //I am using this for filter, which is crucial thing, hence by default it's ON and in Manual Mode +struct_relay relay4 = { 900, 1500, 4, 1, 0, true, 0, 0, 2, "OFF", 0, 0, 0, 0, 600000, 600000 }; /* Checks configuration and turns on the relays or reads config from SPIFF(to be implemented later) Returns nothing. */ -void relayInitialize() -{ - if (relay1.flag==1) { +void relayInitialize() { + if (relay1.flag == 1) { RELAY1ON; relay1.relayState = "ON"; } - if (relay2.flag==1) { + if (relay2.flag == 1) { RELAY2ON; relay2.relayState = "ON"; } - if (relay3.flag==1) { + if (relay3.flag == 1) { RELAY3ON; relay3.relayState = "ON"; } - if (relay4.flag==1) { + if (relay4.flag == 1) { RELAY4ON; relay4.relayState = "ON"; } @@ -403,7 +402,7 @@ void relayInitialize() // REMOVE this section if you don't want to broadcast time data to other ESPs ##################################################### // ESPNOW: REPLACE WITH RECEIVER MAC Address -uint8_t broadcastAddress[] = { 0xF4, 0xCF, 0xA2, 0xF0, 0x0A, 0xE3 }; +uint8_t broadcastAddress[] = { 0xE8, 0x9F, 0x6D, 0x93, 0x15, 0x0D }; //E8:9F:6D:93:15:0D // Structure example to send data // Must match the receiver structure typedef struct struct_message { @@ -442,18 +441,18 @@ String processor(const String &var) { buttons += ""; } else if (relay1.config == 1) buttons += ""; - else if (relay1.config == 2) - { + else if (relay1.config == 2) { String timeOn; String timeOff; - byte minOn = (relay1.psTimerDelayOn/1000)/60; - byte minOff = (relay1.psTimerDelayOff/1000)/60; - timeOn=String(minOn)+" min"; - timeOff=String(minOff)+" min"; + byte minOn = (relay1.psTimerDelayOn / 1000) / 60; + byte minOff = (relay1.psTimerDelayOff / 1000) / 60; + timeOn = String(minOn) + " min"; + timeOff = String(minOff) + " min"; buttons += "\
\
\ -
ON: "+timeOn+"\ +
ON: " + + timeOn + "\ \
\ -
OFF: "+timeOff+"\ +
OFF: " + + timeOff + "\ \ \ \ @@ -553,7 +551,8 @@ String processor(const String &var) { \
\ -
OFF: "+timeOff+"\ +
OFF: " + + timeOff + "\ \ \ \ @@ -646,7 +641,8 @@ String processor(const String &var) { \
\ -
OFF: "+timeOff+"\ +
OFF: " + + timeOff + "\ "; } else buttons += ""; - } else if (relay4.config == 1) - buttons += ""; - else if (relay4.config == 2) - { + } else if (relay4.config == 1) { String timeOn; String timeOff; - byte minOn = (relay4.psTimerDelayOn/1000)/60; - byte minOff = (relay4.psTimerDelayOff/1000)/60; - timeOn=String(minOn)+" min"; - timeOff=String(minOff)+" min"; + + int hour = (relay4.onTime) / 100; + int min = (relay4.onTime) % 100; + if (hour < 10) + timeOn = "0" + String(hour); + else + timeOn = String(hour); + + if (min < 10) + timeOn = timeOn + ":" + "0" + String(min); + else + timeOn = timeOn + ":" + String(min); + + hour = (relay4.offTime) / 100; + min = (relay4.offTime) % 100; + if (hour < 10) + timeOff = "0" + String(hour); + else + timeOff = String(hour); + + if (min < 10) + timeOff = timeOff + ":" + "0" + String(min); + else + timeOff = timeOff + ":" + String(min); + + buttons += "\ +
\ +
\ +
ON: " + + timeOn + "\ + \ + \ +
\ +
OFF: " + + timeOff + "\ + \ + \ +
\ +
"; + } else if (relay4.config == 2) { + String timeOn; + String timeOff; + byte minOn = (relay4.psTimerDelayOn / 1000) / 60; + byte minOff = (relay4.psTimerDelayOff / 1000) / 60; + timeOn = String(minOn) + " min"; + timeOff = String(minOff) + " min"; buttons += "\
\
\ -
ON: "+timeOn+"\ +
ON: " + + timeOn + "\ \
\ -
OFF: "+timeOff+"\ +
OFF: " + + timeOff + "\