From 6a3c047427c2175f24cd91ab8abb71d8bbc20916 Mon Sep 17 00:00:00 2001 From: Sara Damiano Date: Wed, 5 May 2021 16:27:17 -0400 Subject: [PATCH] Set default wake delay back to 0 Signed-off-by: Sara Damiano --- ChangeLog.md | 7 ++++++ VERSION | 2 +- docs/Doxyfile | 2 +- library.json | 2 +- library.properties | 2 +- src/SDI12.h | 16 +++++++++--- tools/TestCommands/TestCommands.ino | 38 +++++++++++++++++------------ 7 files changed, 47 insertions(+), 22 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 21d12ab..2729374 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 **** +## v2.1.4 (2021-05-05) [Revert wake delay to 0ms](https://github.com/EnviroDIY/Arduino-SDI-12/releases/tag/v2.1.4) + +### Possibly breaking changes +- Reverted the default wake delay to 0ms. + - In 92055d377b26fa862c43d1429de1ccbef054af01 this was bumped up to 10ms, which caused problems for several people. + - The delay can now also be set using the build flag `-D SDI12_WAKE_DELAY=#` + ## v2.1.3 (2021-03-24) [Migrate to GitHub Actions](https://github.com/EnviroDIY/Arduino-SDI-12/releases/tag/v2.1.3) ### Improvements diff --git a/VERSION b/VERSION index 557fefc..0f84bed 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v2.1.3 \ No newline at end of file +v2.1.4 \ No newline at end of file diff --git a/docs/Doxyfile b/docs/Doxyfile index 2167b1e..7caadfc 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = "SDI-12 for Arduino" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 2.1.3 +PROJECT_NUMBER = 2.1.4 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/library.json b/library.json index ffad197..95b25f7 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "SDI-12", - "version": "2.1.3", + "version": "2.1.4", "keywords": "SDI-12, sdi12, communication, bus, sensor, Decagon", "description": "An Arduino library for SDI-12 communication with a wide variety of environmental sensors.", "repository": { diff --git a/library.properties b/library.properties index c5b7c28..83a2da9 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SDI-12 -version=2.1.3 +version=2.1.4 author=Kevin M. Smith , Shannon Hicks maintainer=Sara Damiano sentence=An Arduino library for SDI-12 communication with a wide variety of environmental sensors. diff --git a/src/SDI12.h b/src/SDI12.h index 20a5f9b..ec949e3 100644 --- a/src/SDI12.h +++ b/src/SDI12.h @@ -137,6 +137,16 @@ typedef const __FlashStringHelper* FlashString; /// a char not found in a valid ASCII numeric field #define NO_IGNORE_CHAR '\x01' +#ifndef SDI12_WAKE_DELAY +/** + * @brief The amount of additional time in milliseconds that the sensor takes to wake + * before being ready to receive a command. Default is 0ms - meaning the sensor is + * ready for a command by the end of the 12ms break. Per protocol, the wake time must + * be less than 100 ms. + */ +#define SDI12_WAKE_DELAY 0 +#endif + #ifndef SDI12_BUFFER_SIZE /** * @brief The buffer size for incoming SDI-12 data. @@ -894,11 +904,11 @@ class SDI12 : public Stream { * the sensor is ready for a command by the end of the 12ms break. Per protocol, the * wake time must be less than 100 ms. */ - void sendCommand(String& cmd, int8_t extraWakeTime = 10); + void sendCommand(String& cmd, int8_t extraWakeTime = SDI12_WAKE_DELAY); /// @copydoc SDI12::sendCommand(String&, int8_t) - void sendCommand(const char* cmd, int8_t extraWakeTime = 10); + void sendCommand(const char* cmd, int8_t extraWakeTime = SDI12_WAKE_DELAY); /// @copydoc SDI12::sendCommand(String&, int8_t) - void sendCommand(FlashString cmd, int8_t extraWakeTime = 10); + void sendCommand(FlashString cmd, int8_t extraWakeTime = SDI12_WAKE_DELAY); /** * @brief Send a response out on the data line (for slave use) diff --git a/tools/TestCommands/TestCommands.ino b/tools/TestCommands/TestCommands.ino index 9b5f447..3a83f55 100644 --- a/tools/TestCommands/TestCommands.ino +++ b/tools/TestCommands/TestCommands.ino @@ -30,10 +30,10 @@ #define DATA_PIN 7 /*!< The pin of the SDI-12 data bus */ #define POWER_PIN 22 /*!< The sensor power pin (or -1 if not switching power) */ #define FIRST_ADDRESS 0 -#define LAST_ADDRESS 1 // 62 +#define LAST_ADDRESS 6 // 62 #define WAKE_DELAY 0 /*!< The extra time needed for the board to wake. */ #define COMMANDS_TO_TEST \ - 10 /*!< The number of measurement commands to test, between 1 and 10. */ + 2 /*!< The number of measurement commands to test, between 1 and 11. */ /** Define the SDI-12 bus */ SDI12 mySDI12(DATA_PIN); @@ -41,7 +41,7 @@ SDI12 mySDI12(DATA_PIN); /// variable that alternates output type back and forth between parsed and raw boolean flip = 0; -String commands[] = {"2", "2", "2", "2", "2", "2", "2", "2", "", "1", "3", "4", "5", "6", "7", "8", "9"}; +String commands[] = {"","0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}; // keeps track of active addresses bool isActive[LAST_ADDRESS - FIRST_ADDRESS] = { @@ -425,7 +425,7 @@ String takeMeasurement(char i, String meas_type = "", bool printCommands = true) mySDI12.clearBuffer(); // return getResults(i, numResults,printCommands); - String res= getStringResults(i, numResults, printCommands); + String res = getStringResults(i, numResults, printCommands); Serial.print("Result: "); Serial.println(res); return res; @@ -529,9 +529,9 @@ void setup() { } void loop() { - flip = !flip; // flip the switch between concurrent and not + // flip = !flip; // flip the switch between concurrent and not // flip = 1; - // flip = 0; + flip = 0; uint32_t start = millis(); Serial.print("Flip: "); Serial.println(flip); @@ -559,8 +559,11 @@ void loop() { if (isActive[i]) { for (uint8_t a = 0; a < COMMANDS_TO_TEST; a++) { Serial.print("Command "); - Serial.println(commands[a]); - this_result[i] = takeMeasurement(addr, commands[a], false); + Serial.print(i); + Serial.print("M"); + Serial.print(commands[a]); + Serial.println('!'); + this_result[i] = takeMeasurement(addr, commands[a], true); } // getContinuousResults(addr, 3); Serial.println(); @@ -570,19 +573,24 @@ void loop() { Serial.println(millis() - start); } else { for (uint8_t a = 0; a < COMMANDS_TO_TEST; a++) { - Serial.print("Command "); - Serial.println(commands[a]); - uint8_t min_wait = 127; - uint8_t max_wait = 0; + uint8_t min_wait = 127; + uint8_t max_wait = 0; uint32_t for_start = millis(); // start all sensors measuring concurrently for (byte i = FIRST_ADDRESS; i < LAST_ADDRESS; i++) { char addr = decToChar(i); - if (isActive[i]) { startConcurrentMeasurement(addr, commands[a], false); } + if (isActive[i]) { + Serial.print("Command "); + Serial.print(i); + Serial.print("C"); + Serial.print(commands[a]); + Serial.println('!'); + startConcurrentMeasurement(addr, commands[a], true); + } if (waitTime[i] < min_wait) { min_wait = waitTime[i]; } if (waitTime[i] > max_wait) { max_wait = waitTime[i]; } } - min_wait = max(0, (min_wait - 1) / 2); + min_wait = max(1, (min_wait - 1) / 2); max_wait = max(1, max_wait + 1); // Serial.print("minimum expected wait: "); // Serial.println(min_wait); @@ -604,7 +612,7 @@ void loop() { // if (millis() > millisReady[i]) { // if (millis() > millisStarted[i] + a) { if (returnedResults[i] > 0) { - this_result[i] = getStringResults(addr, returnedResults[i], false); + this_result[i] = getStringResults(addr, returnedResults[i], true); // if (this_result[i] != "") { // Serial.print("timeWaited: "); // Serial.print(timeWaited);