From 001858498e2ecb189cad81fc1a3105baafd88560 Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Sun, 15 Dec 2024 16:51:46 -0700 Subject: [PATCH] toggleing sesor into sleep mode between readings.. power saving. --- .../Telemetry/Sensor/RAK12035VBSensor.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/modules/Telemetry/Sensor/RAK12035VBSensor.cpp b/src/modules/Telemetry/Sensor/RAK12035VBSensor.cpp index a36655c39..0ef3f1d57 100644 --- a/src/modules/Telemetry/Sensor/RAK12035VBSensor.cpp +++ b/src/modules/Telemetry/Sensor/RAK12035VBSensor.cpp @@ -30,6 +30,7 @@ int32_t RAK12035VBSensor::runOnce() LOG_ERROR("RAK12035VBSensor Init Failed"); status = false; } + sensor.sensor_sleep(); return initI2CSensor(); } @@ -40,9 +41,11 @@ void RAK12035VBSensor::setup() { uint16_t hundred_val = 0; uint16_t default_zero_val = 550; uint16_t default_hundred_val = 420; + sensor.sensor_on(); + delay(200); sensor.get_dry_cal(&zero_val); sensor.get_wet_cal(&hundred_val); - delay(100); + delay(200); if(zero_val == 0 || zero_val <= hundred_val){ LOG_ERROR("Dry calibration value is %d", zero_val); LOG_ERROR("Wet calibration value is %d", hundred_val); @@ -61,7 +64,8 @@ void RAK12035VBSensor::setup() { sensor.get_wet_cal(&hundred_val); LOG_ERROR("Wet calibration reset complete. New value is %d", hundred_val); } - delay(100); + sensor.sensor_sleep(); + delay(200); LOG_INFO("Dry calibration value is %d", zero_val); LOG_INFO("Wet calibration value is %d", hundred_val); } @@ -75,11 +79,14 @@ bool RAK12035VBSensor::getMetrics(meshtastic_Telemetry *measurement) uint16_t temp = 0; bool success = false; + sensor.sensor_on(); + delay(200); success = sensor.get_sensor_moisture(&moisture); - delay(500); + delay(200); success = sensor.get_sensor_temperature(&temp); - delay(500); - + delay(200); + sensor.sensor_sleep(); + if(success == false){ LOG_ERROR("Failed to read sensor data"); return false;