From 87631aac743d4a7098b7ed813272f09be423fb70 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 2 Apr 2022 12:57:35 +0100 Subject: fix data logging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- datalog.h | 20 ++++++++++++++------ 1 file 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); -- cgit v1.2.3