diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index cfbb32c55..deec0b304 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -347,14 +347,19 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) case RAK12035VB_ADDR: // (0x20) can be RAK12023VB Soil Sensor or TCA9535 I2C expander // check if it is a RAK12035, if not can assume it is a TCA9535 I2C expander - registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x20), 1); // get ID - if (registerValue == 0xC0) { + // registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x20), 1); // get ID + // if (registerValue == 0xC0) { + // type = RAK12035VB; + // LOG_INFO("RAK12035VB Soil Sensor found\n"); + // } else { + // type = TCA9535; + // LOG_INFO("TCA9535 I2C expander found\n"); + // } + // break; + + // ^^^^^^^^^^^ not working... so we will just assume it is a RAK12035VB Soil Sensor so I can keep testing. type = RAK12035VB; - LOG_INFO("RAK12023VB Soil Sensor found\n"); - } else { - type = TCA9535; - LOG_INFO("TCA9535 I2C expander found\n"); - } + LOG_INFO("RAK12035VB Soil Sensor found\n"); break; @@ -362,9 +367,6 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) - - - case MCP9808_ADDR: // We need to check for STK8BAXX first, since register 0x07 is new data flag for the z-axis and can produce some // weird result. and register 0x00 doesn't seems to be colliding with MCP9808 and LIS3DH chips. diff --git a/src/mesh/generated/meshtastic/telemetry.pb.h b/src/mesh/generated/meshtastic/telemetry.pb.h index eca192397..1fbc51475 100644 --- a/src/mesh/generated/meshtastic/telemetry.pb.h +++ b/src/mesh/generated/meshtastic/telemetry.pb.h @@ -111,7 +111,7 @@ typedef struct _meshtastic_EnvironmentMetrics { uint16_t soil_moisture; /* Soil temperature measured */ bool has_soil_temperature; - double soil_temperature; + float soil_temperature; /* Temperature measured */ bool has_temperature; float temperature; diff --git a/src/modules/Telemetry/Sensor/RAK12035VBSensor.cpp b/src/modules/Telemetry/Sensor/RAK12035VBSensor.cpp index 4d336b0c2..581417c45 100644 --- a/src/modules/Telemetry/Sensor/RAK12035VBSensor.cpp +++ b/src/modules/Telemetry/Sensor/RAK12035VBSensor.cpp @@ -1,6 +1,6 @@ #include "configuration.h" -#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSO #include "../mesh/generated/meshtastic/telemetry.pb.h" #include "RAK12035VBSensor.h" @@ -14,6 +14,8 @@ int32_t RAK12035VBSensor::runOnce() return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } + sensor.set_sensor_addr(RAK12035VB_ADDR); + sensor.begin(); // Get sensor firmware version uint8_t data = 0; @@ -34,10 +36,18 @@ int32_t RAK12035VBSensor::runOnce() void RAK12035VBSensor::setup() { // Set the calibration values // Reading the saved calibration values from the sensor. - uint16_t zero_val = 73; - uint16_t hundred_val = 250; + uint16_t zero_val = 0; + uint16_t hundred_val = 0; + uint16_t default_zero_val = 400; + uint16_t default_hundred_val = 560; sensor.get_dry_cal(&zero_val); sensor.get_wet_cal(&hundred_val); + delay(100); + if(zero_val == 0 || zero_val >= hundred_val) + sensor.set_dry_cal(default_zero_val); + if(hundred_val == 0 || hundred_val <= zero_val) + sensor.set_wet_cal(default_hundred_val); + delay(100); LOG_INFO("Dry calibration value is %d\n", zero_val); LOG_INFO("Wet calibration value is %d\n", hundred_val); } @@ -51,7 +61,8 @@ bool RAK12035VBSensor::getMetrics(meshtastic_Telemetry *measurement) uint16_t temp = 0; sensor.get_sensor_moisture(&moisture); sensor.get_sensor_temperature(&temp); - measurement->variant.environment_metrics.soil_temperature = (double)temp/10.0; + delay(100); + measurement->variant.environment_metrics.soil_temperature = temp/10.0; measurement->variant.environment_metrics.soil_moisture = moisture; return true; }