diff --git a/examples/DRWI_CitSci/DRWI_CitSci.ino b/examples/DRWI_CitSci/DRWI_CitSci.ino index 4da7f930f..cf2aeff17 100644 --- a/examples/DRWI_CitSci/DRWI_CitSci.ino +++ b/examples/DRWI_CitSci/DRWI_CitSci.ino @@ -7,7 +7,7 @@ Software License: BSD-3. Copyright (c) 2017, Stroud Water Research Center (SWRC) and the EnviroDIY Development Team -This example sketch is written for ModularSensors library version 0.23.11 +This example sketch is written for ModularSensors library version 0.23.13 This sketch is an example of logging data to an SD card and sending the data to both the EnviroDIY data portal as should be used by groups involved with @@ -40,7 +40,7 @@ THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN. // Data Logger Settings // ========================================================================== // The library version this example was written for -const char *libraryVersion = "0.23.11"; +const char *libraryVersion = "0.23.13"; // The name of this file const char *sketchName = "DWRI_CitSci.ino"; // Logger ID, also becomes the prefix for the name of the data file on SD card @@ -291,28 +291,21 @@ void setup() // Note: Please change these battery voltages to match your battery // Check that the battery is OK before powering the modem - if (getBatteryVoltage() > 3.7) + if (getBatteryVoltage() > 3.55 || !dataLogger.isRTCSane()) { modem.modemPowerUp(); modem.wake(); modem.setup(); - // At very good battery voltage, or with suspicious time stamp, sync the clock - // Note: Please change these battery voltages to match your battery - if (getBatteryVoltage() > 3.8 || - dataLogger.getNowEpoch() < 1546300800 || /*Before 01/01/2019*/ - dataLogger.getNowEpoch() > 1735689600) /*After 1/1/2025*/ + // Synchronize the RTC with NIST + Serial.println(F("Attempting to connect to the internet and synchronize RTC with NIST")); + if (modem.connectInternet(120000L)) { - // Synchronize the RTC with NIST - Serial.println(F("Attempting to connect to the internet and synchronize RTC with NIST")); - if (modem.connectInternet(120000L)) - { - dataLogger.setRTClock(modem.getNISTTime()); - } - else - { - Serial.println(F("Could not connect to internet for clock sync.")); - } + dataLogger.setRTClock(modem.getNISTTime()); + } + else + { + Serial.println(F("Could not connect to internet for clock sync.")); } } diff --git a/examples/DRWI_CitSci/platformio.ini b/examples/DRWI_CitSci/platformio.ini index 623a43980..d4ba6ec40 100644 --- a/examples/DRWI_CitSci/platformio.ini +++ b/examples/DRWI_CitSci/platformio.ini @@ -22,7 +22,7 @@ build_flags = -DSDI12_EXTERNAL_PCINT -DNEOSWSERIAL_EXTERNAL_PCINT lib_deps = - EnviroDIY_ModularSensors@0.23.11 + EnviroDIY_ModularSensors@0.23.13 ; ^^ Use this when working from an official release of the library ; https://github.com/EnviroDIY/ModularSensors.git#develop ; ^^ Use this when if you want to pull from the develop branch diff --git a/examples/DRWI_LTE/DRWI_LTE.ino b/examples/DRWI_LTE/DRWI_LTE.ino index 57021375e..2cf6bebf5 100644 --- a/examples/DRWI_LTE/DRWI_LTE.ino +++ b/examples/DRWI_LTE/DRWI_LTE.ino @@ -7,7 +7,7 @@ Software License: BSD-3. Copyright (c) 2017, Stroud Water Research Center (SWRC) and the EnviroDIY Development Team -This example sketch is written for ModularSensors library version 0.23.11 +This example sketch is written for ModularSensors library version 0.23.13 This sketch is an example of logging data to an SD card and sending the data to both the EnviroDIY data portal as should be used by groups involved with @@ -40,7 +40,7 @@ THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN. // Data Logger Settings // ========================================================================== // The library version this example was written for -const char *libraryVersion = "0.23.11"; +const char *libraryVersion = "0.23.13"; // The name of this file const char *sketchName = "DRWI_LTE.ino"; // Logger ID, also becomes the prefix for the name of the data file on SD card @@ -295,28 +295,21 @@ void setup() // Note: Please change these battery voltages to match your battery // Check that the battery is OK before powering the modem - if (getBatteryVoltage() > 3.7) + if (getBatteryVoltage() > 3.55 || !dataLogger.isRTCSane()) { modem.modemPowerUp(); modem.wake(); modem.setup(); - // At very good battery voltage, or with suspicious time stamp, sync the clock - // Note: Please change these battery voltages to match your battery - if (getBatteryVoltage() > 3.8 || - dataLogger.getNowEpoch() < 1546300800 || /*Before 01/01/2019*/ - dataLogger.getNowEpoch() > 1735689600) /*After 1/1/2025*/ + // Synchronize the RTC with NIST + Serial.println(F("Attempting to connect to the internet and synchronize RTC with NIST")); + if (modem.connectInternet(120000L)) { - // Synchronize the RTC with NIST - Serial.println(F("Attempting to connect to the internet and synchronize RTC with NIST")); - if (modem.connectInternet(120000L)) - { - dataLogger.setRTClock(modem.getNISTTime()); - } - else - { - Serial.println(F("Could not connect to internet for clock sync.")); - } + dataLogger.setRTClock(modem.getNISTTime()); + } + else + { + Serial.println(F("Could not connect to internet for clock sync.")); } } diff --git a/examples/DRWI_LTE/platformio.ini b/examples/DRWI_LTE/platformio.ini index 8e1f24ed7..e3c24bfc6 100644 --- a/examples/DRWI_LTE/platformio.ini +++ b/examples/DRWI_LTE/platformio.ini @@ -21,7 +21,7 @@ lib_ignore = RTCZero build_flags = -DSDI12_EXTERNAL_PCINT lib_deps = - EnviroDIY_ModularSensors@0.23.11 + EnviroDIY_ModularSensors@0.23.13 ; ^^ Use this when working from an official release of the library ; https://github.com/EnviroDIY/ModularSensors.git#develop ; ^^ Use this when if you want to pull from the develop branch diff --git a/examples/DRWI_NoCellular/DRWI_NoCellular.ino b/examples/DRWI_NoCellular/DRWI_NoCellular.ino index c6febd69e..7a04cdab3 100644 --- a/examples/DRWI_NoCellular/DRWI_NoCellular.ino +++ b/examples/DRWI_NoCellular/DRWI_NoCellular.ino @@ -7,7 +7,7 @@ Software License: BSD-3. Copyright (c) 2017, Stroud Water Research Center (SWRC) and the EnviroDIY Development Team -This example sketch is written for ModularSensors library version 0.23.11 +This example sketch is written for ModularSensors library version 0.23.13 This sketch is an example of logging data to an SD card as should be used by groups involved with The William Penn Foundation's Delaware River Watershed @@ -34,7 +34,7 @@ THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN. // Data Logger Settings // ========================================================================== // The library version this example was written for -const char *libraryVersion = "0.23.11"; +const char *libraryVersion = "0.23.13"; // The name of this file const char *sketchName = "DRWI_NoCellular.ino"; // Logger ID, also becomes the prefix for the name of the data file on SD card diff --git a/examples/DRWI_NoCellular/platformio.ini b/examples/DRWI_NoCellular/platformio.ini index 44808fdf3..b9824a804 100644 --- a/examples/DRWI_NoCellular/platformio.ini +++ b/examples/DRWI_NoCellular/platformio.ini @@ -22,7 +22,7 @@ build_flags = -DSDI12_EXTERNAL_PCINT -DNEOSWSERIAL_EXTERNAL_PCINT lib_deps = - EnviroDIY_ModularSensors@0.23.11 + EnviroDIY_ModularSensors@0.23.13 ; ^^ Use this when working from an official release of the library ; https://github.com/EnviroDIY/ModularSensors.git#develop ; ^^ Use this when if you want to pull from the develop branch diff --git a/examples/baro_rho_correction/baro_rho_correction.ino b/examples/baro_rho_correction/baro_rho_correction.ino index 668d9eb46..c5d23e673 100644 --- a/examples/baro_rho_correction/baro_rho_correction.ino +++ b/examples/baro_rho_correction/baro_rho_correction.ino @@ -7,7 +7,7 @@ Software License: BSD-3. Copyright (c) 2017, Stroud Water Research Center (SWRC) and the EnviroDIY Development Team -This example sketch is written for ModularSensors library version 0.23.11 +This example sketch is written for ModularSensors library version 0.23.13 This sketch is an example of logging data to an SD card and sending the data to the EnviroDIY data portal. @@ -43,7 +43,7 @@ THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN. // Data Logger Settings // ========================================================================== // The library version this example was written for -const char *libraryVersion = "0.23.11"; +const char *libraryVersion = "0.23.13"; // The name of this file const char *sketchName = "baro_rho_correction.ino"; // Logger ID, also becomes the prefix for the name of the data file on SD card @@ -407,28 +407,21 @@ void setup() // Note: Please change these battery voltages to match your battery // Check that the battery is OK before powering the modem - if (getBatteryVoltage() > 3.7) + if (getBatteryVoltage() > 3.55 || !dataLogger.isRTCSane()) { modem.modemPowerUp(); modem.wake(); modem.setup(); - // At very good battery voltage, or with suspicious time stamp, sync the clock - // Note: Please change these battery voltages to match your battery - if (getBatteryVoltage() > 3.8 || - dataLogger.getNowEpoch() < 1546300800 || /*Before 01/01/2019*/ - dataLogger.getNowEpoch() > 1735689600) /*After 1/1/2025*/ + // Synchronize the RTC with NIST + Serial.println(F("Attempting to connect to the internet and synchronize RTC with NIST")); + if (modem.connectInternet(120000L)) { - // Synchronize the RTC with NIST - Serial.println(F("Attempting to connect to the internet and synchronize RTC with NIST")); - if (modem.connectInternet(120000L)) - { - dataLogger.setRTClock(modem.getNISTTime()); - } - else - { - Serial.println(F("Could not connect to internet for clock sync.")); - } + dataLogger.setRTClock(modem.getNISTTime()); + } + else + { + Serial.println(F("Could not connect to internet for clock sync.")); } } diff --git a/examples/baro_rho_correction/platformio.ini b/examples/baro_rho_correction/platformio.ini index f9e2712dd..452567acd 100644 --- a/examples/baro_rho_correction/platformio.ini +++ b/examples/baro_rho_correction/platformio.ini @@ -23,7 +23,7 @@ build_flags = -DSDI12_EXTERNAL_PCINT -DNEOSWSERIAL_EXTERNAL_PCINT lib_deps = - EnviroDIY_ModularSensors@0.23.11 + EnviroDIY_ModularSensors@0.23.13 ; ^^ Use this when working from an official release of the library ; https://github.com/EnviroDIY/ModularSensors.git#develop ; ^^ Use this when if you want to pull from the develop branch diff --git a/examples/cuahsi_workshop/cuahsi_workshop.ino b/examples/cuahsi_workshop/cuahsi_workshop.ino index 4a6e15e40..fbe0bd992 100644 --- a/examples/cuahsi_workshop/cuahsi_workshop.ino +++ b/examples/cuahsi_workshop/cuahsi_workshop.ino @@ -7,7 +7,7 @@ Software License: BSD-3. Copyright (c) 2017, Stroud Water Research Center (SWRC) and the EnviroDIY Development Team -This example sketch is written for ModularSensors library version 0.23.11 +This example sketch is written for ModularSensors library version 0.23.13 This shows most of the standard functions of the library at once. @@ -42,7 +42,7 @@ THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN. // Data Logger Settings // ========================================================================== // The library version this example was written for -const char *libraryVersion = "0.23.11"; +const char *libraryVersion = "0.23.13"; // The name of this file const char *sketchName = "cuahsi_workshop.ino"; // Logger ID, also becomes the prefix for the name of the data file on SD card @@ -429,8 +429,8 @@ void setup() // At very good battery voltage, or with suspicious time stamp, sync the clock // Note: Please change these battery voltages to match your battery if (getBatteryVoltage() > 3.8 || - dataLogger.getNowEpoch() < 1546300800 || /*Before 01/01/2019*/ - dataLogger.getNowEpoch() > 1735689600) /*After 1/1/2025*/ + dataLogger.getNowEpoch() < 1546300800 || /*Before September 01, 2019*/ + dataLogger.getNowEpoch() > 1735689600) /*After January 1, 2025*/ { // Synchronize the RTC with NIST Serial.println(F("Attempting to connect to the internet and synchronize RTC with NIST")); diff --git a/examples/data_saving/data_saving.ino b/examples/data_saving/data_saving.ino index e2885e291..c298ae2c6 100644 --- a/examples/data_saving/data_saving.ino +++ b/examples/data_saving/data_saving.ino @@ -7,7 +7,7 @@ Software License: BSD-3. Copyright (c) 2017, Stroud Water Research Center (SWRC) and the EnviroDIY Development Team -This example sketch is written for ModularSensors library version 0.23.11 +This example sketch is written for ModularSensors library version 0.23.13 This sketch is an example of logging data to an SD card and sending only a portion of that data to the EnviroDIY data portal. @@ -42,7 +42,7 @@ THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN. // Data Logger Settings // ========================================================================== // The library version this example was written for -const char *libraryVersion = "0.23.11"; +const char *libraryVersion = "0.23.13"; // The name of this file const char *sketchName = "data_saving.ino"; // Logger ID, also becomes the prefix for the name of the data file on SD card @@ -511,24 +511,17 @@ void setup() // Note: Please change these battery voltages to match your battery // Check that the battery is OK before powering the modem - if (getBatteryVoltage() > 3.7) + if (getBatteryVoltage() > 3.55 || !loggerAllVars.isRTCSane()) { modem.modemPowerUp(); modem.wake(); modem.setup(); - // At very good battery voltage, or with suspicious time stamp, sync the clock - // Note: Please change these battery voltages to match your battery - if (getBatteryVoltage() > 3.8 || - loggerAllVars.getNowEpoch() < 1546300800 || /*Before 01/01/2019*/ - loggerAllVars.getNowEpoch() > 1735689600) /*After 1/1/2025*/ + // Synchronize the RTC with NIST + Serial.println(F("Attempting to connect to the internet and synchronize RTC with NIST")); + if (modem.connectInternet(120000L)) { - // Synchronize the RTC with NIST - Serial.println(F("Attempting to connect to the internet and synchronize RTC with NIST")); - if (modem.connectInternet(120000L)) - { - loggerAllVars.setRTClock(modem.getNISTTime()); - } + loggerAllVars.setRTClock(modem.getNISTTime()); } } @@ -595,7 +588,7 @@ void loop() // NOTE: if the modemPowerUp function is not run before the completeUpdate // function is run, the modem will not be powered and will not return // a signal strength readign. - if (getBatteryVoltage() > 3.7) + if (getBatteryVoltage() > 3.55) modem.modemPowerUp(); // Start the stream for the modbus sensors @@ -633,7 +626,7 @@ void loop() // Connect to the network // Again, we're only doing this if the battery is doing well - if (getBatteryVoltage() > 3.7) + if (getBatteryVoltage() > 3.55) { if (modem.connectInternet()) { diff --git a/examples/data_saving/platformio.ini b/examples/data_saving/platformio.ini index 3f1b7d860..059fb9ffe 100644 --- a/examples/data_saving/platformio.ini +++ b/examples/data_saving/platformio.ini @@ -22,7 +22,7 @@ build_flags = -DSDI12_EXTERNAL_PCINT -DNEOSWSERIAL_EXTERNAL_PCINT lib_deps = - EnviroDIY_ModularSensors@0.23.11 + EnviroDIY_ModularSensors@0.23.13 ; ^^ Use this when working from an official release of the library ; https://github.com/EnviroDIY/ModularSensors.git#develop ; ^^ Use this when if you want to pull from the develop branch diff --git a/examples/double_logger/double_logger.ino b/examples/double_logger/double_logger.ino index e44221369..0dfe1a2e7 100644 --- a/examples/double_logger/double_logger.ino +++ b/examples/double_logger/double_logger.ino @@ -7,7 +7,7 @@ Software License: BSD-3. Copyright (c) 2017, Stroud Water Research Center (SWRC) and the EnviroDIY Development Team -This example sketch is written for ModularSensors library version 0.23.11 +This example sketch is written for ModularSensors library version 0.23.13 This sketch is an example of logging data from different variables at two different logging intervals. This example uses more of the manual functions @@ -29,7 +29,7 @@ THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN. // Data Logger Settings // ========================================================================== // The library version this example was written for -const char *libraryVersion = "0.23.11"; +const char *libraryVersion = "0.23.13"; // The name of this file const char *sketchName = "double_logger.ino"; // Logger ID - we're only using one logger ID for both "loggers" diff --git a/examples/double_logger/platformio.ini b/examples/double_logger/platformio.ini index 4973674fe..011d36a8a 100644 --- a/examples/double_logger/platformio.ini +++ b/examples/double_logger/platformio.ini @@ -22,7 +22,7 @@ build_flags = -DSDI12_EXTERNAL_PCINT -DNEOSWSERIAL_EXTERNAL_PCINT lib_deps = - EnviroDIY_ModularSensors@0.23.11 + EnviroDIY_ModularSensors@0.23.13 ; ^^ Use this when working from an official release of the library ; https://github.com/EnviroDIY/ModularSensors.git#develop ; ^^ Use this when if you want to pull from the develop branch diff --git a/examples/logging_to_MMW/logging_to_MMW.ino b/examples/logging_to_MMW/logging_to_MMW.ino index 98a4b787d..0353429d7 100644 --- a/examples/logging_to_MMW/logging_to_MMW.ino +++ b/examples/logging_to_MMW/logging_to_MMW.ino @@ -7,7 +7,7 @@ Software License: BSD-3. Copyright (c) 2017, Stroud Water Research Center (SWRC) and the EnviroDIY Development Team -This example sketch is written for ModularSensors library version 0.23.11 +This example sketch is written for ModularSensors library version 0.23.13 This shows most of the standard functions of the library at once. @@ -41,7 +41,7 @@ THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN. // Data Logger Settings // ========================================================================== // The library version this example was written for -const char *libraryVersion = "0.23.11"; +const char *libraryVersion = "0.23.13"; // The name of this file const char *sketchName = "logging_to MMW.ino"; // Logger ID, also becomes the prefix for the name of the data file on SD card @@ -302,28 +302,21 @@ void setup() // Note: Please change these battery voltages to match your battery // Check that the battery is OK before powering the modem - if (getBatteryVoltage() > 3.7) + if (getBatteryVoltage() > 3.55 || !dataLogger.isRTCSane()) { modem.modemPowerUp(); modem.wake(); modem.setup(); - // At very good battery voltage, or with suspicious time stamp, sync the clock - // Note: Please change these battery voltages to match your battery - if (getBatteryVoltage() > 3.8 || - dataLogger.getNowEpoch() < 1546300800 || /*Before 01/01/2019*/ - dataLogger.getNowEpoch() > 1735689600) /*After 1/1/2025*/ + // Synchronize the RTC with NIST + Serial.println(F("Attempting to connect to the internet and synchronize RTC with NIST")); + if (modem.connectInternet(120000L)) { - // Synchronize the RTC with NIST - Serial.println(F("Attempting to connect to the internet and synchronize RTC with NIST")); - if (modem.connectInternet(120000L)) - { - dataLogger.setRTClock(modem.getNISTTime()); - } - else - { - Serial.println(F("Could not connect to internet for clock sync.")); - } + dataLogger.setRTClock(modem.getNISTTime()); + } + else + { + Serial.println(F("Could not connect to internet for clock sync.")); } } diff --git a/examples/logging_to_MMW/platformio.ini b/examples/logging_to_MMW/platformio.ini index 2525b0525..1e964a25e 100644 --- a/examples/logging_to_MMW/platformio.ini +++ b/examples/logging_to_MMW/platformio.ini @@ -21,7 +21,7 @@ lib_ignore = RTCZero build_flags = -DSDI12_EXTERNAL_PCINT lib_deps = - EnviroDIY_ModularSensors@0.23.11 + EnviroDIY_ModularSensors@0.23.13 ; ^^ Use this when working from an official release of the library ; https://github.com/EnviroDIY/ModularSensors.git#develop ; ^^ Use this when if you want to pull from the develop branch diff --git a/examples/logging_to_ThingSpeak/logging_to_ThingSpeak.ino b/examples/logging_to_ThingSpeak/logging_to_ThingSpeak.ino index e37d79a5f..f5b2c077d 100644 --- a/examples/logging_to_ThingSpeak/logging_to_ThingSpeak.ino +++ b/examples/logging_to_ThingSpeak/logging_to_ThingSpeak.ino @@ -7,7 +7,7 @@ Software License: BSD-3. Copyright (c) 2017, Stroud Water Research Center (SWRC) and the EnviroDIY Development Team -This example sketch is written for ModularSensors library version 0.23.11 +This example sketch is written for ModularSensors library version 0.23.13 This sketch is an example of logging data to an SD card and sending the data to ThingSpeak. @@ -42,7 +42,7 @@ THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN. // Data Logger Settings // ========================================================================== // The library version this example was written for -const char *libraryVersion = "0.23.11"; +const char *libraryVersion = "0.23.13"; // The name of this file const char *sketchName = "logging_to_ThingSpeak.ino"; // Logger ID, also becomes the prefix for the name of the data file on SD card @@ -304,27 +304,20 @@ void setup() // Note: Please change these battery voltages to match your battery // Check that the battery is OK before powering the modem - if (getBatteryVoltage() > 3.7) + if (getBatteryVoltage() > 3.55 || !dataLogger.isRTCSane()) { modem.modemPowerUp(); modem.wake(); - // At very good battery voltage, or with suspicious time stamp, sync the clock - // Note: Please change these battery voltages to match your battery - if (getBatteryVoltage() > 3.8 || - dataLogger.getNowEpoch() < 1546300800 || /*Before 01/01/2019*/ - dataLogger.getNowEpoch() > 1735689600) /*After 1/1/2025*/ + // Synchronize the RTC with NIST + Serial.println(F("Attempting to connect to the internet and synchronize RTC with NIST")); + if (modem.connectInternet(120000L)) { - // Synchronize the RTC with NIST - Serial.println(F("Attempting to connect to the internet and synchronize RTC with NIST")); - if (modem.connectInternet(120000L)) - { - dataLogger.setRTClock(modem.getNISTTime()); - } - else - { - Serial.println(F("Could not connect to internet for clock sync.")); - } + dataLogger.setRTClock(modem.getNISTTime()); + } + else + { + Serial.println(F("Could not connect to internet for clock sync.")); } } diff --git a/examples/logging_to_ThingSpeak/platformio.ini b/examples/logging_to_ThingSpeak/platformio.ini index c4b3675ad..d836d744f 100644 --- a/examples/logging_to_ThingSpeak/platformio.ini +++ b/examples/logging_to_ThingSpeak/platformio.ini @@ -23,7 +23,7 @@ build_flags = -DNEOSWSERIAL_EXTERNAL_PCINT -DMQTT_MAX_PACKET_SIZE=240 lib_deps = - EnviroDIY_ModularSensors@0.23.11 + EnviroDIY_ModularSensors@0.23.13 ; ^^ Use this when working from an official release of the library ; https://github.com/EnviroDIY/ModularSensors.git#develop ; ^^ Use this when if you want to pull from the develop branch diff --git a/examples/menu_a_la_carte/menu_a_la_carte.ino b/examples/menu_a_la_carte/menu_a_la_carte.ino index cb70011ad..a1f6dbb98 100644 --- a/examples/menu_a_la_carte/menu_a_la_carte.ino +++ b/examples/menu_a_la_carte/menu_a_la_carte.ino @@ -7,7 +7,7 @@ Software License: BSD-3. Copyright (c) 2017, Stroud Water Research Center (SWRC) and the EnviroDIY Development Team -This example sketch is written for ModularSensors library version 0.23.11 +This example sketch is written for ModularSensors library version 0.23.13 This shows most of the standard functions of the library at once. @@ -42,7 +42,7 @@ THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN. // Data Logger Settings // ========================================================================== // The library version this example was written for -const char *libraryVersion = "0.23.11"; +const char *libraryVersion = "0.23.13"; // The name of this file const char *sketchName = "menu_a_la_carte.ino"; // Logger ID, also becomes the prefix for the name of the data file on SD card @@ -1509,28 +1509,21 @@ void setup() // Note: Please change these battery voltages to match your battery // Check that the battery is OK before powering the modem - if (getBatteryVoltage() > 3.65) + if (getBatteryVoltage() > 3.55 || !dataLogger.isRTCSane()) { modem.modemPowerUp(); modem.wake(); modem.setup(); - // At very good battery voltage, or with suspicious time stamp, sync the clock - // Note: Please change these battery voltages to match your battery - if (getBatteryVoltage() > 3.8 || - dataLogger.getNowEpoch() < 1546300800 || /*Before 01/01/2019*/ - dataLogger.getNowEpoch() > 1735689600) /*After 1/1/2025*/ + // Synchronize the RTC with NIST + Serial.println(F("Attempting to connect to the internet and synchronize RTC with NIST")); + if (modem.connectInternet(120000L)) { - // Synchronize the RTC with NIST - Serial.println(F("Attempting to connect to the internet and synchronize RTC with NIST")); - if (modem.connectInternet(120000L)) - { - dataLogger.setRTClock(modem.getNISTTime()); - } - else - { - Serial.println(F("Could not connect to internet for clock sync.")); - } + dataLogger.setRTClock(modem.getNISTTime()); + } + else + { + Serial.println(F("Could not connect to internet for clock sync.")); } } @@ -1647,7 +1640,7 @@ void loop() // Connect to the network // Again, we're only doing this if the battery is doing well - if (getBatteryVoltage() > 3.65) + if (getBatteryVoltage() > 3.55) { if (modem.connectInternet()) { diff --git a/examples/menu_a_la_carte/platformio.ini b/examples/menu_a_la_carte/platformio.ini index 1705838b4..72d82b14d 100644 --- a/examples/menu_a_la_carte/platformio.ini +++ b/examples/menu_a_la_carte/platformio.ini @@ -25,7 +25,7 @@ build_flags = -DENABLE_SERIAL2 -DENABLE_SERIAL3 lib_deps = - EnviroDIY_ModularSensors@0.23.11 + EnviroDIY_ModularSensors@0.23.13 ; ^^ Use this when working from an official release of the library ; https://github.com/EnviroDIY/ModularSensors.git#develop ; ^^ Use this when if you want to pull from the develop branch diff --git a/examples/simple_logging/platformio.ini b/examples/simple_logging/platformio.ini index 367d6ff4c..7feb08369 100644 --- a/examples/simple_logging/platformio.ini +++ b/examples/simple_logging/platformio.ini @@ -22,7 +22,7 @@ build_flags = -DSDI12_EXTERNAL_PCINT -DNEOSWSERIAL_EXTERNAL_PCINT lib_deps = - EnviroDIY_ModularSensors@0.23.11 + EnviroDIY_ModularSensors@0.23.13 ; ^^ Use this when working from an official release of the library ; https://github.com/EnviroDIY/ModularSensors.git#develop ; ^^ Use this when if you want to pull from the develop branch diff --git a/examples/simple_logging/simple_logging.ino b/examples/simple_logging/simple_logging.ino index a4afb4708..a8ff38464 100644 --- a/examples/simple_logging/simple_logging.ino +++ b/examples/simple_logging/simple_logging.ino @@ -7,7 +7,7 @@ Software License: BSD-3. Copyright (c) 2017, Stroud Water Research Center (SWRC) and the EnviroDIY Development Team -This example sketch is written for ModularSensors library version 0.23.11 +This example sketch is written for ModularSensors library version 0.23.13 This sketch is an example of logging data to an SD card @@ -32,7 +32,7 @@ THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN. // Data Logger Settings // ========================================================================== // The library version this example was written for -const char *libraryVersion = "0.23.11"; +const char *libraryVersion = "0.23.13"; // The name of this file const char *sketchName = "simple_logging.ino"; // Logger ID, also becomes the prefix for the name of the data file on SD card diff --git a/examples/simple_logging_LearnEnviroDIY/platformio.ini b/examples/simple_logging_LearnEnviroDIY/platformio.ini index f9555af56..cd85ec3e9 100644 --- a/examples/simple_logging_LearnEnviroDIY/platformio.ini +++ b/examples/simple_logging_LearnEnviroDIY/platformio.ini @@ -22,7 +22,7 @@ build_flags = -DSDI12_EXTERNAL_PCINT -DNEOSWSERIAL_EXTERNAL_PCINT lib_deps = - EnviroDIY_ModularSensors@0.23.11 + EnviroDIY_ModularSensors@0.23.13 ; ^^ Use this when working from an official release of the library ; https://github.com/EnviroDIY/ModularSensors.git#develop ; ^^ Use this when if you want to pull from the develop branch diff --git a/examples/simple_logging_LearnEnviroDIY/simple_logging_LearnEnviroDIY.ino b/examples/simple_logging_LearnEnviroDIY/simple_logging_LearnEnviroDIY.ino index 8006d93fc..332dfea65 100644 --- a/examples/simple_logging_LearnEnviroDIY/simple_logging_LearnEnviroDIY.ino +++ b/examples/simple_logging_LearnEnviroDIY/simple_logging_LearnEnviroDIY.ino @@ -7,7 +7,7 @@ Software License: BSD-3. Copyright (c) 2017, Stroud Water Research Center (SWRC) and the EnviroDIY Development Team -This example sketch is written for ModularSensors library version 0.23.11 +This example sketch is written for ModularSensors library version 0.23.13 This sketch is an example of logging data to an SD card @@ -27,7 +27,7 @@ THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN. // Data Logger Settings // ========================================================================== // The library version this example was written for -const char *libraryVersion = "0.23.11"; +const char *libraryVersion = "0.23.13"; // The name of this file const char *sketchName = "simple_logging.ino"; // Logger ID, also becomes the prefix for the name of the data file on SD card diff --git a/examples/single_sensor/platformio.ini b/examples/single_sensor/platformio.ini index 3ea806f75..eb0c7aef3 100644 --- a/examples/single_sensor/platformio.ini +++ b/examples/single_sensor/platformio.ini @@ -22,7 +22,7 @@ build_flags = -DSDI12_EXTERNAL_PCINT -DNEOSWSERIAL_EXTERNAL_PCINT lib_deps = - EnviroDIY_ModularSensors@0.23.11 + EnviroDIY_ModularSensors@0.23.13 ; ^^ Use this when working from an official release of the library ; https://github.com/EnviroDIY/ModularSensors.git#develop ; ^^ Use this when if you want to pull from the develop branch diff --git a/examples/single_sensor/single_sensor.ino b/examples/single_sensor/single_sensor.ino index aa6dddb41..2bb564c23 100644 --- a/examples/single_sensor/single_sensor.ino +++ b/examples/single_sensor/single_sensor.ino @@ -7,7 +7,7 @@ Software License: BSD-3. Copyright (c) 2017, Stroud Water Research Center (SWRC) and the EnviroDIY Development Team -This example sketch is written for ModularSensors library version 0.23.11 +This example sketch is written for ModularSensors library version 0.23.13 This sketch is an example of getting data from a single sensor, in this case, a MaxBotix Ultrasonic Range Finder @@ -29,7 +29,7 @@ THIS CODE IS PROVIDED "AS IS" - NO WARRANTY IS GIVEN. #include // The library version this example was written for -const char *libraryVersion = "0.23.11"; +const char *libraryVersion = "0.23.13"; // The name of this file const char *sketchName = "single_sensor.ino"; diff --git a/library.json b/library.json index f38bced4a..169ba62fa 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "EnviroDIY_ModularSensors", - "version": "0.23.11", + "version": "0.23.13", "description": "A library that allows access to multiple sensors through a unified interface. This allows the user to simply access many sensors to log the data or send the data to data repositories like the EnviroDIY data portal.", "keywords": "modular, sensor, sensors, datalogger, logger, low power, sleeping, EnviroDIY, ModularSensors, Mayfly, WikiWatershed, ThingSpeak", "platforms": "atmelavr, atmelsam", @@ -38,7 +38,9 @@ [ "doc/*", "sensor_tests/*", - "compile_tests/*" + "compile_tests/*", + "travis/*", + "pioScripts/*" ] }, "examples": diff --git a/library.properties b/library.properties index 78645e519..03972a832 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=EnviroDIY_ModularSensors -version=0.23.11 +version=0.23.13 author=Sara Damiano , Shannon Hicks maintainer=Sara Damiano sentence=A library that allows access to multiple sensors through a unified interface. diff --git a/src/LoggerBase.cpp b/src/LoggerBase.cpp index f81fce829..5a2e49b4c 100644 --- a/src/LoggerBase.cpp +++ b/src/LoggerBase.cpp @@ -390,7 +390,7 @@ void Logger::registerDataPublisher(dataPublisher* publisher) uint8_t i = 0; for (; i < MAX_NUMBER_SENDERS; i++) { - if (dataPublishers[i] == publisher) + if (dataPublishers[i] == publisher) { MS_DBG(F("dataPublisher already registered.")); return; @@ -631,6 +631,25 @@ bool Logger::setRTClock(uint32_t UTCEpochSeconds) } } +// This checks that the logger time is within a "sane" range +bool Logger::isRTCSane(void) +{ + uint32_t curRTC = getNowEpoch(); + return isRTCSane(curRTC); +} +bool Logger::isRTCSane(uint32_t epochTime) +{ + if (epochTime < 1546300800 || /*Before September 01, 2019*/ + epochTime > 1735689600) /*After January 1, 2025*/ + { + return false; + } + else + { + return true; + } +} + // This sets static variables for the date/time - this is needed so that all // data outputs (SD, EnviroDIY, serial printing, etc) print the same time @@ -646,7 +665,6 @@ void Logger::markTime(void) // This checks to see if the CURRENT time is an even interval of the logging rate -// or we're in the first 15 minutes of logging bool Logger::checkInterval(void) { bool retval; @@ -669,12 +687,59 @@ bool Logger::checkInterval(void) MS_DBG(F("Not time yet.")); retval = false; } + if (!isRTCSane(checkTime)) + { + PRINTOUT(F("----- WARNING ----- !!!!!!!!!!!!!!!!!!!!")); + alertOn(); + delay(25); + alertOff(); + delay(25); + PRINTOUT(F("!!!!!!!!!! ----- WARNING ----- !!!!!!!!!!")); + alertOn(); + delay(25); + alertOff(); + delay(25); + PRINTOUT(F("!!!!!!!!!!!!!!!!!!!! ----- WARNING ----- ")); + alertOn(); + delay(25); + alertOff(); + delay(25); + PRINTOUT(' '); + alertOn(); + delay(25); + alertOff(); + delay(25); + PRINTOUT(F("The current clock timestamp is not valid!")); + alertOn(); + delay(25); + alertOff(); + delay(25); + PRINTOUT(' '); + alertOn(); + delay(25); + alertOff(); + delay(25); + PRINTOUT(F("----- WARNING ----- !!!!!!!!!!!!!!!!!!!!")); + alertOn(); + delay(25); + alertOff(); + delay(25); + PRINTOUT(F("!!!!!!!!!! ----- WARNING ----- !!!!!!!!!!")); + alertOn(); + delay(25); + alertOff(); + delay(25); + PRINTOUT(F("!!!!!!!!!!!!!!!!!!!! ----- WARNING ----- ")); + alertOn(); + delay(25); + alertOff(); + delay(25); + } return retval; } // This checks to see if the MARKED time is an even interval of the logging rate -// or we're in the first 15 minutes of logging bool Logger::checkMarkedInterval(void) { bool retval; @@ -1609,7 +1674,9 @@ void Logger::logDataAndPublish(void) publishDataToRemotes(); watchDogTimer.resetWatchDog(); - if (Logger::markedEpochTime != 0 && Logger::markedEpochTime % 86400 == 43200) + if ((Logger::markedEpochTime != 0 && + Logger::markedEpochTime % 86400 == 43200) || + !isRTCSane(Logger::markedEpochTime)) // Sync the clock at noon { MS_DBG(F("Running a daily clock sync...")); diff --git a/src/LoggerBase.h b/src/LoggerBase.h index 658fd24a6..81294823e 100644 --- a/src/LoggerBase.h +++ b/src/LoggerBase.h @@ -236,6 +236,10 @@ class Logger // This sets the real time clock to the given time bool setRTClock(uint32_t UTCEpochSeconds); + // This checks that the logger time is within a "sane" range + bool isRTCSane(void); + bool isRTCSane(uint32_t epochTime); + // This sets static variables for the date/time - this is needed so that all // data outputs (SD, EnviroDIY, serial printing, etc) print the same time // for updating the sensors - even though the routines to update the sensors diff --git a/src/ModSensorDebugger.h b/src/ModSensorDebugger.h index 2bf9b5200..f7ccc70d6 100644 --- a/src/ModSensorDebugger.h +++ b/src/ModSensorDebugger.h @@ -15,7 +15,7 @@ #include // The current library version number -#define MODULAR_SENSORS_VERSION "0.23.11" +#define MODULAR_SENSORS_VERSION "0.23.13" #ifndef STANDARD_SERIAL_OUTPUT // #if defined(ARDUINO_SAMD_ZERO) && defined(SERIAL_PORT_USBVIRTUAL) diff --git a/src/modems/DigiXBee3GBypass.cpp b/src/modems/DigiXBee3GBypass.cpp index 2332d8298..885bc903d 100644 --- a/src/modems/DigiXBee3GBypass.cpp +++ b/src/modems/DigiXBee3GBypass.cpp @@ -87,11 +87,6 @@ bool DigiXBee3GBypass::extraModemSetup(void) // Disable remote manager, enable 2G fallback gsmModem.sendAT(GF("DO"),02); success &= gsmModem.waitResponse(GF("OK\r")) == 1; - MS_DBG(F("Setting Cellular Carrier Options...")); - // Cellular carrier profile - AT&T - // Hologram says they can use any network, but I've never succeeded with anything but AT&T - gsmModem.sendAT(GF("CP"),2); - success &= gsmModem.waitResponse(GF("OK\r")) == 1; // Make sure airplane mode is off - bypass and airplane mode are incompatible MS_DBG(F("Making sure airplane mode is off...")); gsmModem.sendAT(GF("AM"),0); diff --git a/src/modems/DigiXBeeCellularTransparent.cpp b/src/modems/DigiXBeeCellularTransparent.cpp index 07a58c144..2e9d40c0c 100644 --- a/src/modems/DigiXBeeCellularTransparent.cpp +++ b/src/modems/DigiXBeeCellularTransparent.cpp @@ -46,6 +46,58 @@ MS_MODEM_CONNECT_INTERNET(DigiXBeeCellularTransparent); MS_MODEM_DISCONNECT_INTERNET(DigiXBeeCellularTransparent); +// We turn off airplane mode in the wake. +bool DigiXBeeCellularTransparent::modemWakeFxn(void) +{ + if (_modemSleepRqPin >= 0) // Don't go to sleep if there's not a wake pin! + { + MS_DBG(F("Setting pin"), _modemSleepRqPin, F("LOW to wake XBee")); + digitalWrite(_modemSleepRqPin, LOW); + MS_DBG(F("Turning off airplane mode...")); + if (gsmModem.commandMode()) + { + gsmModem.sendAT(GF("AM"),0); + gsmModem.waitResponse(); + // Write changes to flash and apply them + gsmModem.writeChanges(); + // Exit command mode + gsmModem.exitCommand(); + } + return true; + } + else + { + return true; + } +} + + +// We turn on airplane mode in before sleep +bool DigiXBeeCellularTransparent::modemSleepFxn(void) +{ + if (_modemSleepRqPin >= 0) + { + MS_DBG(F("Turning on airplane mode...")); + if (gsmModem.commandMode()) + { + gsmModem.sendAT(GF("AM"),0); + gsmModem.waitResponse(); + // Write changes to flash and apply them + gsmModem.writeChanges(); + // Exit command mode + gsmModem.exitCommand(); + } + MS_DBG(F("Setting pin"), _modemSleepRqPin, F("HIGH to put XBee to sleep")); + digitalWrite(_modemSleepRqPin, HIGH); + return true; + } + else + { + return true; + } +} + + bool DigiXBeeCellularTransparent::extraModemSetup(void) { bool success = true; @@ -67,7 +119,7 @@ bool DigiXBeeCellularTransparent::extraModemSetup(void) success &= gsmModem.waitResponse() == 1; // Turn on CTS pin - it will be LOW when the XBee is ready to receive commands // This can be used as proxy for status indication if the true status pin is not accessible - // NOTE: Only pin 12/DIO5/CTS can be used for this function + // NOTE: Only pin 12/DIO7/CTS can be used for this function gsmModem.sendAT(GF("D7"),1); success &= gsmModem.waitResponse() == 1; // Turn on the associate LED (if you're using a board with one) @@ -102,20 +154,14 @@ bool DigiXBeeCellularTransparent::extraModemSetup(void) gsmModem.sendAT(GF("TM"),64); success &= gsmModem.waitResponse() == 1; MS_DBG(F("Setting Cellular Carrier Options...")); - // Cellular carrier profile - AT&T - // Hologram says they can use any network, but I've never succeeded with anything but AT&T - gsmModem.sendAT(GF("CP"),2); + // Carrier Profile - Automatic + gsmModem.sendAT(GF("CP"),0); gsmModem.waitResponse(); // Don't check for success - only works on LTE - // Cellular network technology - LTE-M Only - // LTE-M XBee connects much faster on AT&T/Hologram when set to LTE-M only (instead of LTE-M/NB IoT) - gsmModem.sendAT(GF("N#"),2); + // Cellular network technology - LTE-M/NB IoT + gsmModem.sendAT(GF("N#"),0); gsmModem.waitResponse(); // Don't check for success - only works on LTE // Put the network connection parameters into flash success &= gsmModem.gprsConnect(_apn); - // Make sure airplane mode is off - MS_DBG(F("Making sure airplane mode is off...")); - gsmModem.sendAT(GF("AM"),0); - success &= gsmModem.waitResponse() == 1; MS_DBG(F("Ensuring XBee is in transparent mode...")); // Make sure we're really in transparent mode gsmModem.sendAT(GF("AP0")); @@ -197,48 +243,57 @@ uint32_t DigiXBeeCellularTransparent::getNISTTime(void) return 0; } - /* Must ensure that we do not ping the daylight more than once every 4 seconds */ - /* NIST clearly specifies here that this is a requirement for all software */ - /* that accesses its servers: https://tf.nist.gov/tf-cgi/servers.cgi */ - while (millis() < _lastNISTrequest + 4000) {} - - /* Make TCP connection */ - MS_DBG(F("\nConnecting to NIST daytime Server")); - bool connectionMade = false; - - /* This is the IP address of time-c-g.nist.gov */ - /* XBee's address lookup falters on time.nist.gov */ - IPAddress ip(129, 6, 15, 30); - connectionMade = gsmClient.connect(ip, 37, 15); - /* Wait again so NIST doesn't refuse us! */ - delay(4000L); - /* Try sending something to ensure connection */ - gsmClient.println('!'); - - /* Wait up to 5 seconds for a response */ - if (connectionMade) + /* Try up to 12 times to get a timestamp from NIST */ + for (uint8_t i = 0; i < 12; i++) { - uint32_t start = millis(); - while (gsmClient && gsmClient.available() < 4 && millis() - start < 5000L){} + /* Must ensure that we do not ping the daylight more than once every 4 seconds */ + /* NIST clearly specifies here that this is a requirement for all software */ + /* that accesses its servers: https://tf.nist.gov/tf-cgi/servers.cgi */ + while (millis() < _lastNISTrequest + 4000) + { + } - if (gsmClient.available() >= 4) + /* Make TCP connection */ + MS_DBG(F("\nConnecting to NIST daytime Server")); + bool connectionMade = false; + + /* This is the IP address of time-e-wwv.nist.gov */ + /* XBee's address lookup falters on time.nist.gov */ + IPAddress ip(132, 163, 97, 6); + connectionMade = gsmClient.connect(ip, 37, 15); + /* Wait again so NIST doesn't refuse us! */ + delay(4000L); + /* Try sending something to ensure connection */ + gsmClient.println('!'); + + /* Wait up to 5 seconds for a response */ + if (connectionMade) { - MS_DBG(F("NIST responded after"), millis() - start, F("ms")); - byte response[4] = {0}; - gsmClient.read(response, 4); - return parseNISTBytes(response); + uint32_t start = millis(); + while (gsmClient && gsmClient.available() < 4 && millis() - start < 5000L) + { + } + + if (gsmClient.available() >= 4) + { + MS_DBG(F("NIST responded after"), millis() - start, F("ms")); + byte response[4] = {0}; + gsmClient.read(response, 4); + gsmClient.stop(); + return parseNISTBytes(response); + } + else + { + MS_DBG(F("NIST Time server did not respond!")); + gsmClient.stop(); + } } else { - MS_DBG(F("NIST Time server did not respond!")); - return 0; + MS_DBG(F("Unable to open TCP to NIST!")); } } - else - { - MS_DBG(F("Unable to open TCP to NIST!")); - } return 0; } diff --git a/src/modems/DigiXBeeCellularTransparent.h b/src/modems/DigiXBeeCellularTransparent.h index e9f0995a2..b9dea9546 100644 --- a/src/modems/DigiXBeeCellularTransparent.h +++ b/src/modems/DigiXBeeCellularTransparent.h @@ -43,6 +43,8 @@ class DigiXBeeCellularTransparent : public DigiXBee uint8_t measurementsToAverage = 1); ~DigiXBeeCellularTransparent(); + bool modemWakeFxn(void) override; + bool modemSleepFxn(void) override; bool addSingleMeasurementResult(void) override; bool connectInternet(uint32_t maxConnectionTime = 50000L) override; diff --git a/src/modems/DigiXBeeLTEBypass.cpp b/src/modems/DigiXBeeLTEBypass.cpp index 80e55882f..618f8b04e 100644 --- a/src/modems/DigiXBeeLTEBypass.cpp +++ b/src/modems/DigiXBeeLTEBypass.cpp @@ -92,13 +92,11 @@ bool DigiXBeeLTEBypass::extraModemSetup(void) gsmModem.sendAT(GF("P1"),0); success &= gsmModem.waitResponse(GF("OK\r")) == 1; MS_DBG(F("Setting Cellular Carrier Options...")); - // Cellular carrier profile - AT&T - // Hologram says they can use any network, but I've never succeeded with anything but AT&T - gsmModem.sendAT(GF("CP"),2); + // Carrier Profile - Automatic + gsmModem.sendAT(GF("CP"),0); success &= gsmModem.waitResponse(GF("OK\r")) == 1; - // Cellular network technology - LTE-M Only - // LTE-M XBee connects much faster on AT&T/Hologram when set to LTE-M only (instead of LTE-M/NB IoT) - gsmModem.sendAT(GF("N#"),2); + // Cellular network technology - LTE-M/NB IoT + gsmModem.sendAT(GF("N#"),0); success &= gsmModem.waitResponse(GF("OK\r")) == 1; // Make sure airplane mode is off - bypass and airplane mode are incompatible MS_DBG(F("Making sure airplane mode is off...")); diff --git a/src/modems/DigiXBeeWifi.cpp b/src/modems/DigiXBeeWifi.cpp index 9a9290260..af32c0937 100644 --- a/src/modems/DigiXBeeWifi.cpp +++ b/src/modems/DigiXBeeWifi.cpp @@ -278,49 +278,58 @@ uint32_t DigiXBeeWifi::getNISTTime(void) gsmClient.stop(); - /* Must ensure that we do not ping the daylight more than once every 4 seconds */ - /* NIST clearly specifies here that this is a requirement for all software */ - /* that accesses its servers: https://tf.nist.gov/tf-cgi/servers.cgi */ - while (millis() < _lastNISTrequest + 4000) {} - - /* Make TCP connection */ - MS_DBG(F("\nConnecting to NIST daytime Server")); - bool connectionMade = false; - - /* This is the IP address of time-e-wwv.nist.gov */ - /* XBee's address lookup falters on time.nist.gov */ - IPAddress ip(132, 163, 97, 6); - connectionMade = gsmClient.connect(ip, 37); - /* Wait again so NIST doesn't refuse us! */ - delay(4000L); - /* Need to send something before connection is made */ - gsmClient.println('!'); - // delay(100); // Need this delay! Can get away with 50, but 100 is safer. - - /* Wait up to 5 seconds for a response */ - if (connectionMade) + /* Try up to 12 times to get a timestamp from NIST */ + for (uint8_t i = 0; i < 12; i++) { - uint32_t start = millis(); - while (gsmClient && gsmClient.available() < 4 && millis() - start < 5000L){} + /* Must ensure that we do not ping the daylight more than once every 4 seconds */ + /* NIST clearly specifies here that this is a requirement for all software */ + /* that accesses its servers: https://tf.nist.gov/tf-cgi/servers.cgi */ + while (millis() < _lastNISTrequest + 4000) + { + } - if (gsmClient.available() >= 4) + /* Make TCP connection */ + MS_DBG(F("\nConnecting to NIST daytime Server")); + bool connectionMade = false; + + /* This is the IP address of time-e-wwv.nist.gov */ + /* XBee's address lookup falters on time.nist.gov */ + IPAddress ip(132, 163, 97, 6); + connectionMade = gsmClient.connect(ip, 37); + /* Wait again so NIST doesn't refuse us! */ + delay(4000L); + /* Need to send something before connection is made */ + gsmClient.println('!'); + // delay(100); // Need this delay! Can get away with 50, but 100 is safer. + + /* Wait up to 5 seconds for a response */ + if (connectionMade) { - MS_DBG(F("NIST responded after"), millis() - start, F("ms")); - byte response[4] = {0}; - gsmClient.read(response, 4); - return parseNISTBytes(response); + uint32_t start = millis(); + while (gsmClient && gsmClient.available() < 4 && millis() - start < 5000L) + { + } + + if (gsmClient.available() >= 4) + { + MS_DBG(F("NIST responded after"), millis() - start, F("ms")); + byte response[4] = {0}; + gsmClient.read(response, 4); + gsmClient.stop(); + return parseNISTBytes(response); + } + else + { + MS_DBG(F("NIST Time server did not respond!")); + gsmClient.stop(); + } } else { - MS_DBG(F("NIST Time server did not respond!")); - return 0; + MS_DBG(F("Unable to open TCP to NIST!")); } } - else - { - MS_DBG(F("Unable to open TCP to NIST!")); - } return 0; } diff --git a/src/modems/EspressifESP8266.cpp b/src/modems/EspressifESP8266.cpp index 1f6bca862..b0d02e25f 100644 --- a/src/modems/EspressifESP8266.cpp +++ b/src/modems/EspressifESP8266.cpp @@ -57,6 +57,7 @@ MS_MODEM_GET_MODEM_BATTERY_NA(EspressifESP8266); MS_MODEM_GET_MODEM_TEMPERATURE_NA(EspressifESP8266); MS_MODEM_CONNECT_INTERNET(EspressifESP8266); MS_MODEM_DISCONNECT_INTERNET(EspressifESP8266); +MS_MODEM_GET_NIST_TIME(EspressifESP8266); // A helper function to wait for the esp to boot and immediately change some settings @@ -278,47 +279,3 @@ bool EspressifESP8266::startSingleMeasurement(void) return success; } - - - -// Get the time from NIST via TIME protocol (rfc868) -// This would be much more efficient if done over UDP, but I'm doing it -// over TCP because I don't have a UDP library for all the modems. -uint32_t EspressifESP8266::getNISTTime(void) -{ - // NOTE: For the ESP, we're not checking for internet connection first - - /* Must ensure that we do not ping the daylight more than once every 4 seconds */ - /* NIST clearly specifies here that this is a requirement for all software */ - /* that accesses its servers: https://tf.nist.gov/tf-cgi/servers.cgi */ - while (millis() < _lastNISTrequest + 4000) {} - - /* Make TCP connection */ - MS_DBG(F("\nConnecting to NIST daytime Server")); - bool connectionMade = gsmClient.connect("time.nist.gov", 37, 15); - - /* Wait up to 5 seconds for a response */ - if (connectionMade) - { \ - uint32_t start = millis(); - while (gsmClient && gsmClient.available() < 4 && millis() - start < 5000L){} - - if (gsmClient.available() >= 4) - { - MS_DBG(F("NIST responded after"), millis() - start, F("ms")); - byte response[4] = {0}; - gsmClient.read(response, 4); - return parseNISTBytes(response); - } - else - { - MS_DBG(F("NIST Time server did not respond!")); - return 0; - } - } - else - { - MS_DBG(F("Unable to open TCP to NIST!")); - } - return 0; -} diff --git a/src/modems/LoggerModemMacros.h b/src/modems/LoggerModemMacros.h index 606c80c69..711b6db81 100644 --- a/src/modems/LoggerModemMacros.h +++ b/src/modems/LoggerModemMacros.h @@ -333,53 +333,60 @@ // Get the time from NIST via TIME protocol (rfc868) // This would be much more efficient if done over UDP, but I'm doing it // over TCP because I don't have a UDP library for all the modems. -#define MS_MODEM_GET_NIST_TIME(specificModem) \ - uint32_t specificModem::getNISTTime(void) \ - { \ - /* bail if not connected to the internet */ \ - if (!isInternetAvailable()) \ - { \ - MS_DBG(F("No internet connection, cannot connect to NIST.")); \ - return 0; \ - } \ - \ - /* Must ensure that we do not ping the daylight more than once every 4 seconds */ \ - /* NIST clearly specifies here that this is a requirement for all software */ \ - /* that accesses its servers: https://tf.nist.gov/tf-cgi/servers.cgi */ \ - while (millis() < _lastNISTrequest + 4000) \ - { \ - } \ - \ - /* Make TCP connection */ \ - MS_DBG(F("\nConnecting to NIST daytime Server")); \ - bool connectionMade = gsmClient.connect("time.nist.gov", 37, 15); \ - \ - /* Wait up to 5 seconds for a response */ \ - if (connectionMade) \ - { \ - uint32_t start = millis(); \ - while (gsmClient && gsmClient.available() < 4 && millis() - start < 5000L) \ - { \ - } \ - \ - if (gsmClient.available() >= 4) \ - { \ - MS_DBG(F("NIST responded after"), millis() - start, F("ms")); \ - byte response[4] = {0}; \ - gsmClient.read(response, 4); \ - return parseNISTBytes(response); \ - } \ - else \ - { \ - MS_DBG(F("NIST Time server did not respond!")); \ - return 0; \ - } \ - } \ - else \ - { \ - MS_DBG(F("Unable to open TCP to NIST!")); \ - } \ - return 0; \ +#define MS_MODEM_GET_NIST_TIME(specificModem) \ + uint32_t specificModem::getNISTTime(void) \ + { \ + /* bail if not connected to the internet */ \ + if (!isInternetAvailable()) \ + { \ + MS_DBG(F("No internet connection, cannot connect to NIST.")); \ + return 0; \ + } \ + \ + /* Try up to 12 times to get a timestamp from NIST */ \ + for (uint8_t i = 0; i < 12; i++) \ + { \ + /* Must ensure that we do not ping the daylight server more than once every 4 seconds */ \ + /* NIST clearly specifies here that this is a requirement for all software */ \ + /* that accesses its servers: https://tf.nist.gov/tf-cgi/servers.cgi */ \ + while (millis() < _lastNISTrequest + 4000) \ + { \ + } \ + \ + /* Make TCP connection */ \ + MS_DBG(F("\nConnecting to NIST daytime Server")); \ + bool connectionMade = gsmClient.connect("time.nist.gov", 37, 15); \ + \ + /* Wait up to 5 seconds for a response */ \ + if (connectionMade) \ + { \ + uint32_t start = millis(); \ + while (gsmClient && gsmClient.available() < 4 && millis() - start < 5000L) \ + { \ + } \ + \ + if (gsmClient.available() >= 4) \ + { \ + MS_DBG(F("NIST responded after"), millis() - start, F("ms")); \ + byte response[4] = {0}; \ + gsmClient.read(response, 4); \ + if (gsmClient.connected()) \ + gsmClient.stop(); \ + return parseNISTBytes(response); \ + } \ + else \ + { \ + MS_DBG(F("NIST Time server did not respond!")); \ + if (gsmClient.connected()) \ + gsmClient.stop(); \ + } \ + } \ + else \ + { \ + MS_DBG(F("Unable to open TCP to NIST!")); \ + } \ + } \ + return 0; \ } #endif diff --git a/tools/sdi12_address_change/platformio.ini b/tools/sdi12_address_change/platformio.ini index 5a76d1ca6..51a595960 100644 --- a/tools/sdi12_address_change/platformio.ini +++ b/tools/sdi12_address_change/platformio.ini @@ -26,7 +26,7 @@ build_flags = -DENABLE_SERIAL2 -DENABLE_SERIAL3 lib_deps = - EnviroDIY_ModularSensors@0.23.11 + EnviroDIY_ModularSensors@0.23.13 ; ^^ Use this when working from an official release of the library ; https://github.com/EnviroDIY/ModularSensors.git#develop ; ^^ Use this when if you want to pull from the develop branch