From 32670520231a1e55b2150e679f29c3a07e735908 Mon Sep 17 00:00:00 2001 From: BinTechLLC <51284647+BinTechLLC@users.noreply.github.com> Date: Tue, 29 Nov 2022 20:14:28 -0600 Subject: [PATCH 01/15] Add files via upload --- .../Pointless_Button_V2.0.1-Beta.ino | 1120 +++++++++++++++++ 1 file changed, 1120 insertions(+) create mode 100644 Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino diff --git a/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino b/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino new file mode 100644 index 0000000..2a756f7 --- /dev/null +++ b/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino @@ -0,0 +1,1120 @@ +/* + Pointless Button V2 - Version History + + V2.0.0 - Connect Buttons (this build uses 4 buttons and 4 LEDs) + - Base WiFi and WiFi reset functions + - Multi SSID Failover functions + - Basic Firebase Read Functions + - Basic Count Functions + - Basic Firebase Write and Update Functions + - Release and Beta Version Checker + + V2.0.1 - Add LED Success / Fail Indicators for Boot and Updates + - *Add Button Combo to Trigger a Reboot + - *Add Current SSID String and Firebase Entry + - *Move Boot Cycle to its own String and Firebase Entry + - *Add Remote LED Test Trigger + - *Local Web GUI + - * + + V2.1.0 - *Create Python Server for Time Keeping and Last Boot Recording + - * + +*/ +//----------------------------------------------------------------------------------------------------------------------- +// Default Node Values +//----------------------------------------------------------------------------------------------------------------------- +String currentLocalVersionNumber = "V2.0.1-Beta"; +String currentReleaseVersionNumber; +String currentBetaReleaseVersionNumber; +int writeAsNetPB = false; // Set this to true if creating new node. +String pbName = "PB001-Alpha"; +int serialDebugOutput = true; +//----------------------------------------------------------------------------------------------------------------------- +// Libraries +//----------------------------------------------------------------------------------------------------------------------- +#include +#include +//----------------------------------------------------------------------------------------------------------------------- +// Credentials and Links +//----------------------------------------------------------------------------------------------------------------------- +#define FIREBASE_HOST "https://pointlessbuttonv2-2022-default-rtdb.firebaseio.com" +#define FIREBASE_AUTH "Bddm9oBrsBKmjzKv9iUtwqO7JjpgJBwb4ObBqOra" +const char* ssid2 = "BinTech LLC"; +const char* ssidpass2 = "FuckYouBitch123!@#"; +const char* ssid1 = "KB-N20U"; +const char* ssidpass1 = "RollYourButt123!@#"; +const char* externalHostname = "api.ipify.org"; +//----------------------------------------------------------------------------------------------------------------------- +// Definitions and States +//----------------------------------------------------------------------------------------------------------------------- +#define greenButton1 12 +#define greenButton2 14 +#define redButton1 27 +#define redButton2 26 +#define greenLED1 25 +#define greenLED2 33 +#define redLED1 32 +#define redLED2 13 +int greenButton1State; +int greenButton2State; +int redButton1State; +int redButton2State; +int g1Press; +int g2Press; +int r1Press; +int r2Press; +int g1LEDState; +int g2LEDState; +int r1LEDState; +int r2LEDState; +unsigned long g1Count; +unsigned long g2Count; +unsigned long r1Count; +unsigned long r2Count; +unsigned long g1CountRead; +unsigned long g2CountRead; +unsigned long r1CountRead; +unsigned long r2CountRead; +String currentState; +String lastState; +IPAddress lip; +IPAddress eip; +String ep; +int defaultSystemDelayInMilliseconds = 50; +int defaultUpdateDelayInSeconds = 300; +int defaultFirebaseReadDelay = 50; +int defaultFirebaseWriteDelay = 50; +int portNumber = 80; +int wifiResetCycles = 40; // 20 per SSID. +int connectResetCount; +int connectRunCommand; +int defaultDelayCount; +int defaultDelayCountCycle; +int isRunning; +unsigned long bootCycles; +int writeBootCycles; +int firebaseCycle; +int bootErrorCount; +int updateErrorCount; +String rebootNode; +WiFiServer server(portNumber); +FirebaseData fbdo; +//----------------------------------------------------------------------------------------------------------------------- +// Void Call Reset Function +//----------------------------------------------------------------------------------------------------------------------- +void(* resetFunc) (void) = 0; // This Is The Software Reset Function, Just Like A Reboot. It Needs To Be Above All Other Voids To Be Called From Them +//----------------------------------------------------------------------------------------------------------------------- +// Void Test LEDs +//----------------------------------------------------------------------------------------------------------------------- +void testLEDs() { + digitalWrite(greenLED1, HIGH); + delay(500); + digitalWrite(greenLED2, HIGH); + delay(500); + digitalWrite(redLED1, HIGH); + delay(500); + digitalWrite(redLED2, HIGH); + delay(500); +} +//----------------------------------------------------------------------------------------------------------------------- +// String Get External IP +//----------------------------------------------------------------------------------------------------------------------- +String getExternalIP() { + delay(500); + WiFiClient client; + if (client.connect("api.ipify.org", 80)) + { + client.println("GET / HTTP/1.0"); + client.println("Host: api.ipify.org"); + client.println(); + } else { + return String(); + } + delay(5000); + String line; + line = ""; + while (client.available()) + { + line = client.readStringUntil('\n'); + } + return line; +} +//----------------------------------------------------------------------------------------------------------------------- +// Void WiFi First Connect +//----------------------------------------------------------------------------------------------------------------------- +void wifiFirstConnect() { + g1LEDState = 1; + connectResetCount = 0; + while (WiFi.status() != WL_CONNECTED) { + connectResetCount ++ ; + if (g1LEDState == 1) { + digitalWrite(greenLED1, LOW); + g1LEDState = 0; + } + else if (g1LEDState == 0) { + digitalWrite(greenLED1, HIGH); + g1LEDState = 1; + } + if (connectResetCount <= 19) { + if (connectRunCommand == 0) { + if (serialDebugOutput == true) { + Serial.println(String("Connecting to ") + ssid1); + } + WiFi.disconnect(); + delay(500); + WiFi.begin(ssid1, ssidpass1); + connectRunCommand = 1; + } + } + else if (connectResetCount >= 20 && connectResetCount <= 39) { + if (connectRunCommand == 1) { + connectRunCommand = 2; + } + if (connectRunCommand == 2) { + if (serialDebugOutput == true) { + Serial.println(String("Connecting to ") + ssid2); + } + WiFi.disconnect(); + delay(500); + WiFi.begin(ssid2, ssidpass2); + connectRunCommand = 3; + } + } + else if (connectResetCount >= 40) { + if (serialDebugOutput == true) { + Serial.println("Resetting"); + } + delay(1000); + resetFunc(); + } + delay(500); + } + firebaseCycle = 0; + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + WiFi.setSleep(false); + Serial.println("Getting Internal IP."); + lip = WiFi.localIP(); + if (serialDebugOutput == true) { + Serial.println(lip); + } + delay(500); + Serial.println("Getting External IP."); + String(eip) = getExternalIP(); + if (serialDebugOutput == true) { + Serial.println(eip); + } + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + delay(500); + Serial.println("Starting Firebase Connection."); + Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); // Start The Firebase Connection + Firebase.reconnectWiFi(true); // Set Firebase To Reconnect If Wireless Fails And Reconnects + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + delay(500); + Serial.println("Reading Firebase Initial Values."); + //----------------------------------------------------------------------------------------------------------------------- Read Default System Delay In Milliseconds. + while (firebaseCycle == 0) { + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/11-Default_System_Delay_In_Milliseconds")) { // This Will Read The Directory + defaultSystemDelayInMilliseconds = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Default System Delay In Milliseconds, "); + Serial.println(defaultSystemDelayInMilliseconds); + + } + firebaseCycle = 1; + } + else { + Serial.println("Read Failed of Default System Delay In Milliseconds."); + firebaseCycle = 0; + bootErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Default Update Delay In Seconds. + while (firebaseCycle == 1) { + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/12-Default_Update_Delay_In_Seconds")) { // This Will Read The Directory + defaultUpdateDelayInSeconds = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Default Update Delay In Seconds."); + Serial.println(defaultUpdateDelayInSeconds); + } + firebaseCycle = 2; + } + else { + Serial.println("Read Failed of Default Update Delay In Seconds."); + firebaseCycle = 1; + bootErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Default Firebase Write Delay. + while (firebaseCycle == 2) { + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/13-Default_Firebase_Write_Delay")) { // This Will Read The Directory + defaultFirebaseWriteDelay = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Default Firebase Write Delay, "); + Serial.println(defaultFirebaseWriteDelay); + } + firebaseCycle = 3; + } + else { + Serial.println("Read Failed of Default Firebase Write Delay."); + firebaseCycle = 2; + bootErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Default Firebase Read Delay. + while (firebaseCycle == 3) { + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/14-Default_Firebase_Read_Delay")) { // This Will Read The Directory + defaultFirebaseReadDelay = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Default Firebase Read Delay, "); + Serial.println(defaultFirebaseReadDelay); + } + firebaseCycle = 4; + } + else { + Serial.println("Read Failed of Default Firebase Read Delay."); + firebaseCycle = 3; + bootErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Current Release Number + while (firebaseCycle == 4) { + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + if (Firebase.getString(fbdo, "/00-Global/00-Current_Release_Number")) { // This Will Read The Directory + currentReleaseVersionNumber = fbdo.stringData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Current Release Version Number, "); + Serial.println(currentReleaseVersionNumber); + } + firebaseCycle = 5; + } + else { + Serial.println("Read Failed of Current Release Version Number."); + firebaseCycle = 4; + bootErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Current Beta Version + while (firebaseCycle == 5) { + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + if (Firebase.getString(fbdo, "/00-Global/01-Current_Beta_Release_Number")) { // This Will Read The Directory + currentBetaReleaseVersionNumber = fbdo.stringData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Current Beta Release Version Number, "); + Serial.println(currentBetaReleaseVersionNumber); + } + firebaseCycle = 6; + } + else { + Serial.println("Read Failed of Current Beta Release Version Number."); + firebaseCycle = 5; + bootErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Check For Update and Beta + if (currentReleaseVersionNumber == currentLocalVersionNumber) { + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + if (serialDebugOutput == true) { + Serial.println("# # # # # You are running the most recent version."); + Serial.println(String("Current Local: ") + currentLocalVersionNumber); + Serial.println(String("Current Release: ") + currentReleaseVersionNumber); + } + } + else if (currentReleaseVersionNumber != currentLocalVersionNumber) { + if (serialDebugOutput == true) { + Serial.println("# # # # # Your version does not match the current version."); + Serial.println(String("Current Local: ") + currentLocalVersionNumber); + Serial.println(String("Current Release: ") + currentReleaseVersionNumber); + } + } + if (currentReleaseVersionNumber == currentBetaReleaseVersionNumber) { + if (serialDebugOutput == true) { + Serial.println("# # # # # There are no Beta versions available."); + Serial.println(String("Current Release: ") + currentReleaseVersionNumber); + Serial.println(String("Current Beta: ") + currentBetaReleaseVersionNumber); + } + } + else if (currentReleaseVersionNumber != currentBetaReleaseVersionNumber) { + if (serialDebugOutput == true) { + Serial.println("# # # # # There is a newer Beta version available."); + Serial.println(String("Current Release: ") + currentReleaseVersionNumber); + Serial.println(String("Current Beta: ") + currentBetaReleaseVersionNumber); + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Port Number + while (firebaseCycle == 6) { + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/15-Port_Number")) { // This Will Read The Directory + portNumber = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Port Number, "); + Serial.println(portNumber); + } + firebaseCycle = 7; + } + else { + Serial.println("Read Failed of Port Number."); + firebaseCycle = 6; + bootErrorCount ++; + } + } + //-----------------------------------------------------------------------------------------------------------------------Read WiFi Reset Cycles + while (firebaseCycle == 7) { + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/16-WiFi_Reset_Cycles")) { // This Will Read The Directory + wifiResetCycles = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of WiFi Reset Cycles, "); + Serial.println(wifiResetCycles); + } + firebaseCycle = 8; + } + else { + Serial.println("Read Failed of WiFi Reset Cycles."); + firebaseCycle = 7; + bootErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Reboot Node + while (firebaseCycle == 8) { + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + if (Firebase.getString(fbdo, "/01-Counters/" + pbName + "/19-Reboot_Node")) { // This Will Read The Directory + rebootNode = fbdo.stringData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Reboot Node, "); + Serial.println(rebootNode); + } + firebaseCycle = 9; + if (rebootNode == "true") { + if (serialDebugOutput == true) { + Serial.println("Reboot Triggered Remotely"); + } + delay(1000); + resetFunc(); + } + } + else { + Serial.println("Read Failed of Reboot Node."); + firebaseCycle = 8; + bootErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Count 1 + while (firebaseCycle == 9) { + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/01-Count1")) { // This Will Read The "/01-....." Directory + g1Count = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Green 1 Count, "); + Serial.println(g1Count); + } + firebaseCycle = 10; + } + else { + Serial.println("Read Failed of Green 1 Count."); + firebaseCycle = 9; + bootErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Count 2 + while (firebaseCycle == 10) { + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/02-Count2")) { // This Will Read The "/02-....." Directory + g2Count = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Green 2 Count, "); + Serial.println(g2Count); + } + firebaseCycle = 11; + } + else { + Serial.println("Read Failed of Green 2 Count."); + firebaseCycle = 10; + bootErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Count 3 + while (firebaseCycle == 11) { + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/03-Count3")) { // This Will Read The "/03-....." Directory + r1Count = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Red 1 Count, "); + Serial.println(r1Count); + } + firebaseCycle = 12; + } + else { + Serial.println("Read Failed of Red 1 Count."); + firebaseCycle = 11; + bootErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Count 4 + while (firebaseCycle == 12) { + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/04-Count4")) { // This Will Read The "/04-....." Directory + r2Count = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Red 2 Count, "); + Serial.println(r2Count); + } + firebaseCycle = 13; + } + else { + Serial.println("Read Failed of Red 2 Count."); + firebaseCycle = 12; + bootErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Count 10 (Boot Cycles) + while (firebaseCycle == 13) { + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/10-Count10")) { // This Will Read The "/04-....." Directory + bootCycles = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Boot Cycles, "); + Serial.println(bootCycles); + if (isRunning == 0) { + writeBootCycles = true; + isRunning = 1; + } + else { + writeBootCycles = false; + } + } + firebaseCycle = 14; + } + else { + Serial.println("Read Failed of Boot Cycles."); + writeBootCycles = false; + firebaseCycle = 13; + bootErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- #### WRITE FUNCTIONS ############################################### + //----------------------------------------------------------------------------------------------------------------------- Write Local Version Number + while (firebaseCycle == 14) { + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + if (Firebase.setString(fbdo, "/01-Counters/" + pbName + "/20-Current_Local_Version_Number", currentLocalVersionNumber)) { + delay(defaultFirebaseWriteDelay); // Defined At The Top + if (serialDebugOutput) { + Serial.print("Write Successful of Current Local Version Number, "); + Serial.println(currentLocalVersionNumber); + } + firebaseCycle = 15; + } + else { + Serial.println("Write Failed of Current Local Version Number."); + firebaseCycle = 14; + bootErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Write Locak IP + while (firebaseCycle == 15) { + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + String lip2 = WiFi.localIP().toString(); + if (Firebase.setString(fbdo, "/01-Counters/" + pbName + "/17-LocalIP", lip2)) { + delay(defaultFirebaseWriteDelay); // Defined At The Top + if (serialDebugOutput) { + Serial.print("Write Successful of Local IP, "); + Serial.println(lip); + } + firebaseCycle = 16; + } + else { + Serial.println("Write Failed of Local IP."); + firebaseCycle = 15; + bootErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Write External IP + while (firebaseCycle == 16) { + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + if (Firebase.setString(fbdo, "/01-Counters/" + pbName + "/18-ExternalIP", eip)) { + delay(defaultFirebaseWriteDelay); // Defined At The Top + if (serialDebugOutput) { + Serial.print("Write Successful of External IP, "); + Serial.println(eip); + } + firebaseCycle = 17; + } + else { + Serial.println("Write Failed of External IP."); + firebaseCycle = 16; + bootErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Write Boot Cycles + while (firebaseCycle == 17) { + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + if (writeBootCycles == true) { + if (bootCycles >= 1) { + delay(5); + bootCycles ++; + delay(5); + if (Firebase.setInt(fbdo, "/01-Counters/" + pbName + "/10-Count10", bootCycles)) { + delay(defaultFirebaseWriteDelay); // Defined At The Top + if (serialDebugOutput) { + Serial.print("Write Successful of Boot Cycles (Count10), "); + Serial.println(bootCycles); + } + firebaseCycle = 18; + } + else { + Serial.println("Write Failed of Boot Cycles (Count10)."); + firebaseCycle = 17; + bootErrorCount ++; + } + } + } + } + + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, HIGH); + delay(500); + delay(1000); + if (bootErrorCount <= 0) { + if (serialDebugOutput) { + Serial.println("All Firebase First Boot Variables Sent / Received Successfully"); + } + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, HIGH); + digitalWrite(redLED1, LOW); + digitalWrite(redLED2, LOW); + } + else if (bootErrorCount >= 1) { + if (serialDebugOutput) { + Serial.println(String("All Firebase First Boot Variables Sent / Received Successfully with retry errors: ") + String(bootErrorCount)); + } + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, HIGH); + digitalWrite(redLED1, HIGH); + digitalWrite(redLED2, LOW); + } + delay(500); + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, LOW); + digitalWrite(redLED1, LOW); + digitalWrite(redLED2, LOW); +} +//----------------------------------------------------------------------------------------------------------------------- +// Void Write Firebase Updates +//----------------------------------------------------------------------------------------------------------------------- +void writeFirebaseUpdate() { + updateErrorCount = 0; + if (serialDebugOutput == true) { + Serial.println(" # # # # # Firebase Update Triggered"); + } + //----------------------------------------------------------------------------------------------------------------------- Read Default System Delay In Milliseconds. + while (firebaseCycle == 0) { + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + if (Firebase.getString(fbdo, "/01-Counters/" + pbName + "/00-PB_Name")) { // This Will Read The Directory + String pbNameRead = fbdo.stringData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of PB Name, "); + Serial.println(pbNameRead); + } + firebaseCycle = 1; + } + else { + Serial.println("Read Failed of PB Name."); + firebaseCycle = 0; + updateErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Default System Delay In Milliseconds. + while (firebaseCycle == 1) { + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/11-Default_System_Delay_In_Milliseconds")) { // This Will Read The Directory + defaultSystemDelayInMilliseconds = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Default System Delay In Milliseconds, "); + Serial.println(defaultSystemDelayInMilliseconds); + } + firebaseCycle = 2; + } + else { + Serial.println("Read Failed of Default System Delay In Milliseconds."); + firebaseCycle = 1; + updateErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Default Update Delay In Seconds. + while (firebaseCycle == 2) { + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/12-Default_Update_Delay_In_Seconds")) { // This Will Read The Directory + defaultUpdateDelayInSeconds = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Default Update Delay In Seconds, "); + Serial.println(defaultUpdateDelayInSeconds); + } + firebaseCycle = 3; + } + else { + Serial.println("Read Failed of Default Update Delay In Seconds."); + firebaseCycle = 2; + updateErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Default Firebase Write Delay. + while (firebaseCycle == 3) { + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/13-Default_Firebase_Write_Delay")) { // This Will Read The Directory + defaultFirebaseWriteDelay = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Default Firebase Write Delay, "); + Serial.println(defaultFirebaseWriteDelay); + } + firebaseCycle = 4; + } + else { + Serial.println("Read Failed of Default Firebase Write Delay."); + firebaseCycle = 3; + updateErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Default Firebase Read Delay. + while (firebaseCycle == 4) { + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/14-Default_Firebase_Read_Delay")) { // This Will Read The Directory + defaultFirebaseReadDelay = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Default Firebase Read Delay, "); + Serial.println(defaultFirebaseReadDelay); + } + firebaseCycle = 5; + } + else { + Serial.println("Read Failed of Default Firebase Read Delay."); + firebaseCycle = 4; + updateErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Port Number + while (firebaseCycle == 5) { + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/15-Port_Number")) { // This Will Read The Directory + portNumber = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Port Number, "); + Serial.println(portNumber); + } + firebaseCycle = 6; + } + else { + Serial.println("Read Failed of Port Number."); + firebaseCycle = 5; + updateErrorCount ++; + } + } + //-----------------------------------------------------------------------------------------------------------------------Read WiFi Reset Cycles + while (firebaseCycle == 6) { + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/16-WiFi_Reset_Cycles")) { // This Will Read The Directory + wifiResetCycles = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of WiFi Reset Cycles, "); + Serial.println(wifiResetCycles); + } + firebaseCycle = 7; + } + else { + Serial.println("Read Failed of WiFi Reset Cycles."); + firebaseCycle = 6; + updateErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Reboot Node + while (firebaseCycle == 7) { + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + if (Firebase.getString(fbdo, "/01-Counters/" + pbName + "/19-Reboot_Node")) { // This Will Read The Directory + rebootNode = fbdo.stringData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Reboot Node, "); + Serial.println(rebootNode); + } + firebaseCycle = 8; + if (rebootNode == "true") { + if (serialDebugOutput == true) { + Serial.println("Reboot Triggered Remotely"); + } + delay(1000); + resetFunc(); + } + } + else { + Serial.println("Read Failed of Reboot Node."); + firebaseCycle = 7; + updateErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Count 1 + while (firebaseCycle == 8) { + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/01-Count1")) { // This Will Read The "/01-....." Directory + g1CountRead = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Green 1 Count, "); + Serial.println(g1Count); + } + firebaseCycle = 9; + } + else { + Serial.println("Read Failed of Green 1 Count."); + firebaseCycle = 8; + updateErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Count 2 + while (firebaseCycle == 9) { + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/02-Count2")) { // This Will Read The "/02-....." Directory + g2CountRead = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Green 2 Count, "); + Serial.println(g2Count); + } + firebaseCycle = 10; + } + else { + Serial.println("Read Failed of Green 2 Count."); + firebaseCycle = 9; + updateErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Count 3 + while (firebaseCycle == 10) { + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/03-Count3")) { // This Will Read The "/03-....." Directory + r1CountRead = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Red 1 Count, "); + Serial.println(r1Count); + } + firebaseCycle = 11; + } + else { + Serial.println("Read Failed of Red 1 Count."); + firebaseCycle = 10; + updateErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Count 4 + while (firebaseCycle == 11) { + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/04-Count4")) { // This Will Read The "/04-....." Directory + r2CountRead = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == true) { + Serial.print("Read Successful of Red 2 Count, "); + Serial.println(r2Count); + } + firebaseCycle = 12; + } + else { + Serial.println("Read Failed of Red 2 Count."); + firebaseCycle = 11; + updateErrorCount ++; + } + } + if (g1Count >= (g1CountRead + 1) or g2Count >= (g2CountRead + 1) or r1Count >= (r1CountRead + 1) or r2Count >= (r2CountRead + 1)) { + //----------------------------------------------------------------------------------------------------------------------- Write Count 1 + while (firebaseCycle == 12) { + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + if (Firebase.setInt(fbdo, "/01-Counters/" + pbName + "/01-Count1", g1Count)) { + delay(defaultFirebaseWriteDelay); // Defined At The Top + if (serialDebugOutput) { + Serial.print("Write Successful of New Green 1 Count, "); + Serial.println(g1Count); + } + firebaseCycle = 13; + } + else { + Serial.println("Write Failed of New Green 1 Count."); + firebaseCycle = 12; + updateErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Write Count 2 + while (firebaseCycle == 13) { + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + if (Firebase.setInt(fbdo, "/01-Counters/" + pbName + "/02-Count2", g2Count)) { + delay(defaultFirebaseWriteDelay); // Defined At The Top + if (serialDebugOutput) { + Serial.print("Write Successful of New Green 2 Count, "); + Serial.println(g2Count); + } + firebaseCycle = 14; + } + else { + Serial.println("Write Failed of New Green 2 Count."); + firebaseCycle = 13; + updateErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Write Count 3 + while (firebaseCycle == 14) { + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + if (Firebase.setInt(fbdo, "/01-Counters/" + pbName + "/03-Count3", r1Count)) { + delay(defaultFirebaseWriteDelay); // Defined At The Top + if (serialDebugOutput) { + Serial.print("Write Successful of New Red 1 Count, "); + Serial.println(r1Count); + } + firebaseCycle = 15; + } + else { + Serial.println("Write Failed of New Red 1 Count."); + firebaseCycle = 14; + updateErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Write Count 4 + while (firebaseCycle == 15) { + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + if (Firebase.setInt(fbdo, "/01-Counters/" + pbName + "/04-Count4", r2Count)) { + delay(defaultFirebaseWriteDelay); // Defined At The Top + if (serialDebugOutput) { + Serial.print("Write Successful of New Red 2 Count, "); + Serial.println(r2Count); + } + firebaseCycle = 16; + } + else { + Serial.println("Write Failed of New Red 2 Count."); + firebaseCycle = 15; + updateErrorCount ++; + } + } + } + if (updateErrorCount <= 0) { + if (serialDebugOutput) { + Serial.println(" # # # # # Finished Successfully"); + } + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, HIGH); + digitalWrite(redLED1, LOW); + digitalWrite(redLED2, LOW); + } + if (updateErrorCount >= 1) { + if (serialDebugOutput) { + Serial.println(String(" # # # # # Finished with retry errors: ") + String(updateErrorCount)); + } + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, HIGH); + digitalWrite(redLED1, LOW); + digitalWrite(redLED2, HIGH); + + } + delay(500); + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, LOW); + digitalWrite(redLED1, LOW); + digitalWrite(redLED2, LOW); +} +//----------------------------------------------------------------------------------------------------------------------- +// Void Run Button Logic +//----------------------------------------------------------------------------------------------------------------------- +void runButtonLogic() { + //--------------------------------- Green 1 + if (greenButton1State == 0) { + if (g1Press == 0) { + digitalWrite(greenLED1, HIGH); + g1Count ++; + g1Press = 1; + } + else if (g1Press == 1) { + g1Press = 1; + } + } + else if (greenButton1State == 1) { + digitalWrite(greenLED1, LOW); + g1Press = 0; + } + //--------------------------------- Green 2 + if (greenButton2State == 0) { + if (g2Press == 0) { + digitalWrite(greenLED2, HIGH); + g2Count ++; + g2Press = 1; + } + else if (g2Press == 1) { + g2Press = 1; + } + } + else if (greenButton2State == 1) { + digitalWrite(greenLED2, LOW); + g2Press = 0; + } + //--------------------------------- Red 1 + if (redButton1State == 0) { + if (r1Press == 0) { + digitalWrite(redLED1, HIGH); + r1Count ++; + r1Press = 1; + } + else if (r1Press == 1) { + r1Press = 1; + } + } + else if (redButton1State == 1) { + digitalWrite(redLED1, LOW); + r1Press = 0; + } + //--------------------------------- Red 2 + if (redButton2State == 0) { + if (r2Press == 0) { + digitalWrite(redLED2, HIGH); + r2Count ++; + r2Press = 1; + } + else if (r2Press == 1) { + r2Press = 1; + } + } + else if (redButton2State == 1) { + digitalWrite(redLED2, LOW); + r2Press = 0; + } +} +//----------------------------------------------------------------------------------------------------------------------- +// Void Setup +//----------------------------------------------------------------------------------------------------------------------- +void setup() { + if (serialDebugOutput == true) { + Serial.begin(115200); + if (!Serial) { + serialDebugOutput = false; + } + if (serialDebugOutput == true) { + Serial.println(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "); + Serial.println(" - Starting - " + pbName + " New Node Enabled? " + writeAsNetPB); + } + } + pinMode(greenButton1, INPUT_PULLUP); + pinMode(greenButton2, INPUT_PULLUP); + pinMode(redButton1, INPUT_PULLUP); + pinMode(redButton2, INPUT_PULLUP); + pinMode(greenLED1, OUTPUT); + pinMode(greenLED2, OUTPUT); + pinMode(redLED1, OUTPUT); + pinMode(redLED2, OUTPUT); + if (serialDebugOutput == true) { + Serial.println("Testing LEDs"); + } + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, LOW); + digitalWrite(redLED1, LOW); + digitalWrite(redLED2, LOW); + WiFi.disconnect(); + wifiFirstConnect(); + testLEDs(); +} +//----------------------------------------------------------------------------------------------------------------------- +// Void Loop +//----------------------------------------------------------------------------------------------------------------------- +void loop() { + writeBootCycles = 0; + if (WiFi.status() != 3) { + WiFi.disconnect(); + delay(1000); + wifiFirstConnect(); + } + defaultDelayCountCycle ++; + if (defaultDelayCountCycle >= 20) { + defaultDelayCount ++; + if (serialDebugOutput == true) { + Serial.println(defaultDelayCount); + } + defaultDelayCountCycle = 0; + } + if (defaultDelayCount >= defaultUpdateDelayInSeconds) { + + defaultDelayCount = 0; + defaultDelayCountCycle = 0; + firebaseCycle = 0; + writeFirebaseUpdate(); + } + greenButton1State = digitalRead(greenButton1); + greenButton2State = digitalRead(greenButton2); + redButton1State = digitalRead(redButton1); + redButton2State = digitalRead(redButton2); + currentState = (String("G1: ") + g1Count + String(" G2: ") + g2Count + String(" R1: ") + r1Count + String(" R2: ") + r2Count); + runButtonLogic(); + //--------------------------------- Print Debug To Serial + if (serialDebugOutput == true) { + if (lastState != currentState) { + lastState = currentState; + Serial.println(currentState); + } + } + delay(defaultSystemDelayInMilliseconds); +} From 71f3a68ec7657c30e6bc70aef1f208cf486d9844 Mon Sep 17 00:00:00 2001 From: BinTechLLC <51284647+BinTechLLC@users.noreply.github.com> Date: Tue, 29 Nov 2022 20:18:17 -0600 Subject: [PATCH 02/15] Update Pointless_Button_V2.0.1-Beta.ino --- .../Pointless_Button_V2.0.1-Beta.ino | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino b/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino index 2a756f7..be2b99d 100644 --- a/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino +++ b/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino @@ -27,8 +27,8 @@ String currentLocalVersionNumber = "V2.0.1-Beta"; String currentReleaseVersionNumber; String currentBetaReleaseVersionNumber; -int writeAsNetPB = false; // Set this to true if creating new node. -String pbName = "PB001-Alpha"; +int writeAsNetPB = false; // Set this to true if creating new node. (Currently Not Functional) +String pbName = "PB###"; int serialDebugOutput = true; //----------------------------------------------------------------------------------------------------------------------- // Libraries @@ -38,12 +38,12 @@ int serialDebugOutput = true; //----------------------------------------------------------------------------------------------------------------------- // Credentials and Links //----------------------------------------------------------------------------------------------------------------------- -#define FIREBASE_HOST "https://pointlessbuttonv2-2022-default-rtdb.firebaseio.com" -#define FIREBASE_AUTH "Bddm9oBrsBKmjzKv9iUtwqO7JjpgJBwb4ObBqOra" -const char* ssid2 = "BinTech LLC"; -const char* ssidpass2 = "FuckYouBitch123!@#"; -const char* ssid1 = "KB-N20U"; -const char* ssidpass1 = "RollYourButt123!@#"; +#define FIREBASE_HOST "https://YourHostToFirebase-default-rtdb.firebaseio.com" +#define FIREBASE_AUTH "YourAPIKey" +const char* ssid1 = "SSID1 Name"; +const char* ssidpass1 = "SSID1 Password"; +const char* ssid2 = "SSID2 Name"; +const char* ssidpass2 = "SSID2 Password"; const char* externalHostname = "api.ipify.org"; //----------------------------------------------------------------------------------------------------------------------- // Definitions and States From ffa02e04e81287b416113ab107e9c61f486ad82d Mon Sep 17 00:00:00 2001 From: BinTechLLC <51284647+BinTechLLC@users.noreply.github.com> Date: Wed, 30 Nov 2022 20:06:37 -0600 Subject: [PATCH 03/15] Update file to current beta Added the Current SSID Firebase Entry and moved the Boot Count to its own entry. --- .../Pointless_Button_V2.0.1-Beta.ino | 58 ++++++++++++++----- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino b/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino index be2b99d..8c687da 100644 --- a/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino +++ b/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino @@ -10,9 +10,9 @@ - Release and Beta Version Checker V2.0.1 - Add LED Success / Fail Indicators for Boot and Updates - - *Add Button Combo to Trigger a Reboot - - *Add Current SSID String and Firebase Entry - - *Move Boot Cycle to its own String and Firebase Entry + - (Not going to add, have had a lot of people mash multiple / all buttons at a time, would cause an unwanted reboot. ##Add Button Combo to Trigger a Reboot + - Add Current SSID String and Firebase Entry + - Move Boot Cycle to its own String and Firebase Entry - *Add Remote LED Test Trigger - *Local Web GUI - * @@ -27,8 +27,8 @@ String currentLocalVersionNumber = "V2.0.1-Beta"; String currentReleaseVersionNumber; String currentBetaReleaseVersionNumber; -int writeAsNetPB = false; // Set this to true if creating new node. (Currently Not Functional) -String pbName = "PB###"; +int writeAsNetPB = false; // Set this to true if creating new node. +String pbName = "PB001-Alpha"; int serialDebugOutput = true; //----------------------------------------------------------------------------------------------------------------------- // Libraries @@ -38,12 +38,12 @@ int serialDebugOutput = true; //----------------------------------------------------------------------------------------------------------------------- // Credentials and Links //----------------------------------------------------------------------------------------------------------------------- -#define FIREBASE_HOST "https://YourHostToFirebase-default-rtdb.firebaseio.com" +#define FIREBASE_HOST "https://YourRTDHostname-default-rtdb.firebaseio.com" #define FIREBASE_AUTH "YourAPIKey" -const char* ssid1 = "SSID1 Name"; -const char* ssidpass1 = "SSID1 Password"; -const char* ssid2 = "SSID2 Name"; -const char* ssidpass2 = "SSID2 Password"; +const char* ssid2 = "SSIDName1"; +const char* ssidpass2 = "SSIDPassword1"; +const char* ssid1 = "SSIDName2"; +const char* ssidpass1 = "SSIDPassword2"; const char* externalHostname = "api.ipify.org"; //----------------------------------------------------------------------------------------------------------------------- // Definitions and States @@ -97,6 +97,7 @@ int writeBootCycles; int firebaseCycle; int bootErrorCount; int updateErrorCount; +String currentSSID; String rebootNode; WiFiServer server(portNumber); FirebaseData fbdo; @@ -164,6 +165,7 @@ void wifiFirstConnect() { WiFi.disconnect(); delay(500); WiFi.begin(ssid1, ssidpass1); + currentSSID = ssid1; connectRunCommand = 1; } } @@ -178,6 +180,7 @@ void wifiFirstConnect() { WiFi.disconnect(); delay(500); WiFi.begin(ssid2, ssidpass2); + currentSSID = ssid2; connectRunCommand = 3; } } @@ -505,7 +508,7 @@ void wifiFirstConnect() { while (firebaseCycle == 13) { digitalWrite(greenLED1, LOW); digitalWrite(greenLED2, HIGH); - if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/10-Count10")) { // This Will Read The "/04-....." Directory + if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/22-Boot_Count")) { // This Will Read The "/04-....." Directory bootCycles = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); if (serialDebugOutput == true) { @@ -593,22 +596,47 @@ void wifiFirstConnect() { delay(5); bootCycles ++; delay(5); - if (Firebase.setInt(fbdo, "/01-Counters/" + pbName + "/10-Count10", bootCycles)) { + if (Firebase.setString(fbdo, "/01-Counters/" + pbName + "/21-Current_Connected_SSID", currentSSID)) { delay(defaultFirebaseWriteDelay); // Defined At The Top if (serialDebugOutput) { - Serial.print("Write Successful of Boot Cycles (Count10), "); - Serial.println(bootCycles); + Serial.print("Write Successful of Current SSID."); + Serial.println(currentSSID); } firebaseCycle = 18; } else { - Serial.println("Write Failed of Boot Cycles (Count10)."); + Serial.println("Write Failed of Current SSID."); firebaseCycle = 17; bootErrorCount ++; } } } } + //----------------------------------------------------------------------------------------------------------------------- Write Boot Cycles + while (firebaseCycle == 18) { + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + if (writeBootCycles == true) { + if (bootCycles >= 1) { + delay(5); + bootCycles ++; + delay(5); + if (Firebase.setInt(fbdo, "/01-Counters/" + pbName + "/22-Boot_Count", bootCycles)) { + delay(defaultFirebaseWriteDelay); // Defined At The Top + if (serialDebugOutput) { + Serial.print("Write Successful of Boot Cycles."); + Serial.println(bootCycles); + } + firebaseCycle = 19; + } + else { + Serial.println("Write Failed of Boot Cycles."); + firebaseCycle = 18; + bootErrorCount ++; + } + } + } + } digitalWrite(greenLED1, HIGH); digitalWrite(greenLED2, HIGH); From 670002c6a1853017356d28512eb2271b585bd7a5 Mon Sep 17 00:00:00 2001 From: BinTechLLC <51284647+BinTechLLC@users.noreply.github.com> Date: Wed, 30 Nov 2022 20:10:04 -0600 Subject: [PATCH 04/15] Create Current_Additions.txt --- Pointless_Button_V2.0.1-Beta/Current_Additions.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Pointless_Button_V2.0.1-Beta/Current_Additions.txt diff --git a/Pointless_Button_V2.0.1-Beta/Current_Additions.txt b/Pointless_Button_V2.0.1-Beta/Current_Additions.txt new file mode 100644 index 0000000..add816f --- /dev/null +++ b/Pointless_Button_V2.0.1-Beta/Current_Additions.txt @@ -0,0 +1,9 @@ +V2.0.1-Beta - (I cant remember the date of the first upload of the beta so this is the stuff that was added to this point.) + +- ##-##-2022 +- + +- 11-30-2022 +- Added LED Success / Fail Indicators for Boot and Updates +- Added Current Connected SSID Firebase String +- Moved Boot Cycles to its own Firebase String From 1f73f88d95dc768f61f009ba1bf7fe0f0c90412c Mon Sep 17 00:00:00 2001 From: BinTechLLC <51284647+BinTechLLC@users.noreply.github.com> Date: Wed, 30 Nov 2022 20:10:32 -0600 Subject: [PATCH 05/15] Update Current_Additions.txt --- Pointless_Button_V2.0.1-Beta/Current_Additions.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Pointless_Button_V2.0.1-Beta/Current_Additions.txt b/Pointless_Button_V2.0.1-Beta/Current_Additions.txt index add816f..4eaebfb 100644 --- a/Pointless_Button_V2.0.1-Beta/Current_Additions.txt +++ b/Pointless_Button_V2.0.1-Beta/Current_Additions.txt @@ -1,9 +1,9 @@ -V2.0.1-Beta - (I cant remember the date of the first upload of the beta so this is the stuff that was added to this point.) +V2.0.1-Beta - ##-##-2022 - -- 11-30-2022 +- 11-30-2022 (I cant remember the date of the first upload of the beta so this is the stuff that was added to this point.) - Added LED Success / Fail Indicators for Boot and Updates - Added Current Connected SSID Firebase String - Moved Boot Cycles to its own Firebase String From acca0609cb2a4b3623ae4b528d510ab06dae0204 Mon Sep 17 00:00:00 2001 From: BinTechLLC <51284647+BinTechLLC@users.noreply.github.com> Date: Wed, 30 Nov 2022 22:36:51 -0600 Subject: [PATCH 06/15] Update Current_Additions.txt --- Pointless_Button_V2.0.1-Beta/Current_Additions.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Pointless_Button_V2.0.1-Beta/Current_Additions.txt b/Pointless_Button_V2.0.1-Beta/Current_Additions.txt index 4eaebfb..5ac9775 100644 --- a/Pointless_Button_V2.0.1-Beta/Current_Additions.txt +++ b/Pointless_Button_V2.0.1-Beta/Current_Additions.txt @@ -3,6 +3,9 @@ V2.0.1-Beta - ##-##-2022 - +- 11-30-2022 +- Add Firebase Read Entry for Serial Debug Output and Serial Count Output + - 11-30-2022 (I cant remember the date of the first upload of the beta so this is the stuff that was added to this point.) - Added LED Success / Fail Indicators for Boot and Updates - Added Current Connected SSID Firebase String From a3dc1797ecc3f1e1fca9dec7d69c2d291a74ad7a Mon Sep 17 00:00:00 2001 From: BinTechLLC <51284647+BinTechLLC@users.noreply.github.com> Date: Wed, 30 Nov 2022 23:48:44 -0600 Subject: [PATCH 07/15] Update to current beta version Add Firebase Read Entry for Serial Debug Output and Serial Count Output --- .../Pointless_Button_V2.0.1-Beta.ino | 342 +++++++++++------- 1 file changed, 208 insertions(+), 134 deletions(-) diff --git a/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino b/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino index 8c687da..07fba8d 100644 --- a/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino +++ b/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino @@ -13,6 +13,7 @@ - (Not going to add, have had a lot of people mash multiple / all buttons at a time, would cause an unwanted reboot. ##Add Button Combo to Trigger a Reboot - Add Current SSID String and Firebase Entry - Move Boot Cycle to its own String and Firebase Entry + - Add Firebase Read Entry for Serial Debug Output and Serial Count Output - *Add Remote LED Test Trigger - *Local Web GUI - * @@ -29,7 +30,8 @@ String currentReleaseVersionNumber; String currentBetaReleaseVersionNumber; int writeAsNetPB = false; // Set this to true if creating new node. String pbName = "PB001-Alpha"; -int serialDebugOutput = true; +String serialDebugOutput; +String serialCountOutput; //----------------------------------------------------------------------------------------------------------------------- // Libraries //----------------------------------------------------------------------------------------------------------------------- @@ -38,12 +40,12 @@ int serialDebugOutput = true; //----------------------------------------------------------------------------------------------------------------------- // Credentials and Links //----------------------------------------------------------------------------------------------------------------------- -#define FIREBASE_HOST "https://YourRTDHostname-default-rtdb.firebaseio.com" -#define FIREBASE_AUTH "YourAPIKey" -const char* ssid2 = "SSIDName1"; -const char* ssidpass2 = "SSIDPassword1"; -const char* ssid1 = "SSIDName2"; -const char* ssidpass1 = "SSIDPassword2"; + #define FIREBASE_HOST "https://YourRTDHostname-default-rtdb.firebaseio.com" + #define FIREBASE_AUTH "YourAPIKey" + const char* ssid2 = "SSIDName1"; + const char* ssidpass2 = "SSIDPassword1"; + const char* ssid1 = "SSIDName2"; + const char* ssidpass1 = "SSIDPassword2"; const char* externalHostname = "api.ipify.org"; //----------------------------------------------------------------------------------------------------------------------- // Definitions and States @@ -159,7 +161,7 @@ void wifiFirstConnect() { } if (connectResetCount <= 19) { if (connectRunCommand == 0) { - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.println(String("Connecting to ") + ssid1); } WiFi.disconnect(); @@ -174,7 +176,7 @@ void wifiFirstConnect() { connectRunCommand = 2; } if (connectRunCommand == 2) { - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.println(String("Connecting to ") + ssid2); } WiFi.disconnect(); @@ -185,7 +187,7 @@ void wifiFirstConnect() { } } else if (connectResetCount >= 40) { - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.println("Resetting"); } delay(1000); @@ -199,13 +201,13 @@ void wifiFirstConnect() { WiFi.setSleep(false); Serial.println("Getting Internal IP."); lip = WiFi.localIP(); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.println(lip); } delay(500); Serial.println("Getting External IP."); String(eip) = getExternalIP(); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.println(eip); } digitalWrite(greenLED1, LOW); @@ -225,7 +227,7 @@ void wifiFirstConnect() { if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/11-Default_System_Delay_In_Milliseconds")) { // This Will Read The Directory defaultSystemDelayInMilliseconds = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Default System Delay In Milliseconds, "); Serial.println(defaultSystemDelayInMilliseconds); @@ -245,7 +247,7 @@ void wifiFirstConnect() { if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/12-Default_Update_Delay_In_Seconds")) { // This Will Read The Directory defaultUpdateDelayInSeconds = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Default Update Delay In Seconds."); Serial.println(defaultUpdateDelayInSeconds); } @@ -264,7 +266,7 @@ void wifiFirstConnect() { if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/13-Default_Firebase_Write_Delay")) { // This Will Read The Directory defaultFirebaseWriteDelay = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Default Firebase Write Delay, "); Serial.println(defaultFirebaseWriteDelay); } @@ -283,7 +285,7 @@ void wifiFirstConnect() { if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/14-Default_Firebase_Read_Delay")) { // This Will Read The Directory defaultFirebaseReadDelay = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Default Firebase Read Delay, "); Serial.println(defaultFirebaseReadDelay); } @@ -302,7 +304,7 @@ void wifiFirstConnect() { if (Firebase.getString(fbdo, "/00-Global/00-Current_Release_Number")) { // This Will Read The Directory currentReleaseVersionNumber = fbdo.stringData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Current Release Version Number, "); Serial.println(currentReleaseVersionNumber); } @@ -321,7 +323,7 @@ void wifiFirstConnect() { if (Firebase.getString(fbdo, "/00-Global/01-Current_Beta_Release_Number")) { // This Will Read The Directory currentBetaReleaseVersionNumber = fbdo.stringData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Current Beta Release Version Number, "); Serial.println(currentBetaReleaseVersionNumber); } @@ -337,28 +339,28 @@ void wifiFirstConnect() { if (currentReleaseVersionNumber == currentLocalVersionNumber) { digitalWrite(greenLED1, LOW); digitalWrite(greenLED2, HIGH); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.println("# # # # # You are running the most recent version."); Serial.println(String("Current Local: ") + currentLocalVersionNumber); Serial.println(String("Current Release: ") + currentReleaseVersionNumber); } } else if (currentReleaseVersionNumber != currentLocalVersionNumber) { - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.println("# # # # # Your version does not match the current version."); Serial.println(String("Current Local: ") + currentLocalVersionNumber); Serial.println(String("Current Release: ") + currentReleaseVersionNumber); } } if (currentReleaseVersionNumber == currentBetaReleaseVersionNumber) { - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.println("# # # # # There are no Beta versions available."); Serial.println(String("Current Release: ") + currentReleaseVersionNumber); Serial.println(String("Current Beta: ") + currentBetaReleaseVersionNumber); } } else if (currentReleaseVersionNumber != currentBetaReleaseVersionNumber) { - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.println("# # # # # There is a newer Beta version available."); Serial.println(String("Current Release: ") + currentReleaseVersionNumber); Serial.println(String("Current Beta: ") + currentBetaReleaseVersionNumber); @@ -371,7 +373,7 @@ void wifiFirstConnect() { if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/15-Port_Number")) { // This Will Read The Directory portNumber = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Port Number, "); Serial.println(portNumber); } @@ -390,7 +392,7 @@ void wifiFirstConnect() { if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/16-WiFi_Reset_Cycles")) { // This Will Read The Directory wifiResetCycles = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of WiFi Reset Cycles, "); Serial.println(wifiResetCycles); } @@ -409,13 +411,13 @@ void wifiFirstConnect() { if (Firebase.getString(fbdo, "/01-Counters/" + pbName + "/19-Reboot_Node")) { // This Will Read The Directory rebootNode = fbdo.stringData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Reboot Node, "); Serial.println(rebootNode); } firebaseCycle = 9; if (rebootNode == "true") { - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.println("Reboot Triggered Remotely"); } delay(1000); @@ -435,7 +437,7 @@ void wifiFirstConnect() { if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/01-Count1")) { // This Will Read The "/01-....." Directory g1Count = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Green 1 Count, "); Serial.println(g1Count); } @@ -454,7 +456,7 @@ void wifiFirstConnect() { if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/02-Count2")) { // This Will Read The "/02-....." Directory g2Count = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Green 2 Count, "); Serial.println(g2Count); } @@ -473,7 +475,7 @@ void wifiFirstConnect() { if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/03-Count3")) { // This Will Read The "/03-....." Directory r1Count = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Red 1 Count, "); Serial.println(r1Count); } @@ -492,7 +494,7 @@ void wifiFirstConnect() { if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/04-Count4")) { // This Will Read The "/04-....." Directory r2Count = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Red 2 Count, "); Serial.println(r2Count); } @@ -504,23 +506,16 @@ void wifiFirstConnect() { bootErrorCount ++; } } - //----------------------------------------------------------------------------------------------------------------------- Read Count 10 (Boot Cycles) + //----------------------------------------------------------------------------------------------------------------------- Read Boot Cycles while (firebaseCycle == 13) { digitalWrite(greenLED1, LOW); digitalWrite(greenLED2, HIGH); if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/22-Boot_Count")) { // This Will Read The "/04-....." Directory bootCycles = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Boot Cycles, "); Serial.println(bootCycles); - if (isRunning == 0) { - writeBootCycles = true; - isRunning = 1; - } - else { - writeBootCycles = false; - } } firebaseCycle = 14; } @@ -531,9 +526,49 @@ void wifiFirstConnect() { bootErrorCount ++; } } + //----------------------------------------------------------------------------------------------------------------------- Read Serial Debug Output Setting + while (firebaseCycle == 14) { + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + if (Firebase.getString(fbdo, "/01-Counters/" + pbName + "/23-Serial_Debug_Output")) { // This Will Read The "/04-....." Directory + serialDebugOutput = fbdo.stringData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == "true") { + Serial.print("Read Successful of Serial Debug Output, "); + Serial.println(serialDebugOutput); + } + firebaseCycle = 15; + } + else { + Serial.println("Read Failed of Serial Debug Output."); + writeBootCycles = false; + firebaseCycle = 14; + bootErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Count Output Setting + while (firebaseCycle == 15) { + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + if (Firebase.getString(fbdo, "/01-Counters/" + pbName + "/24-Serial_Count_Output")) { // This Will Read The "/04-....." Directory + serialCountOutput = fbdo.stringData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == "true") { + Serial.print("Read Successful of Serial Count Output, "); + Serial.println(serialCountOutput); + } + firebaseCycle = 16; + } + else { + Serial.println("Read Failed of Serial Count Output."); + writeBootCycles = false; + firebaseCycle = 15; + bootErrorCount ++; + } + } //----------------------------------------------------------------------------------------------------------------------- #### WRITE FUNCTIONS ############################################### //----------------------------------------------------------------------------------------------------------------------- Write Local Version Number - while (firebaseCycle == 14) { + while (firebaseCycle == 16) { digitalWrite(greenLED1, HIGH); digitalWrite(greenLED2, LOW); if (Firebase.setString(fbdo, "/01-Counters/" + pbName + "/20-Current_Local_Version_Number", currentLocalVersionNumber)) { @@ -542,16 +577,16 @@ void wifiFirstConnect() { Serial.print("Write Successful of Current Local Version Number, "); Serial.println(currentLocalVersionNumber); } - firebaseCycle = 15; + firebaseCycle = 17; } else { Serial.println("Write Failed of Current Local Version Number."); - firebaseCycle = 14; + firebaseCycle = 16; bootErrorCount ++; } } //----------------------------------------------------------------------------------------------------------------------- Write Locak IP - while (firebaseCycle == 15) { + while (firebaseCycle == 17) { digitalWrite(greenLED1, LOW); digitalWrite(greenLED2, HIGH); String lip2 = WiFi.localIP().toString(); @@ -561,16 +596,16 @@ void wifiFirstConnect() { Serial.print("Write Successful of Local IP, "); Serial.println(lip); } - firebaseCycle = 16; + firebaseCycle = 18; } else { Serial.println("Write Failed of Local IP."); - firebaseCycle = 15; + firebaseCycle = 17; bootErrorCount ++; } } //----------------------------------------------------------------------------------------------------------------------- Write External IP - while (firebaseCycle == 16) { + while (firebaseCycle == 18) { digitalWrite(greenLED1, HIGH); digitalWrite(greenLED2, LOW); if (Firebase.setString(fbdo, "/01-Counters/" + pbName + "/18-ExternalIP", eip)) { @@ -579,65 +614,60 @@ void wifiFirstConnect() { Serial.print("Write Successful of External IP, "); Serial.println(eip); } - firebaseCycle = 17; + firebaseCycle = 19; } else { Serial.println("Write Failed of External IP."); - firebaseCycle = 16; + firebaseCycle = 18; bootErrorCount ++; } } //----------------------------------------------------------------------------------------------------------------------- Write Boot Cycles - while (firebaseCycle == 17) { + while (firebaseCycle == 19) { digitalWrite(greenLED1, LOW); digitalWrite(greenLED2, HIGH); - if (writeBootCycles == true) { - if (bootCycles >= 1) { - delay(5); - bootCycles ++; - delay(5); - if (Firebase.setString(fbdo, "/01-Counters/" + pbName + "/21-Current_Connected_SSID", currentSSID)) { - delay(defaultFirebaseWriteDelay); // Defined At The Top - if (serialDebugOutput) { - Serial.print("Write Successful of Current SSID."); - Serial.println(currentSSID); - } - firebaseCycle = 18; - } - else { - Serial.println("Write Failed of Current SSID."); - firebaseCycle = 17; - bootErrorCount ++; + if (bootCycles >= 1) { + delay(5); + bootCycles + 1; + delay(5); + if (Firebase.setString(fbdo, "/01-Counters/" + pbName + "/21-Current_Connected_SSID", currentSSID)) { + delay(defaultFirebaseWriteDelay); // Defined At The Top + if (serialDebugOutput) { + Serial.print("Write Successful of Current SSID: "); + Serial.println(currentSSID); } + firebaseCycle = 20; + } + else { + Serial.println("Write Failed of Current SSID."); + firebaseCycle = 19; + bootErrorCount ++; } } } //----------------------------------------------------------------------------------------------------------------------- Write Boot Cycles - while (firebaseCycle == 18) { + while (firebaseCycle == 20) { digitalWrite(greenLED1, LOW); digitalWrite(greenLED2, HIGH); - if (writeBootCycles == true) { - if (bootCycles >= 1) { - delay(5); - bootCycles ++; - delay(5); - if (Firebase.setInt(fbdo, "/01-Counters/" + pbName + "/22-Boot_Count", bootCycles)) { - delay(defaultFirebaseWriteDelay); // Defined At The Top - if (serialDebugOutput) { - Serial.print("Write Successful of Boot Cycles."); - Serial.println(bootCycles); - } - firebaseCycle = 19; - } - else { - Serial.println("Write Failed of Boot Cycles."); - firebaseCycle = 18; - bootErrorCount ++; + if (bootCycles >= 1) { + delay(5); + bootCycles ++; + delay(5); + if (Firebase.setInt(fbdo, "/01-Counters/" + pbName + "/22-Boot_Count", bootCycles)) { + delay(defaultFirebaseWriteDelay); // Defined At The Top + if (serialDebugOutput) { + Serial.print("Write Successful of Boot Cycles."); + Serial.println(bootCycles); } + firebaseCycle = 21; + } + else { + Serial.println("Write Failed of Boot Cycles."); + firebaseCycle = 20; + bootErrorCount ++; } } } - digitalWrite(greenLED1, HIGH); digitalWrite(greenLED2, HIGH); delay(500); @@ -671,9 +701,9 @@ void wifiFirstConnect() { //----------------------------------------------------------------------------------------------------------------------- void writeFirebaseUpdate() { updateErrorCount = 0; - if (serialDebugOutput == true) { - Serial.println(" # # # # # Firebase Update Triggered"); - } + if (serialDebugOutput == "true") { + Serial.println(" # # # # # Firebase Update Triggered"); + } //----------------------------------------------------------------------------------------------------------------------- Read Default System Delay In Milliseconds. while (firebaseCycle == 0) { digitalWrite(greenLED1, HIGH); @@ -681,7 +711,7 @@ void writeFirebaseUpdate() { if (Firebase.getString(fbdo, "/01-Counters/" + pbName + "/00-PB_Name")) { // This Will Read The Directory String pbNameRead = fbdo.stringData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of PB Name, "); Serial.println(pbNameRead); } @@ -700,7 +730,7 @@ void writeFirebaseUpdate() { if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/11-Default_System_Delay_In_Milliseconds")) { // This Will Read The Directory defaultSystemDelayInMilliseconds = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Default System Delay In Milliseconds, "); Serial.println(defaultSystemDelayInMilliseconds); } @@ -719,7 +749,7 @@ void writeFirebaseUpdate() { if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/12-Default_Update_Delay_In_Seconds")) { // This Will Read The Directory defaultUpdateDelayInSeconds = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Default Update Delay In Seconds, "); Serial.println(defaultUpdateDelayInSeconds); } @@ -738,7 +768,7 @@ void writeFirebaseUpdate() { if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/13-Default_Firebase_Write_Delay")) { // This Will Read The Directory defaultFirebaseWriteDelay = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Default Firebase Write Delay, "); Serial.println(defaultFirebaseWriteDelay); } @@ -757,7 +787,7 @@ void writeFirebaseUpdate() { if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/14-Default_Firebase_Read_Delay")) { // This Will Read The Directory defaultFirebaseReadDelay = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Default Firebase Read Delay, "); Serial.println(defaultFirebaseReadDelay); } @@ -776,7 +806,7 @@ void writeFirebaseUpdate() { if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/15-Port_Number")) { // This Will Read The Directory portNumber = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Port Number, "); Serial.println(portNumber); } @@ -795,7 +825,7 @@ void writeFirebaseUpdate() { if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/16-WiFi_Reset_Cycles")) { // This Will Read The Directory wifiResetCycles = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of WiFi Reset Cycles, "); Serial.println(wifiResetCycles); } @@ -814,13 +844,13 @@ void writeFirebaseUpdate() { if (Firebase.getString(fbdo, "/01-Counters/" + pbName + "/19-Reboot_Node")) { // This Will Read The Directory rebootNode = fbdo.stringData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Reboot Node, "); Serial.println(rebootNode); } firebaseCycle = 8; if (rebootNode == "true") { - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.println("Reboot Triggered Remotely"); } delay(1000); @@ -833,85 +863,125 @@ void writeFirebaseUpdate() { updateErrorCount ++; } } - //----------------------------------------------------------------------------------------------------------------------- Read Count 1 + //----------------------------------------------------------------------------------------------------------------------- Read Serial Debug Output Setting while (firebaseCycle == 8) { + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + if (Firebase.getString(fbdo, "/01-Counters/" + pbName + "/23-Serial_Debug_Output")) { // This Will Read The "/04-....." Directory + serialDebugOutput = fbdo.stringData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == "true") { + Serial.print("Read Successful of Serial Debug Output, "); + Serial.println(serialDebugOutput); + } + firebaseCycle = 9; + } + else { + Serial.println("Read Failed of Serial Debug Output."); + writeBootCycles = false; + firebaseCycle = 8; + bootErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Count Output Setting + while (firebaseCycle == 9) { + digitalWrite(greenLED1, LOW); + digitalWrite(greenLED2, HIGH); + if (Firebase.getString(fbdo, "/01-Counters/" + pbName + "/24-Serial_Count_Output")) { // This Will Read The "/04-....." Directory + serialCountOutput = fbdo.stringData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received + delay(defaultFirebaseReadDelay); + if (serialDebugOutput == "true") { + Serial.print("Read Successful of Serial Count Output, "); + Serial.println(serialCountOutput); + } + firebaseCycle = 10; + } + else { + Serial.println("Read Failed of Serial Count Output."); + writeBootCycles = false; + firebaseCycle = 9; + bootErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Read Count 1 + while (firebaseCycle == 10) { digitalWrite(greenLED1, HIGH); digitalWrite(greenLED2, LOW); if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/01-Count1")) { // This Will Read The "/01-....." Directory g1CountRead = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Green 1 Count, "); Serial.println(g1Count); } - firebaseCycle = 9; + firebaseCycle = 11; } else { Serial.println("Read Failed of Green 1 Count."); - firebaseCycle = 8; + firebaseCycle = 10; updateErrorCount ++; } } //----------------------------------------------------------------------------------------------------------------------- Read Count 2 - while (firebaseCycle == 9) { + while (firebaseCycle == 11) { digitalWrite(greenLED1, LOW); digitalWrite(greenLED2, HIGH); if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/02-Count2")) { // This Will Read The "/02-....." Directory g2CountRead = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Green 2 Count, "); Serial.println(g2Count); } - firebaseCycle = 10; + firebaseCycle = 12; } else { Serial.println("Read Failed of Green 2 Count."); - firebaseCycle = 9; + firebaseCycle = 11; updateErrorCount ++; } } //----------------------------------------------------------------------------------------------------------------------- Read Count 3 - while (firebaseCycle == 10) { + while (firebaseCycle == 12) { digitalWrite(greenLED1, HIGH); digitalWrite(greenLED2, LOW); if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/03-Count3")) { // This Will Read The "/03-....." Directory r1CountRead = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Red 1 Count, "); Serial.println(r1Count); } - firebaseCycle = 11; + firebaseCycle = 13; } else { Serial.println("Read Failed of Red 1 Count."); - firebaseCycle = 10; + firebaseCycle = 12; updateErrorCount ++; } } //----------------------------------------------------------------------------------------------------------------------- Read Count 4 - while (firebaseCycle == 11) { + while (firebaseCycle == 13) { digitalWrite(greenLED1, LOW); digitalWrite(greenLED2, HIGH); if (Firebase.getInt(fbdo, "/01-Counters/" + pbName + "/04-Count4")) { // This Will Read The "/04-....." Directory r2CountRead = fbdo.intData(); // If The Read Was Successful, Count Will Be Updated With The String Data Received delay(defaultFirebaseReadDelay); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.print("Read Successful of Red 2 Count, "); Serial.println(r2Count); } - firebaseCycle = 12; + firebaseCycle = 14; } else { Serial.println("Read Failed of Red 2 Count."); - firebaseCycle = 11; + firebaseCycle = 13; updateErrorCount ++; } } if (g1Count >= (g1CountRead + 1) or g2Count >= (g2CountRead + 1) or r1Count >= (r1CountRead + 1) or r2Count >= (r2CountRead + 1)) { //----------------------------------------------------------------------------------------------------------------------- Write Count 1 - while (firebaseCycle == 12) { + while (firebaseCycle == 14) { digitalWrite(greenLED1, HIGH); digitalWrite(greenLED2, LOW); if (Firebase.setInt(fbdo, "/01-Counters/" + pbName + "/01-Count1", g1Count)) { @@ -920,16 +990,16 @@ void writeFirebaseUpdate() { Serial.print("Write Successful of New Green 1 Count, "); Serial.println(g1Count); } - firebaseCycle = 13; + firebaseCycle = 15; } else { Serial.println("Write Failed of New Green 1 Count."); - firebaseCycle = 12; + firebaseCycle = 14; updateErrorCount ++; } } //----------------------------------------------------------------------------------------------------------------------- Write Count 2 - while (firebaseCycle == 13) { + while (firebaseCycle == 15) { digitalWrite(greenLED1, LOW); digitalWrite(greenLED2, HIGH); if (Firebase.setInt(fbdo, "/01-Counters/" + pbName + "/02-Count2", g2Count)) { @@ -938,16 +1008,16 @@ void writeFirebaseUpdate() { Serial.print("Write Successful of New Green 2 Count, "); Serial.println(g2Count); } - firebaseCycle = 14; + firebaseCycle = 16; } else { Serial.println("Write Failed of New Green 2 Count."); - firebaseCycle = 13; + firebaseCycle = 15; updateErrorCount ++; } } //----------------------------------------------------------------------------------------------------------------------- Write Count 3 - while (firebaseCycle == 14) { + while (firebaseCycle == 16) { digitalWrite(greenLED1, HIGH); digitalWrite(greenLED2, LOW); if (Firebase.setInt(fbdo, "/01-Counters/" + pbName + "/03-Count3", r1Count)) { @@ -956,16 +1026,16 @@ void writeFirebaseUpdate() { Serial.print("Write Successful of New Red 1 Count, "); Serial.println(r1Count); } - firebaseCycle = 15; + firebaseCycle = 17; } else { Serial.println("Write Failed of New Red 1 Count."); - firebaseCycle = 14; + firebaseCycle = 16; updateErrorCount ++; } } //----------------------------------------------------------------------------------------------------------------------- Write Count 4 - while (firebaseCycle == 15) { + while (firebaseCycle == 17) { digitalWrite(greenLED1, LOW); digitalWrite(greenLED2, HIGH); if (Firebase.setInt(fbdo, "/01-Counters/" + pbName + "/04-Count4", r2Count)) { @@ -974,11 +1044,11 @@ void writeFirebaseUpdate() { Serial.print("Write Successful of New Red 2 Count, "); Serial.println(r2Count); } - firebaseCycle = 16; + firebaseCycle = 18; } else { Serial.println("Write Failed of New Red 2 Count."); - firebaseCycle = 15; + firebaseCycle = 17; updateErrorCount ++; } } @@ -1000,7 +1070,6 @@ void writeFirebaseUpdate() { digitalWrite(greenLED2, HIGH); digitalWrite(redLED1, LOW); digitalWrite(redLED2, HIGH); - } delay(500); digitalWrite(greenLED1, LOW); @@ -1077,12 +1146,15 @@ void runButtonLogic() { // Void Setup //----------------------------------------------------------------------------------------------------------------------- void setup() { - if (serialDebugOutput == true) { + serialCountOutput = "true"; + serialDebugOutput = "true"; + firebaseCycle = 0; + if (serialDebugOutput == "true") { Serial.begin(115200); if (!Serial) { - serialDebugOutput = false; + serialDebugOutput = "false"; } - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.println(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "); Serial.println(" - Starting - " + pbName + " New Node Enabled? " + writeAsNetPB); } @@ -1095,7 +1167,7 @@ void setup() { pinMode(greenLED2, OUTPUT); pinMode(redLED1, OUTPUT); pinMode(redLED2, OUTPUT); - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { Serial.println("Testing LEDs"); } digitalWrite(greenLED1, LOW); @@ -1119,13 +1191,15 @@ void loop() { defaultDelayCountCycle ++; if (defaultDelayCountCycle >= 20) { defaultDelayCount ++; - if (serialDebugOutput == true) { - Serial.println(defaultDelayCount); + if (serialDebugOutput == "true") { + if (serialCountOutput == "true") { + Serial.println(defaultDelayCount); + } } defaultDelayCountCycle = 0; } if (defaultDelayCount >= defaultUpdateDelayInSeconds) { - + defaultDelayCount = 0; defaultDelayCountCycle = 0; firebaseCycle = 0; @@ -1138,7 +1212,7 @@ void loop() { currentState = (String("G1: ") + g1Count + String(" G2: ") + g2Count + String(" R1: ") + r1Count + String(" R2: ") + r2Count); runButtonLogic(); //--------------------------------- Print Debug To Serial - if (serialDebugOutput == true) { + if (serialDebugOutput == "true") { if (lastState != currentState) { lastState = currentState; Serial.println(currentState); From 1a1877202ce83ee5a1224e27595fb02435760dee Mon Sep 17 00:00:00 2001 From: BinTechLLC <51284647+BinTechLLC@users.noreply.github.com> Date: Thu, 1 Dec 2022 20:39:17 -0600 Subject: [PATCH 08/15] Update Current_Additions.txt --- Pointless_Button_V2.0.1-Beta/Current_Additions.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Pointless_Button_V2.0.1-Beta/Current_Additions.txt b/Pointless_Button_V2.0.1-Beta/Current_Additions.txt index 5ac9775..649066f 100644 --- a/Pointless_Button_V2.0.1-Beta/Current_Additions.txt +++ b/Pointless_Button_V2.0.1-Beta/Current_Additions.txt @@ -3,6 +3,9 @@ V2.0.1-Beta - ##-##-2022 - +- 12-01-2022 +- Added NETBIOS name configuration to pull from pbName string so it no longer shows "esp32-arduino" on the network. + - 11-30-2022 - Add Firebase Read Entry for Serial Debug Output and Serial Count Output From d4ac4e042578497fbe6ad97f72245cc9c442db51 Mon Sep 17 00:00:00 2001 From: BinTechLLC <51284647+BinTechLLC@users.noreply.github.com> Date: Thu, 1 Dec 2022 20:40:28 -0600 Subject: [PATCH 09/15] Update to current beta version. --- .../Pointless_Button_V2.0.1-Beta.ino | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino b/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino index 07fba8d..97bbde2 100644 --- a/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino +++ b/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino @@ -14,6 +14,7 @@ - Add Current SSID String and Firebase Entry - Move Boot Cycle to its own String and Firebase Entry - Add Firebase Read Entry for Serial Debug Output and Serial Count Output + Added NETBIOS name configuration to pull from pbName string so it no longer shows "esp32-arduino" on the network. - *Add Remote LED Test Trigger - *Local Web GUI - * @@ -40,12 +41,20 @@ String serialCountOutput; //----------------------------------------------------------------------------------------------------------------------- // Credentials and Links //----------------------------------------------------------------------------------------------------------------------- - #define FIREBASE_HOST "https://YourRTDHostname-default-rtdb.firebaseio.com" - #define FIREBASE_AUTH "YourAPIKey" - const char* ssid2 = "SSIDName1"; - const char* ssidpass2 = "SSIDPassword1"; - const char* ssid1 = "SSIDName2"; - const char* ssidpass1 = "SSIDPassword2"; +/* +#define FIREBASE_HOST "https://YourRTDHostname-default-rtdb.firebaseio.com" +#define FIREBASE_AUTH "YourAPIKey" +const char* ssid2 = "SSIDName1"; +const char* ssidpass2 = "SSIDPassword1"; +const char* ssid1 = "SSIDName2"; +const char* ssidpass1 = "SSIDPassword2"; +*/ +#define FIREBASE_HOST "https://pointlessbuttonv2-2022-default-rtdb.firebaseio.com" +#define FIREBASE_AUTH "Bddm9oBrsBKmjzKv9iUtwqO7JjpgJBwb4ObBqOra" +const char* ssid2 = "BinTech LLC"; +const char* ssidpass2 = "FuckYouBitch123!@#"; +const char* ssid1 = "KB-N20U"; +const char* ssidpass1 = "RollYourButt123!@#"; const char* externalHostname = "api.ipify.org"; //----------------------------------------------------------------------------------------------------------------------- // Definitions and States @@ -149,6 +158,11 @@ String getExternalIP() { void wifiFirstConnect() { g1LEDState = 1; connectResetCount = 0; + //WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE); + WiFi.setHostname(pbName.c_str()); + if (serialDebugOutput == "true") { + Serial.println(String("NETBIOS Name: ")+String(pbName)); + } while (WiFi.status() != WL_CONNECTED) { connectResetCount ++ ; if (g1LEDState == 1) { @@ -164,7 +178,7 @@ void wifiFirstConnect() { if (serialDebugOutput == "true") { Serial.println(String("Connecting to ") + ssid1); } - WiFi.disconnect(); + WiFi.disconnect(true, true); delay(500); WiFi.begin(ssid1, ssidpass1); currentSSID = ssid1; @@ -179,7 +193,7 @@ void wifiFirstConnect() { if (serialDebugOutput == "true") { Serial.println(String("Connecting to ") + ssid2); } - WiFi.disconnect(); + WiFi.disconnect(true, true); delay(500); WiFi.begin(ssid2, ssidpass2); currentSSID = ssid2; From df0599fc3ac87c068ecd5c2239a212b73dc31d56 Mon Sep 17 00:00:00 2001 From: BinTechLLC <51284647+BinTechLLC@users.noreply.github.com> Date: Sat, 3 Dec 2022 00:35:01 -0600 Subject: [PATCH 10/15] Update Current_Additions.txt --- Pointless_Button_V2.0.1-Beta/Current_Additions.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Pointless_Button_V2.0.1-Beta/Current_Additions.txt b/Pointless_Button_V2.0.1-Beta/Current_Additions.txt index 649066f..2975e79 100644 --- a/Pointless_Button_V2.0.1-Beta/Current_Additions.txt +++ b/Pointless_Button_V2.0.1-Beta/Current_Additions.txt @@ -3,6 +3,9 @@ V2.0.1-Beta - ##-##-2022 - +- 12-03-2022 +- Added NTP Read for Time Recording of Boot and Update times in Firebase + - 12-01-2022 - Added NETBIOS name configuration to pull from pbName string so it no longer shows "esp32-arduino" on the network. From 004a760a689a6a932fdaeaf72455e19a2b3e8d19 Mon Sep 17 00:00:00 2001 From: BinTechLLC <51284647+BinTechLLC@users.noreply.github.com> Date: Sat, 3 Dec 2022 00:36:49 -0600 Subject: [PATCH 11/15] Update to current beta version --- .../Pointless_Button_V2.0.1-Beta.ino | 163 +++++++++++++----- 1 file changed, 122 insertions(+), 41 deletions(-) diff --git a/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino b/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino index 97bbde2..062a444 100644 --- a/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino +++ b/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino @@ -38,24 +38,28 @@ String serialCountOutput; //----------------------------------------------------------------------------------------------------------------------- #include #include +#include "time.h" //----------------------------------------------------------------------------------------------------------------------- // Credentials and Links //----------------------------------------------------------------------------------------------------------------------- /* -#define FIREBASE_HOST "https://YourRTDHostname-default-rtdb.firebaseio.com" -#define FIREBASE_AUTH "YourAPIKey" -const char* ssid2 = "SSIDName1"; -const char* ssidpass2 = "SSIDPassword1"; -const char* ssid1 = "SSIDName2"; -const char* ssidpass1 = "SSIDPassword2"; + #define FIREBASE_HOST "https://YourRTDHostname-default-rtdb.firebaseio.com" + #define FIREBASE_AUTH "YourAPIKey" + const char* ssid2 = "SSIDName1"; + const char* ssidpass2 = "SSIDPassword1"; + const char* ssid1 = "SSIDName2"; + const char* ssidpass1 = "SSIDPassword2"; */ #define FIREBASE_HOST "https://pointlessbuttonv2-2022-default-rtdb.firebaseio.com" #define FIREBASE_AUTH "Bddm9oBrsBKmjzKv9iUtwqO7JjpgJBwb4ObBqOra" -const char* ssid2 = "BinTech LLC"; -const char* ssidpass2 = "FuckYouBitch123!@#"; const char* ssid1 = "KB-N20U"; const char* ssidpass1 = "RollYourButt123!@#"; +const char* ssid2 = "BinTech LLC"; +const char* ssidpass2 = "FuckYouBitch123!@#"; const char* externalHostname = "api.ipify.org"; +const char* ntpServer = "0.debian.pool.ntp.org"; +const long gmtOffset_sec = -21600; // -21600 is GMT -6 or Central Time +const int daylightOffset_sec = 3600; // 3600 I have not messed with this yet //----------------------------------------------------------------------------------------------------------------------- // Definitions and States //----------------------------------------------------------------------------------------------------------------------- @@ -110,6 +114,14 @@ int bootErrorCount; int updateErrorCount; String currentSSID; String rebootNode; +String currentTime; +char yearInt[5]; +char monthInt[10]; +char dayInt[3]; +char dowInt[10]; +char hourInt[3]; +char minuteInt[3]; +char secondInt[3]; WiFiServer server(portNumber); FirebaseData fbdo; //----------------------------------------------------------------------------------------------------------------------- @@ -152,6 +164,32 @@ String getExternalIP() { } return line; } + +//----------------------------------------------------------------------------------------------------------------------- +// Void Get Time and Date +//----------------------------------------------------------------------------------------------------------------------- +void getTime() { + struct tm timeinfo; + while (!getLocalTime(&timeinfo)) { + Serial.println("Failed to obtain time"); + delay(500); + //return; + } + strftime(yearInt, 5, "%Y", &timeinfo); + strftime(monthInt, 10, "%m", &timeinfo); + strftime(dayInt, 3, "%d", &timeinfo); + strftime(dowInt, 10, "%A", &timeinfo); + strftime(hourInt, 3, "%H", &timeinfo); + strftime(minuteInt, 3, "%M", &timeinfo); + strftime(secondInt, 3, "%S", &timeinfo); + + currentTime = (dowInt + String("_") + monthInt + String("-") + dayInt + String("-") + yearInt + String("_") + hourInt + String(":") + minuteInt + String(":") + secondInt); + + if (serialCountOutput == "true") { + Serial.println(dowInt + String("_") + monthInt + String("-") + dayInt + String("-") + yearInt + String("_") + hourInt + String(":") + minuteInt + String(":") + secondInt); + } + +} //----------------------------------------------------------------------------------------------------------------------- // Void WiFi First Connect //----------------------------------------------------------------------------------------------------------------------- @@ -161,7 +199,7 @@ void wifiFirstConnect() { //WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE); WiFi.setHostname(pbName.c_str()); if (serialDebugOutput == "true") { - Serial.println(String("NETBIOS Name: ")+String(pbName)); + Serial.println(String("NETBIOS Name: ") + String(pbName)); } while (WiFi.status() != WL_CONNECTED) { connectResetCount ++ ; @@ -233,6 +271,9 @@ void wifiFirstConnect() { digitalWrite(greenLED1, HIGH); digitalWrite(greenLED2, LOW); delay(500); + Serial.println("Getting Time and Date"); + getTime(); + delay(500); Serial.println("Reading Firebase Initial Values."); //----------------------------------------------------------------------------------------------------------------------- Read Default System Delay In Milliseconds. while (firebaseCycle == 0) { @@ -581,8 +622,26 @@ void wifiFirstConnect() { } } //----------------------------------------------------------------------------------------------------------------------- #### WRITE FUNCTIONS ############################################### - //----------------------------------------------------------------------------------------------------------------------- Write Local Version Number + //----------------------------------------------------------------------------------------------------------------------- Write Boot Time while (firebaseCycle == 16) { + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + if (Firebase.setString(fbdo, "/01-Counters/" + pbName + "/25-Last_Boot_Time", currentTime)) { + delay(defaultFirebaseWriteDelay); // Defined At The Top + if (serialDebugOutput) { + Serial.print("Write Successful of Last Boot Time, "); + Serial.println(currentTime); + } + firebaseCycle = 17; + } + else { + Serial.println("Write Failed of Last Boot Time."); + firebaseCycle = 16; + bootErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Write Local Version Number + while (firebaseCycle == 17) { digitalWrite(greenLED1, HIGH); digitalWrite(greenLED2, LOW); if (Firebase.setString(fbdo, "/01-Counters/" + pbName + "/20-Current_Local_Version_Number", currentLocalVersionNumber)) { @@ -591,16 +650,16 @@ void wifiFirstConnect() { Serial.print("Write Successful of Current Local Version Number, "); Serial.println(currentLocalVersionNumber); } - firebaseCycle = 17; + firebaseCycle = 18; } else { Serial.println("Write Failed of Current Local Version Number."); - firebaseCycle = 16; + firebaseCycle = 17; bootErrorCount ++; } } - //----------------------------------------------------------------------------------------------------------------------- Write Locak IP - while (firebaseCycle == 17) { + //----------------------------------------------------------------------------------------------------------------------- Write Local IP + while (firebaseCycle == 18) { digitalWrite(greenLED1, LOW); digitalWrite(greenLED2, HIGH); String lip2 = WiFi.localIP().toString(); @@ -610,16 +669,16 @@ void wifiFirstConnect() { Serial.print("Write Successful of Local IP, "); Serial.println(lip); } - firebaseCycle = 18; + firebaseCycle = 19; } else { Serial.println("Write Failed of Local IP."); - firebaseCycle = 17; + firebaseCycle = 18; bootErrorCount ++; } } //----------------------------------------------------------------------------------------------------------------------- Write External IP - while (firebaseCycle == 18) { + while (firebaseCycle == 19) { digitalWrite(greenLED1, HIGH); digitalWrite(greenLED2, LOW); if (Firebase.setString(fbdo, "/01-Counters/" + pbName + "/18-ExternalIP", eip)) { @@ -628,16 +687,16 @@ void wifiFirstConnect() { Serial.print("Write Successful of External IP, "); Serial.println(eip); } - firebaseCycle = 19; + firebaseCycle = 20; } else { Serial.println("Write Failed of External IP."); - firebaseCycle = 18; + firebaseCycle = 19; bootErrorCount ++; } } - //----------------------------------------------------------------------------------------------------------------------- Write Boot Cycles - while (firebaseCycle == 19) { + //----------------------------------------------------------------------------------------------------------------------- Write Current SSID + while (firebaseCycle == 20) { digitalWrite(greenLED1, LOW); digitalWrite(greenLED2, HIGH); if (bootCycles >= 1) { @@ -650,17 +709,17 @@ void wifiFirstConnect() { Serial.print("Write Successful of Current SSID: "); Serial.println(currentSSID); } - firebaseCycle = 20; + firebaseCycle = 21; } else { Serial.println("Write Failed of Current SSID."); - firebaseCycle = 19; + firebaseCycle = 20; bootErrorCount ++; } } } //----------------------------------------------------------------------------------------------------------------------- Write Boot Cycles - while (firebaseCycle == 20) { + while (firebaseCycle == 21) { digitalWrite(greenLED1, LOW); digitalWrite(greenLED2, HIGH); if (bootCycles >= 1) { @@ -673,11 +732,11 @@ void wifiFirstConnect() { Serial.print("Write Successful of Boot Cycles."); Serial.println(bootCycles); } - firebaseCycle = 21; + firebaseCycle = 22; } else { Serial.println("Write Failed of Boot Cycles."); - firebaseCycle = 20; + firebaseCycle = 21; bootErrorCount ++; } } @@ -993,9 +1052,28 @@ void writeFirebaseUpdate() { updateErrorCount ++; } } + if (g1Count >= (g1CountRead + 1) or g2Count >= (g2CountRead + 1) or r1Count >= (r1CountRead + 1) or r2Count >= (r2CountRead + 1)) { - //----------------------------------------------------------------------------------------------------------------------- Write Count 1 + //----------------------------------------------------------------------------------------------------------------------- Write Last Update Time while (firebaseCycle == 14) { + digitalWrite(greenLED1, HIGH); + digitalWrite(greenLED2, LOW); + if (Firebase.setString(fbdo, "/01-Counters/" + pbName + "/26-Last_Update_Time", currentTime)) { + delay(defaultFirebaseWriteDelay); // Defined At The Top + if (serialDebugOutput) { + Serial.print("Write Successful of Update Time, "); + Serial.println(currentTime); + } + firebaseCycle = 15; + } + else { + Serial.println("Write Failed of Update Time."); + firebaseCycle = 14; + updateErrorCount ++; + } + } + //----------------------------------------------------------------------------------------------------------------------- Write Count 1 + while (firebaseCycle == 15) { digitalWrite(greenLED1, HIGH); digitalWrite(greenLED2, LOW); if (Firebase.setInt(fbdo, "/01-Counters/" + pbName + "/01-Count1", g1Count)) { @@ -1004,16 +1082,16 @@ void writeFirebaseUpdate() { Serial.print("Write Successful of New Green 1 Count, "); Serial.println(g1Count); } - firebaseCycle = 15; + firebaseCycle = 16; } else { Serial.println("Write Failed of New Green 1 Count."); - firebaseCycle = 14; + firebaseCycle = 15; updateErrorCount ++; } } //----------------------------------------------------------------------------------------------------------------------- Write Count 2 - while (firebaseCycle == 15) { + while (firebaseCycle == 16) { digitalWrite(greenLED1, LOW); digitalWrite(greenLED2, HIGH); if (Firebase.setInt(fbdo, "/01-Counters/" + pbName + "/02-Count2", g2Count)) { @@ -1022,16 +1100,16 @@ void writeFirebaseUpdate() { Serial.print("Write Successful of New Green 2 Count, "); Serial.println(g2Count); } - firebaseCycle = 16; + firebaseCycle = 17; } else { Serial.println("Write Failed of New Green 2 Count."); - firebaseCycle = 15; + firebaseCycle = 16; updateErrorCount ++; } } //----------------------------------------------------------------------------------------------------------------------- Write Count 3 - while (firebaseCycle == 16) { + while (firebaseCycle == 17) { digitalWrite(greenLED1, HIGH); digitalWrite(greenLED2, LOW); if (Firebase.setInt(fbdo, "/01-Counters/" + pbName + "/03-Count3", r1Count)) { @@ -1040,16 +1118,16 @@ void writeFirebaseUpdate() { Serial.print("Write Successful of New Red 1 Count, "); Serial.println(r1Count); } - firebaseCycle = 17; + firebaseCycle = 18; } else { Serial.println("Write Failed of New Red 1 Count."); - firebaseCycle = 16; + firebaseCycle = 17; updateErrorCount ++; } } //----------------------------------------------------------------------------------------------------------------------- Write Count 4 - while (firebaseCycle == 17) { + while (firebaseCycle == 18) { digitalWrite(greenLED1, LOW); digitalWrite(greenLED2, HIGH); if (Firebase.setInt(fbdo, "/01-Counters/" + pbName + "/04-Count4", r2Count)) { @@ -1058,11 +1136,11 @@ void writeFirebaseUpdate() { Serial.print("Write Successful of New Red 2 Count, "); Serial.println(r2Count); } - firebaseCycle = 18; + firebaseCycle = 19; } else { Serial.println("Write Failed of New Red 2 Count."); - firebaseCycle = 17; + firebaseCycle = 18; updateErrorCount ++; } } @@ -1163,6 +1241,7 @@ void setup() { serialCountOutput = "true"; serialDebugOutput = "true"; firebaseCycle = 0; + configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); //init and get the time from ntp and store it locally if (serialDebugOutput == "true") { Serial.begin(115200); if (!Serial) { @@ -1181,21 +1260,23 @@ void setup() { pinMode(greenLED2, OUTPUT); pinMode(redLED1, OUTPUT); pinMode(redLED2, OUTPUT); - if (serialDebugOutput == "true") { - Serial.println("Testing LEDs"); - } digitalWrite(greenLED1, LOW); digitalWrite(greenLED2, LOW); digitalWrite(redLED1, LOW); digitalWrite(redLED2, LOW); WiFi.disconnect(); wifiFirstConnect(); + getTime(); + if (serialDebugOutput == "true") { + Serial.println("Testing LEDs"); + } testLEDs(); } //----------------------------------------------------------------------------------------------------------------------- // Void Loop //----------------------------------------------------------------------------------------------------------------------- void loop() { + getTime(); writeBootCycles = 0; if (WiFi.status() != 3) { WiFi.disconnect(); From ddaa2030ecf1a5c0846807db9670f8794574049c Mon Sep 17 00:00:00 2001 From: BinTechLLC <51284647+BinTechLLC@users.noreply.github.com> Date: Sat, 3 Dec 2022 00:44:06 -0600 Subject: [PATCH 12/15] Update README.txt --- README.txt | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/README.txt b/README.txt index c0c814f..db831fb 100644 --- a/README.txt +++ b/README.txt @@ -30,25 +30,26 @@ Just a heads up, this is my master notes doc and will change quite frequently wh - Basic Count Functions - Basic Firebase Write and Update Functions - Release and Beta Version Checker - - - - * - V2.0.1 - *Add LED Success / Fail Indicators for Boot and Updates - - *Add Button Combo to Trigger a Reboot - - *Add Current SSID String and Firebase Entry - - *Move Boot Cycle to its own String and FIrebase Entry - - *Local Web GUI + V2.0.1 - Add LED Success / Fail Indicators for Boot and Updates + - (Not going to add, have had a lot of people mash multiple / all buttons at a time, would cause an unwanted reboot. + ## Add Button Combo to Trigger a Reboot + - Add Current SSID String and Firebase Entry + - Move Boot Cycle to its own String and Firebase Entry + - Add Firebase Read Entry for Serial Debug Output and Serial Count Output + - Added NETBIOS name configuration to pull from pbName string so it no longer shows "esp32-arduino" on the network. + - Add NTP Read and strftime Variables + - Add Last Boot Time and Last Update Time Firebase Entries - *Add Remote LED Test Trigger - - * - V2.1.0 - *Create Python Intermediate Server For Time Keeping - - *Last Boot Time Recording - - *Last Update Time Recording + V2.0.2 - *Local Web GUI + - *Maybe App functionality - * - - + + + V2.1.0 - * # ---------------------------------------------------------------------------------------------------------- @@ -57,6 +58,8 @@ Just a heads up, this is my master notes doc and will change quite frequently wh V2.1.0 - Things I want for next major version. + V2.0.2 - Web GUI and possibly App integration. + V2.0.1 - This is going to be a lot of extra functions and indicators for things normally moditored over serial. V2.0.0 - The 1.0.0 through 1.10.10 versions are basically all in version 2.0.0 as the base version. I do plan on updating From 3dd8675fb1f3e62145642ce4df581410f2570450 Mon Sep 17 00:00:00 2001 From: BinTechLLC <51284647+BinTechLLC@users.noreply.github.com> Date: Sat, 3 Dec 2022 13:38:53 -0600 Subject: [PATCH 13/15] Update Pointless_Button_V2.0.1-Beta.ino --- .../Pointless_Button_V2.0.1-Beta.ino | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino b/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino index 062a444..ceac775 100644 --- a/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino +++ b/Pointless_Button_V2.0.1-Beta/Pointless_Button_V2.0.1-Beta.ino @@ -42,20 +42,12 @@ String serialCountOutput; //----------------------------------------------------------------------------------------------------------------------- // Credentials and Links //----------------------------------------------------------------------------------------------------------------------- -/* - #define FIREBASE_HOST "https://YourRTDHostname-default-rtdb.firebaseio.com" - #define FIREBASE_AUTH "YourAPIKey" - const char* ssid2 = "SSIDName1"; - const char* ssidpass2 = "SSIDPassword1"; - const char* ssid1 = "SSIDName2"; - const char* ssidpass1 = "SSIDPassword2"; -*/ -#define FIREBASE_HOST "https://pointlessbuttonv2-2022-default-rtdb.firebaseio.com" -#define FIREBASE_AUTH "Bddm9oBrsBKmjzKv9iUtwqO7JjpgJBwb4ObBqOra" -const char* ssid1 = "KB-N20U"; -const char* ssidpass1 = "RollYourButt123!@#"; -const char* ssid2 = "BinTech LLC"; -const char* ssidpass2 = "FuckYouBitch123!@#"; +#define FIREBASE_HOST "https://YourRTDHostname-default-rtdb.firebaseio.com" +#define FIREBASE_AUTH "YourAPIKey" +const char* ssid2 = "SSIDName1"; +const char* ssidpass2 = "SSIDPassword1"; +const char* ssid1 = "SSIDName2"; +const char* ssidpass1 = "SSIDPassword2"; const char* externalHostname = "api.ipify.org"; const char* ntpServer = "0.debian.pool.ntp.org"; const long gmtOffset_sec = -21600; // -21600 is GMT -6 or Central Time From dfa6cedcec8f2e38df23244b9d499dcdda55c0f2 Mon Sep 17 00:00:00 2001 From: BinTechLLC <51284647+BinTechLLC@users.noreply.github.com> Date: Sun, 4 Dec 2022 00:05:06 -0600 Subject: [PATCH 14/15] Update README.txt --- README.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.txt b/README.txt index db831fb..17ff9e2 100644 --- a/README.txt +++ b/README.txt @@ -44,7 +44,10 @@ Just a heads up, this is my master notes doc and will change quite frequently wh - *Add Remote LED Test Trigger - V2.0.2 - *Local Web GUI + V2.0.2 - *Add Create New Node Function for New Boxes + - * + + V2.0.3 - *Local Web GUI - *Maybe App functionality - * From f14f779b882f3a8d5f6df3c890948b4e21864c5c Mon Sep 17 00:00:00 2001 From: BinTechLLC <51284647+BinTechLLC@users.noreply.github.com> Date: Sun, 4 Dec 2022 14:10:17 -0600 Subject: [PATCH 15/15] Update README.txt --- README.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.txt b/README.txt index 17ff9e2..96c74cf 100644 --- a/README.txt +++ b/README.txt @@ -45,7 +45,7 @@ Just a heads up, this is my master notes doc and will change quite frequently wh V2.0.2 - *Add Create New Node Function for New Boxes - - * + - *Firebase Directory Restructure to group like things together. (Previous to this it was in order of as added.) V2.0.3 - *Local Web GUI - *Maybe App functionality