Open bevingtona opened 1 year ago
@HunterGleason
When there are negative SDI-12 responses are note parsed properly in DATA.csv
IT looks like this, with water level and temp in the same cell: datetime,batt_v,mem,water_level_m,water_temp_c,ec_ds_m 2024-03-27T15:00:05,3.64,25835,26-1.6,0 2024-03-27T15:17:02,3.64,25835,18,1.5,0
has to do with the parsing:
String sample_hydros_M() {
myCommand = String(SENSOR_ADDRESS) + "M!"; // first command to take a measurement
mySDI12.sendCommand(myCommand);
delay(30); // wait a while for a response
while (mySDI12.available()) { // build response string
char c = mySDI12.read();
if ((c != '\n') && (c != '\r')) {
sdiResponse += c;
delay(10); // 1 character ~ 7.5ms
}
}
/*Clear buffer*/
if (sdiResponse.length() > 1)
mySDI12.clearBuffer();
delay(2000); // delay between taking reading and requesting data
sdiResponse = ""; // clear the response string
// next command to request data from last measurement
myCommand = String(SENSOR_ADDRESS) + "D0!";
mySDI12.sendCommand(myCommand);
delay(30); // wait a while for a response
while (mySDI12.available()) { // build string from response
char c = mySDI12.read();
if ((c != '\n') && (c != '\r')) {
sdiResponse += c;
delay(10); // 1 character ~ 7.5ms
}
}
sdiResponse = sdiResponse.substring(3);
for (int i = 0; i < sdiResponse.length(); i++) {
char c = sdiResponse.charAt(i);
if (c == '+') {
sdiResponse.setCharAt(i, ',');
}
}
//clear buffer
if (sdiResponse.length() > 1)
mySDI12.clearBuffer();
if (sdiResponse == "")
sdiResponse = "-9,-9,-9";
return sdiResponse;
}
Maybe a patch like this:
void parseData(String dataString) {
// Example dataString format: "1234,-5.6,OK" or "1234-5.6,OK" with missing comma
// Check and correct for missing comma before negative temperature
int tempSignIndex = dataString.indexOf('-', 1); // Start search after the first character
if (tempSignIndex > 0 && dataString[tempSignIndex - 1] != ',') {
// Insert comma if missing before negative sign
dataString = dataString.substring(0, tempSignIndex) + "," + dataString.substring(tempSignIndex);
}
// Now split the corrected string
int firstComma = dataString.indexOf(',');
int secondComma = dataString.indexOf(',', firstComma + 1);
String waterLevelStr = dataString.substring(0, firstComma);
String waterTempStr = dataString.substring(firstComma + 1, secondComma);
String ottStatus = dataString.substring(secondComma + 1);
// Convert to appropriate data types
int waterLevelMM = waterLevelStr.toInt();
float waterTempC = waterTempStr.toFloat();
// Example usage of parsed data
Serial.print("Water Level (mm): ");
Serial.println(waterLevelMM);
Serial.print("Water Temperature (C): ");
Serial.println(waterTempC);
Serial.print("OTT Status: ");
Serial.println(ottStatus);
// Add your handling of parsed data here
}
Hey Alex,
Just so I am clear on what the issue is, sounds like the mySDI12.read(); command reports the output from the OTT-PLS with a missing comma whenever there is a negative water temperature. Wonder if this is an issue in the SDI-12 package we import? Were we having issues with this in previous versions?
Looks like the fix below would catch the occasions when the comma is missing. Guess I’m just curious why the comma is missing in the first place?
Hunter
From: Alexandre Bevington @.> Sent: Monday, April 1, 2024 2:43 PM To: bevingtona/RemoteLogger @.> Cc: Gleason, Hunter ENV:EX @.>; Mention @.> Subject: Re: [bevingtona/RemoteLogger] Bad SDI parsing for negative temps (Issue #1)
[EXTERNAL] This email came from an external source. Only open attachments or links that you are expecting from a known sender.
Maybe a patch like this:
void parseData(String dataString) {
// Example dataString format: "1234,-5.6,OK" or "1234-5.6,OK" with missing comma
// Check and correct for missing comma before negative temperature
int tempSignIndex = dataString.indexOf('-', 1); // Start search after the first character
if (tempSignIndex > 0 && dataString[tempSignIndex - 1] != ',') {
// Insert comma if missing before negative sign
dataString = dataString.substring(0, tempSignIndex) + "," + dataString.substring(tempSignIndex);
}
// Now split the corrected string
int firstComma = dataString.indexOf(',');
int secondComma = dataString.indexOf(',', firstComma + 1);
String waterLevelStr = dataString.substring(0, firstComma);
String waterTempStr = dataString.substring(firstComma + 1, secondComma);
String ottStatus = dataString.substring(secondComma + 1);
// Convert to appropriate data types
int waterLevelMM = waterLevelStr.toInt();
float waterTempC = waterTempStr.toFloat();
// Example usage of parsed data
Serial.print("Water Level (mm): ");
Serial.println(waterLevelMM);
Serial.print("Water Temperature (C): ");
Serial.println(waterTempC);
Serial.print("OTT Status: ");
Serial.println(ottStatus);
// Add your handling of parsed data here
}
— Reply to this email directly, view it on GitHubhttps://github.com/bevingtona/RemoteLogger/issues/1#issuecomment-2030612099, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKCKPCYEWVSYHWGMPDPSLGTY3HIGJAVCNFSM6AAAAAAXTAW7A6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZQGYYTEMBZHE. You are receiving this because you were mentioned.Message ID: @.**@.>>
It's both the Hydros-21 and the OTT-PLS 500
0.001-0.1,1 should have a comma in front of -