Arduino library source: https://github.com/joranbeasley/SDISerial
The problem I'm having is when I'm trying to get the measurement from sensor using SDI12 I only receive first digit which is channel number of the device.
This is how it should work:
Master: 1M! (Measure)
Sonde: 10617[CR][LF] (ch1, 061s to measure,7 sensors).
Sonde: 1[CR][LF] (Measurement ready)
Master: 1D0! (Send data)
Sonde: 1+17.5+12.05+98.7+8.25+6.45[CR][LF]
Master: 1D1! (Send rest of the data)
Sonde: 1-325+10[CR][LF]
The only thing I'm receiving after 1D0! command is "1". I think that it must be because of the + - operator in the measurement data device sends (1+17.5+12.05+98.7+8.25+6.45). I've tried to understand the library code (.cpp and .h), but had no luck with solving this problem. Any thoughts on how this could be fixed?
Arduino code:
#define DATALINE_PIN 2
#define INVERTED 1
#define MAX_TIMEOUT 1000
//see: http://arduino.cc/en/Reference/attachInterrupt
//for pins that support interupts (2 or 3 typically)
SDISerial connection(DATALINE_PIN, INVERTED);
char b_in[125];
char output_buffer[255];
char tmp_buffer[10];
void wait_for_message(char* buffer,char terminal){
Serial.println("Waiting For input...");
int i=0;
while( true){
if(!Serial.available())delay(500);
else{
buffer[i] = Serial.read();
if(buffer[i] == terminal){
buffer[i+1] = '\0';
return;
}
i+=(buffer[i] >= 32 && buffer[i] <= 127);
}
}
}
void setup(){
Serial.begin(9600);
connection.begin();
delay(1000);
Serial.println("Initialization Complete");
}
void loop(){
wait_for_message(b_in,'!');
sprintf(output_buffer,"[out]:%s",b_in?b_in:"No Output");
Serial.println(output_buffer);
char *response =connection.sdi_query(b_in,MAX_TIMEOUT);
//sprintf(output_buffer,"[in]:%s",response?response:"No Response");
Serial.println(response);
Serial.flush();
delay(1000);
}