EnviroDIY / Arduino-SDI-12

An Arduino library for SDI-12 communication with a wide variety of environmental sensors. This library provides a general software solution, without requiring any additional hardware.
https://github.com/EnviroDIY/Arduino-SDI-12/wiki
BSD 3-Clause "New" or "Revised" License
158 stars 99 forks source link

fixed issue in slave example where some commands sent slave into unresponsive state #135

Closed StephenCatsamas closed 1 month ago

StephenCatsamas commented 5 months ago

This pull request fixes an issue in example: h_SDI-12_slave_implementation.ino

Previously sending some commands (eg: 5!) would lead to a call of forceHold() without a call to forceListen(). This would send the slave into an unresponsive state.

ltan10 commented 1 month ago

A more elegant fix for this should be to immediately set the line to listen immediately after the command processing is done as it does not utilize another whole cycle before the mcu process the command. I'm currently working on a more compliant end node support but i haven't finished yet. Still in the testing phase, the following is a snippet which precludes another process cycle.

if (charReceived == '!') {
    // eliminate the chance of getting anything else after the '!'
    slaveSDI12.forceHold();
    // Command string is completed; do something with it
    parseSdi12Cmd(commandReceived, dValues);
    slaveSDI12.forceListen(); // Immediately release line after parsing
    // Clear command string to reset for next command
    commandReceived = "";
    // '!' should be the last available character anyway, but exit the "for"
    // loop just in case there are any stray characters
    slaveSDI12.clearBuffer();
    break;
} else {