This advanced example sends one manufacturer-specific command with SDI12Recorder::startRawCommand(). Replace the example command body with the value documented by the sensor manufacturer. Do not include the sensor address or terminating exclamation point.
The raw path validates the response address and retry timing, but it does not interpret the remaining payload or validate a command-specific CRC. It also invalidates retained measurement context for the addressed sensor. Use a typed recorder method for every standard command that has one.
PlatformIO Configuration
1; PlatformIO Project Configuration File
4description = SDI-12 Library Advanced Example: Raw Extended Commands
5src_dir = .piolibdeps/Arduino-SDI-12_ID1486/examples/extras/raw_extended_commands
The Complete Example
2 * @example{lineno} raw_extended_commands.ino
3 * @copyright Stroud Water Research Center
4 * @license This example is published under the BSD-3 license.
5 * @author Codex, at instruction of Sara Geleskie Damiano <sdamiano@stroudcenter.org>
7 * @brief Send a manufacturer-specific extended command through SDI12Recorder.
10#include <SDI12Config.h>
11#if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) && !defined(SDI12_INTERNAL_PCINT)
12#include <EnableInterrupt.h>
15#include <SDI12Recorder.h>
18#define SDI12_DATA_PIN 7
20#ifndef SDI12_POWER_PIN
21#define SDI12_POWER_PIN 22
23#ifndef SDI12_TERMINAL_BAUD
24#define SDI12_TERMINAL_BAUD 115200
27const int8_t dataPin = SDI12_DATA_PIN;
28const int8_t powerPin = SDI12_POWER_PIN;
29const uint32_t serialBaud = SDI12_TERMINAL_BAUD;
30const char sensorAddress = '0';
32// Replace X with the command body documented by the sensor manufacturer. Do not
33// include the sensor address or terminating exclamation point.
34const String extendedCommand = "X";
36SDI12 mySDI12(dataPin);
37SDI12Recorder mySDI12Recorder(mySDI12);
39bool commandStarted = false;
40bool resultPrinted = false;
43 Serial.begin(serialBaud);
44 while (!Serial && millis() < 10000UL);
47 pinMode(powerPin, OUTPUT);
48 digitalWrite(powerPin, HIGH);
56 if (!commandStarted) {
57 mySDI12Recorder.startRawCommand(sensorAddress, extendedCommand);
58 commandStarted = true;
61 mySDI12Recorder.update();
63 if (!resultPrinted && mySDI12Recorder.isOperationComplete()) {
64 if (mySDI12Recorder.result() == SDI12Recorder::RESULT_SUCCESS) {
65 Serial.print(F("Opaque response payload: "));
66 Serial.println(mySDI12Recorder.response());
68 Serial.print(F("Extended command failed: "));
69 mySDI12Recorder.printRecorderResult(Serial);