aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2022-04-02 12:57:35 +0100
committerdakkar <dakkar@thenautilus.net>2022-04-02 12:57:35 +0100
commit87631aac743d4a7098b7ed813272f09be423fb70 (patch)
tree4a18a8ccb0854397a8665e43520a887b9cccc63b
parentsimple serial command protocol (diff)
downloadenv-sensor-87631aac743d4a7098b7ed813272f09be423fb70.tar.gz
env-sensor-87631aac743d4a7098b7ed813272f09be423fb70.tar.bz2
env-sensor-87631aac743d4a7098b7ed813272f09be423fb70.zip
fix data logging
when pm measurements went above 1k, the string got truncated ☹ remove the sign bits from columns that don't need them! also, uptime can be 6 digits
-rw-r--r--datalog.h20
1 files changed, 14 insertions, 6 deletions
diff --git a/datalog.h b/datalog.h
index 8f7bd81..47833ac 100644
--- a/datalog.h
+++ b/datalog.h
@@ -13,10 +13,18 @@ const int mySD_MOSI=15;
we write fixed-length CSV lines because, at some point in the
future, I may need to seek "10 measurements back" or something like
that; also, it's easier to read
+
+ column ranges and sizes:
+ * secs: up to ~36 hours = 130000, unsigned: 6 characters
+ * co2: up to ~4000, unsigned: 4 characters
+ * temp: -20.0 … +40.0, signed: 5 characters
+ * humid: 0.0 … 100.0, unsigned: 5 characters
+ * pm*: 0.0 … 9999.9, unsigned: 6 characters
+ * batt: 3.00 … 4.30, unsigned: 4 characters
*/
-// 12345, 12345, 12345, 12345, 123456, 123456, 123456, 123456, 12345\n
-const char csvHeader[]=" secs, co2, temp, humid, pm1, pm2.5, pm4, pm10, batt\n";
-const char csvFormat[]="% 5lu, % 5u, % 5.1f, % 5.1f, % 6.1f, % 6.1f, % 6.1f, % 6.1f, % 5.2f\n";
+// 123456, 1234, 12345, 12345, 123456, 123456, 123456, 123456, 1234\n
+const char csvHeader[]=" secs, co2, temp, humid, pm1, pm2.5, pm4, pm10, batt\n";
+const char csvFormat[]="% 6lu, % 4u, % 5.1f, %5.1f, %6.1f, %6.1f, %6.1f, %6.1f, %4.2f\n";
const size_t lineLength=66;
class DataLog {
@@ -49,14 +57,14 @@ public:
data->co2,
data->temperature,
- data->humidity,
+ max(0.0f,data->humidity),
- data->pm.mc_1p0,
+ max(0.0f,data->pm.mc_1p0),
max(0.0f,data->pm.mc_2p5 - data->pm.mc_1p0),
max(0.0f,data->pm.mc_4p0 - data->pm.mc_2p5),
max(0.0f,data->pm.mc_10p0 - data->pm.mc_4p0),
- data->batteryVoltage
+ max(0.0f,data->batteryVoltage)
);
size_t written=logfile.write((uint8_t *)line,lineLength);
Serial.print("# ");Serial.write(line);