From bd82d685dc7db1da0f93f19079f5e2854bb11cbb Mon Sep 17 00:00:00 2001 From: Will Richards Date: Wed, 13 Sep 2023 16:46:19 -0700 Subject: [PATCH 1/8] Project name was being populated with nothing, causing a failed to close message on MQTT --- .../WeatherChimesTippingBucket.ino | 8 ++++---- src/Internet/Logging/Loom_MQTT/Loom_MQTT.cpp | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/Lab Examples/WeatherChimes/WeatherChimesTippingBucket/WeatherChimesTippingBucket.ino b/examples/Lab Examples/WeatherChimes/WeatherChimesTippingBucket/WeatherChimesTippingBucket.ino index 3004b918..5a0f627b 100644 --- a/examples/Lab Examples/WeatherChimes/WeatherChimesTippingBucket/WeatherChimesTippingBucket.ino +++ b/examples/Lab Examples/WeatherChimes/WeatherChimesTippingBucket/WeatherChimesTippingBucket.ino @@ -75,7 +75,7 @@ void setup() { ENABLE_FUNC_SUMMARIES; // Set the interrupt pin to pullup - pinMode(INT_PIN, INPUT_PULLUP); + pinMode(INT_PIN, INPUT_PULLDOWN); // Wait 20 seconds for the serial console to open manager.beginSerial(); @@ -101,6 +101,9 @@ void setup() { void loop() { if(sampleFlag){ + // Set the RTC interrupt alarm to wake the device in 15 min + hypnos.setInterruptDuration(TimeSpan(0, 0, 15, 0)); + // Measure and package the data manager.measure(); manager.package(); @@ -117,9 +120,6 @@ void loop() { // Publish the collected data to MQTT mqtt.publish(); - // Set the RTC interrupt alarm to wake the device in 15 min - hypnos.setInterruptDuration(TimeSpan(0, 0, 15, 0)); - // Reattach to the interrupt after we have set the alarm so we can have repeat triggers hypnos.reattachRTCInterrupt(); attachInterrupt(INT_PIN, tipTrigger, FALLING); diff --git a/src/Internet/Logging/Loom_MQTT/Loom_MQTT.cpp b/src/Internet/Logging/Loom_MQTT/Loom_MQTT.cpp index 07f2e98a..79a79fb3 100644 --- a/src/Internet/Logging/Loom_MQTT/Loom_MQTT.cpp +++ b/src/Internet/Logging/Loom_MQTT/Loom_MQTT.cpp @@ -247,12 +247,14 @@ void Loom_MQTT::loadConfigFromJSON(char* json){ // Doc to store the JSON data from the SD card in StaticJsonDocument<300> doc; DeserializationError deserialError = deserializeJson(doc, json); + memset(projectServer, '\0', 100); // Check if an error occurred and if so print it if(deserialError != DeserializationError::Ok){ snprintf_P(output, OUTPUT_SIZE, PSTR("There was an error reading the MQTT credentials from SD: %s"), deserialError.c_str()); ERROR(output); } + // Only update values if not null if(!doc["broker"].isNull()){ @@ -260,7 +262,8 @@ void Loom_MQTT::loadConfigFromJSON(char* json){ strncpy(database_name, doc["database"].as(), 100); strncpy(username, doc["username"].as(), 100); strncpy(password, doc["password"].as(), 100); - strncpy(projectServer, doc["project"].as(), 100); + if(!doc["project"].isNull()) + strncpy(projectServer, doc["project"].as(), 100); port = doc["port"].as(); } From 0a554f9e1baccdd79afc9806c6814850f3cf82e4 Mon Sep 17 00:00:00 2001 From: Will Richards Date: Thu, 14 Sep 2023 13:37:29 -0700 Subject: [PATCH 2/8] Changed tipping bucket to use a PULLDOWN and moved setInterrupt to top of loop --- .../WeatherChimesTippingBucket/WeatherChimesTippingBucket.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Lab Examples/WeatherChimes/WeatherChimesTippingBucket/WeatherChimesTippingBucket.ino b/examples/Lab Examples/WeatherChimes/WeatherChimesTippingBucket/WeatherChimesTippingBucket.ino index 5a0f627b..f2ff4fd4 100644 --- a/examples/Lab Examples/WeatherChimes/WeatherChimesTippingBucket/WeatherChimesTippingBucket.ino +++ b/examples/Lab Examples/WeatherChimes/WeatherChimesTippingBucket/WeatherChimesTippingBucket.ino @@ -101,7 +101,7 @@ void setup() { void loop() { if(sampleFlag){ - // Set the RTC interrupt alarm to wake the device in 15 min + // Set the RTC interrupt alarm to wake the device in 15 min, this should be done as soon as the device enters sampling mode for consistant sleep cycles hypnos.setInterruptDuration(TimeSpan(0, 0, 15, 0)); // Measure and package the data From e7d24772b1a3eff2f5018971f02e0ff79bfc4146 Mon Sep 17 00:00:00 2001 From: Will Richards Date: Thu, 14 Sep 2023 15:37:00 -0700 Subject: [PATCH 3/8] Update Loom_Digital to take pinMode as a parameter --- examples/Lab Examples/Wattson/Wattson.ino | 5 ++++- examples/Lab Examples/Wattson/arduino_secrets.h | 2 ++ examples/Sensors/Digital/Digital.ino | 5 ++--- src/Sensors/Loom_Digital/Loom_Digital.h | 8 ++++---- 4 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 examples/Lab Examples/Wattson/arduino_secrets.h diff --git a/examples/Lab Examples/Wattson/Wattson.ino b/examples/Lab Examples/Wattson/Wattson.ino index a1f3cca7..70f3b970 100644 --- a/examples/Lab Examples/Wattson/Wattson.ino +++ b/examples/Lab Examples/Wattson/Wattson.ino @@ -17,13 +17,16 @@ Manager manager("Device", 1); //Loom_WIFI wifi(manager, CommunicationMode::AP); // For AP Loom_WIFI wifi(manager, CommunicationMode::CLIENT, SECRET_SSID, SECRET_PASS); // For Client + +// Create a new instance of max this takes in the WiFi object so we can communicate with the computer in addition to adding a controllable neopixel Loom_Max maxMsp(manager, wifi, new Loom_Neopixel()); Loom_MPU6050 mpu(manager); // Read the battery voltage and A0 and A1 Loom_Analog analog(manager, A0, A1); + // Reads the button on pin 10 -Loom_Digital digital(manager, 10); +Loom_Digital digital(manager, INPUT_PULLUP, 10); void setup() { diff --git a/examples/Lab Examples/Wattson/arduino_secrets.h b/examples/Lab Examples/Wattson/arduino_secrets.h new file mode 100644 index 00000000..a36e69b9 --- /dev/null +++ b/examples/Lab Examples/Wattson/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" \ No newline at end of file diff --git a/examples/Sensors/Digital/Digital.ino b/examples/Sensors/Digital/Digital.ino index b0439bb9..d45fc063 100644 --- a/examples/Sensors/Digital/Digital.ino +++ b/examples/Sensors/Digital/Digital.ino @@ -12,8 +12,8 @@ Manager manager("Device", 1); -// Reads the battery voltage -Loom_Digital digital(manager, 12, 11); +// Sets the pinMode of pin 12 and 11 to INPUT_PULLUP and then reads values from the pins +Loom_Digital digital(manager, INPUT_PULLUP, 12, 11); void setup() { @@ -25,7 +25,6 @@ void setup() { } void loop() { - // put your main code here, to run repeatedly: // Measure the data from the sensors manager.measure(); diff --git a/src/Sensors/Loom_Digital/Loom_Digital.h b/src/Sensors/Loom_Digital/Loom_Digital.h index 25a974c3..b959a84e 100644 --- a/src/Sensors/Loom_Digital/Loom_Digital.h +++ b/src/Sensors/Loom_Digital/Loom_Digital.h @@ -27,13 +27,13 @@ class Loom_Digital : public Module{ * @param additionalPins Variable length argument allowing you to supply multiple pins */ template - Loom_Digital(Manager& man, T firstPin , Args... additionalPins) : Module("Digital"){ + Loom_Digital(Manager& man, int pinState, T firstPin , Args... additionalPins) : Module("Digital"){ get_variadic_parameters(firstPin, additionalPins...); manInst = &man; // Set pin mode on digital pins for(int i = 0; i < digitalPins.size(); i++){ - pinMode(digitalPins[i], INPUT_PULLUP); + pinMode(digitalPins[i], pinState); } // Register the module with the manager @@ -46,12 +46,12 @@ class Loom_Digital : public Module{ * @param firstPin First digital pin we want to read from */ template - Loom_Digital(Manager& man, T firstPin) : Module("Digital"){ + Loom_Digital(Manager& man, int pinState, T firstPin) : Module("Digital"){ digitalPins.push_back(firstPin); manInst = &man; for(int i = 0; i < digitalPins.size(); i++){ - pinMode(digitalPins[i], INPUT_PULLUP); + pinMode(digitalPins[i], pinState); } // Register the module with the manager From a5e840e2e42b869205e486ffd9d19a64acfb36c0 Mon Sep 17 00:00:00 2001 From: Will Richards Date: Mon, 18 Sep 2023 11:16:01 -0700 Subject: [PATCH 4/8] Added additional safeguard for not supplying certain parameters on the SD card --- src/Internet/Logging/Loom_MQTT/Loom_MQTT.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Internet/Logging/Loom_MQTT/Loom_MQTT.cpp b/src/Internet/Logging/Loom_MQTT/Loom_MQTT.cpp index 79a79fb3..18dec3d0 100644 --- a/src/Internet/Logging/Loom_MQTT/Loom_MQTT.cpp +++ b/src/Internet/Logging/Loom_MQTT/Loom_MQTT.cpp @@ -247,7 +247,14 @@ void Loom_MQTT::loadConfigFromJSON(char* json){ // Doc to store the JSON data from the SD card in StaticJsonDocument<300> doc; DeserializationError deserialError = deserializeJson(doc, json); + + /* + Initialize all to null bytes so they are treated as a 0 length string + Issue: https://github.com/OPEnSLab-OSU/Loom-V4/issues/57 + */ memset(projectServer, '\0', 100); + memset(username, '\0', 100); + memset(password, '\0', 100); // Check if an error occurred and if so print it if(deserialError != DeserializationError::Ok){ @@ -260,10 +267,17 @@ void Loom_MQTT::loadConfigFromJSON(char* json){ if(!doc["broker"].isNull()){ strncpy(address, doc["broker"].as(), 100); strncpy(database_name, doc["database"].as(), 100); - strncpy(username, doc["username"].as(), 100); - strncpy(password, doc["password"].as(), 100); + + // If we dont have a username don't try to update the variables + if(!doc["username".isNull()]){ + strncpy(username, doc["username"].as(), 100); + strncpy(password, doc["password"].as(), 100); + } + + // If there is no project parameter don't update the project if(!doc["project"].isNull()) strncpy(projectServer, doc["project"].as(), 100); + port = doc["port"].as(); } From 49b8fc3c5b3969b9ec75505beb2232bb349c0465 Mon Sep 17 00:00:00 2001 From: Will Richards Date: Mon, 18 Sep 2023 11:22:44 -0700 Subject: [PATCH 5/8] Update .setInterrupt to be at the top of all sampling examples --- .../Adalogger_Sleep/Adalogger_Sleep.ino | 5 ++- .../Hypnos_SD_Sleep/Hypnos_SD_Sleep.ino | 6 ++- .../Hypnos_SD_Sleep_Interval_From_SD.ino | 6 +-- .../Internet/Logging/LTEBatch/LTEBatch.ino | 6 ++- .../Evaporometer/Evaporometer.ino | 7 ++-- examples/Lab Examples/FloDar/FloDar.ino | 7 ++-- .../MultipleInterrupts/MultipleInterrupts.ino | 40 +++++++++---------- .../SmartRock/SmartRock/SmartRock.ino | 6 +-- .../SmartRock/SmartRock2.5/SmartRock2.5.ino | 5 ++- .../WeatherChimes4G/WeatherChimes4G.ino | 6 +-- .../WeatherChimesTippingBucket.ino | 2 +- .../WeatherChimesTippingBucketI2C.ino | 2 +- .../WeatherChimesWifi/WeatherChimesWiFi.ino | 7 ++-- 13 files changed, 55 insertions(+), 50 deletions(-) diff --git a/examples/Hypnos/Adalogger_Sleep/Adalogger_Sleep.ino b/examples/Hypnos/Adalogger_Sleep/Adalogger_Sleep.ino index 74ef366b..997d4683 100644 --- a/examples/Hypnos/Adalogger_Sleep/Adalogger_Sleep.ino +++ b/examples/Hypnos/Adalogger_Sleep/Adalogger_Sleep.ino @@ -36,6 +36,8 @@ void setup() { } void loop() { + // Set the RTC interrupt alarm to wake the device in 10 seconds, done at top so evenly spaced sample periods + hypnos.setInterruptDuration(TimeSpan(0, 0, 0, 10)); // Measure and package data manager.measure(); @@ -47,8 +49,7 @@ void loop() { // Log the data to the SD card hypnos.logToSD(); - // Set the RTC interrupt alarm to wake the device in 10 seconds - hypnos.setInterruptDuration(TimeSpan(0, 0, 0, 10)); + // Reattach to the interrupt after we have set the alarm so we can have repeat triggers hypnos.reattachRTCInterrupt(); diff --git a/examples/Hypnos/Hypnos_SD_Sleep/Hypnos_SD_Sleep.ino b/examples/Hypnos/Hypnos_SD_Sleep/Hypnos_SD_Sleep.ino index 589230d3..fa2b2838 100644 --- a/examples/Hypnos/Hypnos_SD_Sleep/Hypnos_SD_Sleep.ino +++ b/examples/Hypnos/Hypnos_SD_Sleep/Hypnos_SD_Sleep.ino @@ -38,6 +38,9 @@ void setup() { void loop() { + // Set the RTC interrupt alarm to wake the device in 10 seconds, at the top to schedule next interrupt asap + hypnos.setInterruptDuration(TimeSpan(0, 0, 0, 10)); + // Measure and package data manager.measure(); manager.package(); @@ -48,8 +51,7 @@ void loop() { // Log the data to the SD card hypnos.logToSD(); - // Set the RTC interrupt alarm to wake the device in 10 seconds - hypnos.setInterruptDuration(TimeSpan(0, 0, 0, 10)); + // Reattach to the interrupt after we have set the alarm so we can have repeat triggers hypnos.reattachRTCInterrupt(); diff --git a/examples/Hypnos/Hypnos_SD_Sleep_Interval_From_SD/Hypnos_SD_Sleep_Interval_From_SD.ino b/examples/Hypnos/Hypnos_SD_Sleep_Interval_From_SD/Hypnos_SD_Sleep_Interval_From_SD.ino index aa20f998..44230475 100644 --- a/examples/Hypnos/Hypnos_SD_Sleep_Interval_From_SD/Hypnos_SD_Sleep_Interval_From_SD.ino +++ b/examples/Hypnos/Hypnos_SD_Sleep_Interval_From_SD/Hypnos_SD_Sleep_Interval_From_SD.ino @@ -39,6 +39,9 @@ void setup() { } void loop() { + + // Set the RTC interrupt alarm to wake the device in 10 seconds + hypnos.setInterruptDuration(sleepInterval); // Print the current JSON packet manager.display_data(); @@ -46,9 +49,6 @@ void loop() { // Log the data to the SD card hypnos.logToSD(); - // Set the RTC interrupt alarm to wake the device in 10 seconds - hypnos.setInterruptDuration(sleepInterval); - // Reattach to the interrupt after we have set the alarm so we can have repeat triggers hypnos.reattachRTCInterrupt(); diff --git a/examples/Internet/Logging/LTEBatch/LTEBatch.ino b/examples/Internet/Logging/LTEBatch/LTEBatch.ino index aa296d6d..4362438e 100644 --- a/examples/Internet/Logging/LTEBatch/LTEBatch.ino +++ b/examples/Internet/Logging/LTEBatch/LTEBatch.ino @@ -46,6 +46,9 @@ void setup() { } void loop() { + // Set the RTC interrupt alarm to wake the device in 10 seconds + hypnos.setInterruptDuration(TimeSpan(0, 0, 0, 10)); + // Package data manager.package(); @@ -58,8 +61,7 @@ void loop() { // Pass batch SD along to the MQTT module mqtt.publish(batchSD); - // Set the RTC interrupt alarm to wake the device in 10 seconds - hypnos.setInterruptDuration(TimeSpan(0, 0, 0, 10)); + // Reattach to the interrupt after we have set the alarm so we can have repeat triggers hypnos.reattachRTCInterrupt(); diff --git a/examples/Lab Examples/Evaporometer/Evaporometer.ino b/examples/Lab Examples/Evaporometer/Evaporometer.ino index f1b57ba0..f746d7ad 100644 --- a/examples/Lab Examples/Evaporometer/Evaporometer.ino +++ b/examples/Lab Examples/Evaporometer/Evaporometer.ino @@ -36,6 +36,10 @@ void setup(){ } void loop(){ + + // Set the RTC interrupt alarm to wake the device in 30 seconds, at the top to schedule next interrupt asap + hypnos.setInterruptDuration(TimeSpan(0, 0, 0, 30)); + // Measure and package the data from the sensors manager.measure(); manager.package(); @@ -46,9 +50,6 @@ void loop(){ // Log the data to the SD card hypnos.logToSD(); - // Set the RTC interrupt alarm to wake the device in 30 seconds - hypnos.setInterruptDuration(TimeSpan(0, 0, 0, 30)); - // Reattach to the interrupt after we have set the alarm so we can have repeat triggers hypnos.reattachRTCInterrupt(); diff --git a/examples/Lab Examples/FloDar/FloDar.ino b/examples/Lab Examples/FloDar/FloDar.ino index 4d74130b..4eb4cff1 100644 --- a/examples/Lab Examples/FloDar/FloDar.ino +++ b/examples/Lab Examples/FloDar/FloDar.ino @@ -41,6 +41,9 @@ void setup() { void loop() { + // Set the RTC interrupt alarm to wake the device in 10 seconds, at the top to schedule next interrupt asap + hypnos.setInterruptDuration(TimeSpan(0, 0, 15, 0)); + // Measure and package data manager.measure(); manager.package(); @@ -51,9 +54,7 @@ void loop() { // Log the data to the SD card hypnos.logToSD(); - // Set the RTC interrupt alarm to wake the device in 10 seconds - hypnos.setInterruptDuration(TimeSpan(0, 0, 15, 0)); - + // Reattach to the interrupt after we have set the alarm so we can have repeat triggers hypnos.reattachRTCInterrupt(); diff --git a/examples/Lab Examples/MultipleInterrupts/MultipleInterrupts.ino b/examples/Lab Examples/MultipleInterrupts/MultipleInterrupts.ino index ec63d462..bcb8e1ce 100644 --- a/examples/Lab Examples/MultipleInterrupts/MultipleInterrupts.ino +++ b/examples/Lab Examples/MultipleInterrupts/MultipleInterrupts.ino @@ -30,20 +30,15 @@ void wakeTrigger(){ } void tipTrigger() { - tip_time = millis(); - - // Check if the time of the last tip is more than 250 ms to debounce the switch - if(tip_time - last_tip_time > 250){ - counter++; - tipFlag = true; - detachInterrupt(INT_PIN); - } + hypnos.shouldPowerUp = false; + tipFlag = true; + detachInterrupt(INT_PIN); } void setup() { - // Set the interrupt pin to pullup - pinMode(INT_PIN, INPUT_PULLUP); + // Set the interrupt pin to INPUT + pinMode(INT_PIN, INPUT); // Wait 20 seconds for the serial console to open manager.beginSerial(); @@ -62,12 +57,13 @@ void setup() { void loop() { - // If we are waking up normally then we should sample data - if(sampleFlag) { + if(sampleFlag){ + // Set the RTC interrupt alarm to wake the device in 15 min, this should be done as soon as the device enters sampling mode for consistant sleep cycles + hypnos.setInterruptDuration(TimeSpan(0, 0, 15, 0)); + // Measure and package the data manager.measure(); manager.package(); - manager.addData("Switch", "Status", counter); // Print the current JSON packet manager.display_data(); @@ -75,23 +71,23 @@ void loop() { // Log the data to the SD card hypnos.logToSD(); - // Set the RTC interrupt alarm to wake the device every 30 seconds - hypnos.setInterruptDuration(TimeSpan(0, 0, 0, 30)); - // Reattach to the interrupt after we have set the alarm so we can have repeat triggers hypnos.reattachRTCInterrupt(); - - sampleFlag = false; // Do not do this process unless ISR sets the flag + attachInterrupt(INT_PIN, tipTrigger, FALLING); + attachInterrupt(INT_PIN, tipTrigger, FALLING); + sampleFlag = false; } - // Check if Tipping Bucket event - if(tipFlag) { + if(tipFlag){ + digitalWrite(LED_BUILTIN, HIGH); + delay(20); + bucket.incrementCount(); tipFlag = false; - Serial.println(counter); attachInterrupt(INT_PIN, tipTrigger, FALLING); attachInterrupt(INT_PIN, tipTrigger, FALLING); + digitalWrite(LED_BUILTIN, LOW); } - // Put the device into a deep sleep + // Put the device into a deep sleep, operation HALTS here until the interrupt is triggered hypnos.sleep(); } \ No newline at end of file diff --git a/examples/Lab Examples/SmartRock/SmartRock/SmartRock.ino b/examples/Lab Examples/SmartRock/SmartRock/SmartRock.ino index edacba95..aeb9f4c9 100644 --- a/examples/Lab Examples/SmartRock/SmartRock/SmartRock.ino +++ b/examples/Lab Examples/SmartRock/SmartRock/SmartRock.ino @@ -43,6 +43,9 @@ void setup() { void loop() { + // Set the RTC interrupt alarm to wake the device in 10 seconds, at the top to schedule next interrupt asap + hypnos.setInterruptDuration(sleepInterval); + // Measure and package the data manager.measure(); manager.package(); @@ -58,9 +61,6 @@ void loop() { // Log the data to the SD card hypnos.logToSD(); - // Set the RTC interrupt alarm to wake the device in 10 seconds - hypnos.setInterruptDuration(sleepInterval); - // Reattach to the interrupt after we have set the alarm so we can have repeat triggers hypnos.reattachRTCInterrupt(); diff --git a/examples/Lab Examples/SmartRock/SmartRock2.5/SmartRock2.5.ino b/examples/Lab Examples/SmartRock/SmartRock2.5/SmartRock2.5.ino index a785ae8a..8e7e0d6b 100644 --- a/examples/Lab Examples/SmartRock/SmartRock2.5/SmartRock2.5.ino +++ b/examples/Lab Examples/SmartRock/SmartRock2.5/SmartRock2.5.ino @@ -44,6 +44,9 @@ void setup() { } void loop() { + + // Set the RTC interrupt alarm to wake the device in 10 seconds, at the top to schedule next interrupt asap + hypnos.setInterruptDuration(sleepInterval); // Measure and package the data manager.measure(); @@ -55,8 +58,6 @@ void loop() { // Log the data to the SD card hypnos.logToSD(); - // Set the RTC interrupt alarm to wake the device in 10 seconds - hypnos.setInterruptDuration(sleepInterval); // Reattach to the interrupt after we have set the alarm so we can have repeat triggers hypnos.reattachRTCInterrupt(); diff --git a/examples/Lab Examples/WeatherChimes/WeatherChimes4G/WeatherChimes4G.ino b/examples/Lab Examples/WeatherChimes/WeatherChimes4G/WeatherChimes4G.ino index aea8e7b7..2e0f74ea 100644 --- a/examples/Lab Examples/WeatherChimes/WeatherChimes4G/WeatherChimes4G.ino +++ b/examples/Lab Examples/WeatherChimes/WeatherChimes4G/WeatherChimes4G.ino @@ -79,6 +79,9 @@ void setup() { void loop() { + // Set the RTC interrupt alarm to wake the device in 15 min, at the top to schedule next interrupt asap + hypnos.setInterruptDuration(TimeSpan(0, 0, 15, 0)); + // Measure and package the data manager.measure(); manager.package(); @@ -95,9 +98,6 @@ void loop() { // Publish the collected data to MQTT mqtt.publish(); - // Set the RTC interrupt alarm to wake the device in 15 min - hypnos.setInterruptDuration(TimeSpan(0, 0, 15, 0)); - // Reattach to the interrupt after we have set the alarm so we can have repeat triggers hypnos.reattachRTCInterrupt(); diff --git a/examples/Lab Examples/WeatherChimes/WeatherChimesTippingBucket/WeatherChimesTippingBucket.ino b/examples/Lab Examples/WeatherChimes/WeatherChimesTippingBucket/WeatherChimesTippingBucket.ino index f2ff4fd4..f525f2ef 100644 --- a/examples/Lab Examples/WeatherChimes/WeatherChimesTippingBucket/WeatherChimesTippingBucket.ino +++ b/examples/Lab Examples/WeatherChimes/WeatherChimesTippingBucket/WeatherChimesTippingBucket.ino @@ -75,7 +75,7 @@ void setup() { ENABLE_FUNC_SUMMARIES; // Set the interrupt pin to pullup - pinMode(INT_PIN, INPUT_PULLDOWN); + pinMode(INT_PIN, INPUT); // Wait 20 seconds for the serial console to open manager.beginSerial(); diff --git a/examples/Lab Examples/WeatherChimes/WeatherChimesTippingBucketI2C/WeatherChimesTippingBucketI2C.ino b/examples/Lab Examples/WeatherChimes/WeatherChimesTippingBucketI2C/WeatherChimesTippingBucketI2C.ino index f9916ae6..2ef7b64d 100644 --- a/examples/Lab Examples/WeatherChimes/WeatherChimesTippingBucketI2C/WeatherChimesTippingBucketI2C.ino +++ b/examples/Lab Examples/WeatherChimes/WeatherChimesTippingBucketI2C/WeatherChimesTippingBucketI2C.ino @@ -90,7 +90,7 @@ void loop() { // Publish the collected data to MQTT mqtt.publish(); - // Set the RTC interrupt alarm to wake the device in 15 min + // Set the RTC interrupt alarm to wake the device in 15 min, at the top to schedule next interrupt asap hypnos.setInterruptDuration(TimeSpan(0, 0, 15, 0)); // Reattach to the interrupt after we have set the alarm so we can have repeat triggers diff --git a/examples/Lab Examples/WeatherChimes/WeatherChimesWifi/WeatherChimesWiFi.ino b/examples/Lab Examples/WeatherChimes/WeatherChimesWifi/WeatherChimesWiFi.ino index bae0aab4..cb440570 100644 --- a/examples/Lab Examples/WeatherChimes/WeatherChimesWifi/WeatherChimesWiFi.ino +++ b/examples/Lab Examples/WeatherChimes/WeatherChimesWifi/WeatherChimesWiFi.ino @@ -79,6 +79,9 @@ void setup() { void loop() { + // Set the RTC interrupt alarm to wake the device in 15 min, at the top to schedule next interrupt asap + hypnos.setInterruptDuration(TimeSpan(0, 0, 15, 0)); + // Measure and package the data manager.measure(); manager.package(); @@ -95,9 +98,7 @@ void loop() { // Publish the collected data to MQTT mqtt.publish(); - // Set the RTC interrupt alarm to wake the device in 15 min - hypnos.setInterruptDuration(TimeSpan(0, 0, 15, 0)); - + // Reattach to the interrupt after we have set the alarm so we can have repeat triggers hypnos.reattachRTCInterrupt(); From caf5e9d82cccf5fa34eb37ea1234558190cf61c9 Mon Sep 17 00:00:00 2001 From: Will Richards Date: Mon, 18 Sep 2023 11:32:40 -0700 Subject: [PATCH 6/8] Add failsafe for alarm triggering before sleep --- src/Hardware/Loom_Hypnos/Loom_Hypnos.cpp | 33 +++++++++++++----------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Hardware/Loom_Hypnos/Loom_Hypnos.cpp b/src/Hardware/Loom_Hypnos/Loom_Hypnos.cpp index 6810e244..e9f8454d 100644 --- a/src/Hardware/Loom_Hypnos/Loom_Hypnos.cpp +++ b/src/Hardware/Loom_Hypnos/Loom_Hypnos.cpp @@ -366,22 +366,25 @@ void Loom_Hypnos::setInterruptDuration(const TimeSpan duration){ ////////////////////////////////////////////////////////////////////////////////////////////////////// void Loom_Hypnos::sleep(bool waitForSerial){ - // Try to power down the active modules - if(shouldPowerUp){ - manInst->power_down(); - // 50ms delay allows this last message to be sent before the bus disconnects - LOG("Entering Standby Sleep..."); - delay(50); - } - - - - disable(); - pre_sleep(); // Pre-sleep cleanup - shouldPowerUp = true; - LowPower.sleep(); // Go to sleep and hang - post_sleep(waitForSerial); // Wake up + // If the alarm set time is less than the current time we missed our next alarm so we need to set a new one + if(RTC_DS.getAlarm(1) > RTC_DS.now()){ + // Try to power down the active modules + if(shouldPowerUp){ + manInst->power_down(); + // 50ms delay allows this last message to be sent before the bus disconnects + LOG("Entering Standby Sleep..."); + delay(50); + } + + disable(); + pre_sleep(); // Pre-sleep cleanup + shouldPowerUp = true; + LowPower.sleep(); // Go to sleep and hang + post_sleep(waitForSerial); // Wake up + }else{ + WARNING("If the alarm was set to a time less than the current time we don't want to sleep before a new time was set"); + } } ////////////////////////////////////////////////////////////////////////////////////////////////////// From 7287db5796ee86a9575f7a2c0e441616f3363a2a Mon Sep 17 00:00:00 2001 From: Will Richards Date: Mon, 18 Sep 2023 11:34:56 -0700 Subject: [PATCH 7/8] Updated warning message in sleep --- src/Hardware/Loom_Hypnos/Loom_Hypnos.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Hardware/Loom_Hypnos/Loom_Hypnos.cpp b/src/Hardware/Loom_Hypnos/Loom_Hypnos.cpp index e9f8454d..cd0f07cf 100644 --- a/src/Hardware/Loom_Hypnos/Loom_Hypnos.cpp +++ b/src/Hardware/Loom_Hypnos/Loom_Hypnos.cpp @@ -383,7 +383,7 @@ void Loom_Hypnos::sleep(bool waitForSerial){ LowPower.sleep(); // Go to sleep and hang post_sleep(waitForSerial); // Wake up }else{ - WARNING("If the alarm was set to a time less than the current time we don't want to sleep before a new time was set"); + WARNING("Alarm triggered during sample, specified sample duration was too short! Setting new sample time..."); } } ////////////////////////////////////////////////////////////////////////////////////////////////////// From 2d3d18f63d38b9f2abbd9a6d7e42c5a9ea7fc35c Mon Sep 17 00:00:00 2001 From: Will Richards Date: Tue, 19 Sep 2023 14:30:53 -0700 Subject: [PATCH 8/8] Fixed typo with ["username". --- src/Hardware/Loom_Hypnos/Loom_Hypnos.cpp | 3 ++- src/Internet/Logging/Loom_MQTT/Loom_MQTT.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Hardware/Loom_Hypnos/Loom_Hypnos.cpp b/src/Hardware/Loom_Hypnos/Loom_Hypnos.cpp index cd0f07cf..c052571a 100644 --- a/src/Hardware/Loom_Hypnos/Loom_Hypnos.cpp +++ b/src/Hardware/Loom_Hypnos/Loom_Hypnos.cpp @@ -351,7 +351,6 @@ void Loom_Hypnos::setInterruptDuration(const TimeSpan duration){ DateTime future(RTC_DS.now() + duration); RTC_DS.setAlarm(future); - // Print the time that the next interrupt is set to trigger snprintf(output, OUTPUT_SIZE, PSTR("Current Time: %s"), RTC_DS.now().text()); LOG(output); @@ -369,9 +368,11 @@ void Loom_Hypnos::sleep(bool waitForSerial){ // If the alarm set time is less than the current time we missed our next alarm so we need to set a new one if(RTC_DS.getAlarm(1) > RTC_DS.now()){ + // Try to power down the active modules if(shouldPowerUp){ manInst->power_down(); + // 50ms delay allows this last message to be sent before the bus disconnects LOG("Entering Standby Sleep..."); delay(50); diff --git a/src/Internet/Logging/Loom_MQTT/Loom_MQTT.cpp b/src/Internet/Logging/Loom_MQTT/Loom_MQTT.cpp index 18dec3d0..23ced492 100644 --- a/src/Internet/Logging/Loom_MQTT/Loom_MQTT.cpp +++ b/src/Internet/Logging/Loom_MQTT/Loom_MQTT.cpp @@ -269,7 +269,7 @@ void Loom_MQTT::loadConfigFromJSON(char* json){ strncpy(database_name, doc["database"].as(), 100); // If we dont have a username don't try to update the variables - if(!doc["username".isNull()]){ + if(!doc["username"].isNull()){ strncpy(username, doc["username"].as(), 100); strncpy(password, doc["password"].as(), 100); }