From fee9166377ca8440f88fdf9166b39c32703bd843 Mon Sep 17 00:00:00 2001 From: Tom Fifield Date: Fri, 7 Mar 2025 20:22:52 +0800 Subject: [PATCH 01/38] [WIP] Add RAK12035VB Soil Moisture Sensor support Introduce the RAK12035 sensor as an environmental telemetry sensor, including necessary calibration checks and default values. Update relevant files to integrate the sensor into the existing telemetry system. This hardware is not just one module, but a couple.. RAK12023 and RAK12035 is the component stack, the RAK12023 does not seem to matter much and allows for multiple RAK12035 devices to be used. Co-Authored-By: @Justin-Mann --- src/configuration.h | 9 ++ src/detect/ScanI2C.h | 1 + src/detect/ScanI2CTwoWire.cpp | 14 ++- src/main.cpp | 1 + .../Telemetry/EnvironmentTelemetry.cpp | 28 +++++ .../Telemetry/Sensor/RAK12035Sensor.cpp | 118 ++++++++++++++++++ src/modules/Telemetry/Sensor/RAK12035Sensor.h | 29 +++++ variants/rak4631/platformio.ini | 3 +- variants/rak4631/variant.h | 5 +- variants/rak4631_epaper/platformio.ini | 1 + variants/rak4631_epaper/variant.h | 5 +- variants/rak4631_epaper_onrxtx/platformio.ini | 1 + variants/rak4631_epaper_onrxtx/variant.h | 7 +- variants/rak4631_eth_gw/variant.h | 5 +- variants/rak_wismeshtap/platformio.ini | 1 + variants/rak_wismeshtap/variant.h | 4 +- 16 files changed, 224 insertions(+), 8 deletions(-) create mode 100644 src/modules/Telemetry/Sensor/RAK12035Sensor.cpp create mode 100644 src/modules/Telemetry/Sensor/RAK12035Sensor.h diff --git a/src/configuration.h b/src/configuration.h index fd4a5b196..3a0a2ac6e 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -186,6 +186,15 @@ along with this program. If not, see . // ----------------------------------------------------------------------------- #define FT6336U_ADDR 0x48 +// ----------------------------------------------------------------------------- +// RAK12035VB Soil Monitor (using RAK12023 up to 3 RAK12035 monitors can be connected) +// - the default i2c address for this sensor is 0x20, and users are instructed to +// set 0x21 and 0x22 for the second and third sensor if present. +// ----------------------------------------------------------------------------- +#define RAK120351_ADDR 0x20 +#define RAK120352_ADDR 0x21 +#define RAK120353_ADDR 0x22 + // ----------------------------------------------------------------------------- // BIAS-T Generator // ----------------------------------------------------------------------------- diff --git a/src/detect/ScanI2C.h b/src/detect/ScanI2C.h index 5b6bbe629..8f6f5e7c2 100644 --- a/src/detect/ScanI2C.h +++ b/src/detect/ScanI2C.h @@ -69,6 +69,7 @@ class ScanI2C DFROBOT_RAIN, DPS310, LTR390UV, + RAK12035, } DeviceType; // typedef uint8_t DeviceAddress; diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 8b779277d..d28d0f687 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -417,9 +417,21 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) logFoundDevice("BMA423", (uint8_t)addr.address); } break; + case TCA9535_ADDR: + case RAK120352_ADDR: + case RAK120353_ADDR: + registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x02), 1); + if (registerValue == addr.address) { // RAK12035 returns its I2C address at 0x02 (eg 0x20) + type = RAK12035; + logFoundDevice("RAK12035", (uint8_t)addr.address); + } else { + type = TCA9535; + logFoundDevice("TCA9535", (uint8_t)addr.address); + } + + break; SCAN_SIMPLE_CASE(LSM6DS3_ADDR, LSM6DS3, "LSM6DS3", (uint8_t)addr.address); - SCAN_SIMPLE_CASE(TCA9535_ADDR, TCA9535, "TCA9535", (uint8_t)addr.address); SCAN_SIMPLE_CASE(TCA9555_ADDR, TCA9555, "TCA9555", (uint8_t)addr.address); SCAN_SIMPLE_CASE(VEML7700_ADDR, VEML7700, "VEML7700", (uint8_t)addr.address); SCAN_SIMPLE_CASE(TSL25911_ADDR, TSL2591, "TSL2591", (uint8_t)addr.address); diff --git a/src/main.cpp b/src/main.cpp index 6b8089eaa..607dfc5ad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -643,6 +643,7 @@ void setup() scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::DFROBOT_RAIN, meshtastic_TelemetrySensorType_DFROBOT_RAIN); scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::LTR390UV, meshtastic_TelemetrySensorType_LTR390UV); scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::DPS310, meshtastic_TelemetrySensorType_DPS310); + // scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::RAK12035, meshtastic_TelemetrySensorType_RAK12035); i2cScanner.reset(); #endif diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 8835c985d..6c9be53b4 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -41,6 +41,9 @@ #include "Sensor/SHTC3Sensor.h" #include "Sensor/TSL2591Sensor.h" #include "Sensor/VEML7700Sensor.h" +#ifdef RAK4630 +#include "Sensor/RAK12035Sensor.h" +#endif BMP085Sensor bmp085Sensor; BMP280Sensor bmp280Sensor; @@ -63,6 +66,9 @@ DFRobotGravitySensor dfRobotGravitySensor; NAU7802Sensor nau7802Sensor; BMP3XXSensor bmp3xxSensor; CGRadSensSensor cgRadSens; +#ifdef RAK4630 +RAK12035Sensor rak12035Sensor; +#endif #endif #ifdef T1000X_SENSOR_EN #include "Sensor/T1000xSensor.h" @@ -72,6 +78,7 @@ T1000xSensor t1000xSensor; #include "Sensor/IndicatorSensor.h" IndicatorSensor indicatorSensor; #endif + #define FAILED_STATE_SENSOR_READ_MULTIPLIER 10 #define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true @@ -171,6 +178,11 @@ int32_t EnvironmentTelemetryModule::runOnce() result = rak9154Sensor.runOnce(); #endif +#ifdef RAK4630 + if (rak12035Sensor.hasSensor()) { + result = rak12035Sensor.runOnce(); + } +#endif #endif } // it's possible to have this module enabled, only for displaying values on the screen. @@ -498,6 +510,12 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m valid = valid && rak9154Sensor.getMetrics(m); hasSensor = true; #endif +#ifdef RAK4630 + if (rak12035Sensor.hasSensor()) { + valid = valid && rak12035Sensor.getMetrics(m); + hasSensor = true; + } +#endif #endif return valid && hasSensor; } @@ -552,6 +570,9 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) LOG_INFO("Send: radiation=%fµR/h", m.variant.environment_metrics.radiation); + // LOG_INFO("Send: soil_temperature=%f, soil_moisture=%u", + // m.variant.environment_metrics.soil_temperature, m.variant.environment_metrics.soil_moisture); + sensor_read_error_count = 0; meshtastic_MeshPacket *p = allocDataProtobuf(m); @@ -710,6 +731,13 @@ AdminMessageHandleResult EnvironmentTelemetryModule::handleAdminMessageForModule if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } +#ifdef RAK4630 + if (rak12035Sensor.hasSensor()) { + result = rak12035Sensor.handleAdminMessage(mp, request, response); + if (result != AdminMessageHandleResult::NOT_HANDLED) + return result; + } +#endif #endif return result; } diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp new file mode 100644 index 000000000..b31e34ee5 --- /dev/null +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -0,0 +1,118 @@ +#include "configuration.h" +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && defined(RAK4630) + +#include "../mesh/generated/meshtastic/telemetry.pb.h" +#include "RAK12035Sensor.h" + +RAK12035Sensor::RAK12035Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_RAK12035, "RAK12035") {} + +int32_t RAK12035Sensor::runOnce() +{ + LOG_INFO("Init sensor: %s", sensorName); + if (!hasSensor()) { + return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; + } + + sensor.set_sensor_addr(RAK120351_ADDR); + + sensor.begin(nodeTelemetrySensorsMap[sensorType].first); + // Get sensor firmware version + uint8_t data = 0; + sensor.get_sensor_version(&data); + LOG_INFO("Sensor Firmware version: %i", data); + + if (data != 0) { + LOG_DEBUG("RAK12035Sensor Init Succeed"); + status = true; + } else { + LOG_ERROR("RAK12035Sensor Init Failed"); + status = false; + } + sensor.sensor_sleep(); + return initI2CSensor(); +} + +void RAK12035Sensor::setup() +{ + // Set the calibration values + // Reading the saved calibration values from the sensor. + uint16_t zero_val = 0; + 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(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); + LOG_ERROR("This does not make sense. Youc can recalibrate this sensor using the calibration sketch included here: " + "https://github.com/RAKWireless/RAK12035_SoilMoisture."); + LOG_ERROR("For now, setting default calibration value for Dry Calibration: %d", default_zero_val); + sensor.set_dry_cal(default_zero_val); + sensor.get_dry_cal(&zero_val); + LOG_ERROR("Dry calibration reset complete. New value is %d", zero_val); + } + if (hundred_val == 0 || hundred_val >= zero_val) { + LOG_ERROR("Dry calibration value is %d", zero_val); + LOG_ERROR("Wet calibration value is %d", hundred_val); + LOG_ERROR("This does not make sense. Youc can recalibrate this sensor using the calibration sketch included here: " + "https://github.com/RAKWireless/RAK12035_SoilMoisture."); + LOG_ERROR("For now, setting default calibration value for Wet Calibration: %d", default_hundred_val); + sensor.set_wet_cal(default_hundred_val); + sensor.get_wet_cal(&hundred_val); + LOG_ERROR("Wet calibration reset complete. New value is %d", hundred_val); + } + sensor.sensor_sleep(); + delay(200); + LOG_INFO("Dry calibration value is %d", zero_val); + LOG_INFO("Wet calibration value is %d", hundred_val); +} + +bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement) +{ + measurement->variant.environment_metrics.has_soil_temperature = true; + measurement->variant.environment_metrics.has_soil_moisture = true; + + uint8_t moisture = 0; + uint16_t temp = 0; + bool success = false; + + sensor.sensor_on(); + delay(200); + success = sensor.get_sensor_moisture(&moisture); + delay(200); + success = sensor.get_sensor_temperature(&temp); + delay(200); + sensor.sensor_sleep(); + + if (success == false) { + LOG_ERROR("Failed to read sensor data"); + return false; + } + LOG_INFO("Successful read from sensor Temperature: %.2f, Moisture: %ld%", (double)(temp / 10), moisture); + measurement->variant.environment_metrics.soil_temperature = (float)(temp / 10); + measurement->variant.environment_metrics.soil_moisture = moisture; + + LOG_INFO("Check if the original temperature and moisture (relative_humidity) are being used.. if not just use them for the " + "soil monitoring."); + + if (!measurement->variant.environment_metrics.has_temperature) { + LOG_INFO("Overwrite the temp metrics (not being set right now and this will allow the soil temp value to be used in the " + "client interface)."); + measurement->variant.environment_metrics.has_temperature = true; + measurement->variant.environment_metrics.temperature = (float)(temp / 10); + } + + if (!measurement->variant.environment_metrics.has_relative_humidity) { + LOG_INFO("Overwrite the moisture metrics (not being used for air humidity and this will allow the soil humidity to " + "appear in the client interfaces without adjustments)."); + measurement->variant.environment_metrics.has_relative_humidity = true; + measurement->variant.environment_metrics.relative_humidity = (float)moisture; + } + + return true; +} +#endif diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.h b/src/modules/Telemetry/Sensor/RAK12035Sensor.h new file mode 100644 index 000000000..77ffe24fa --- /dev/null +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.h @@ -0,0 +1,29 @@ +#pragma once + +#include "configuration.h" + +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && defined(RAK4630) +#ifndef _MT_RAK12035VBSENSOR_H +#define _MT_RAK12035VBSENSOR_H +#endif + +#include "../mesh/generated/meshtastic/telemetry.pb.h" +#include "RAK12035_SoilMoisture.h" +#include "TelemetrySensor.h" +#include + +class RAK12035Sensor : public TelemetrySensor +{ + private: + RAK12035 sensor; + + protected: + virtual void setup() override; + + public: + RAK12035Sensor(); + virtual int32_t runOnce() override; + virtual bool getMetrics(meshtastic_Telemetry *measurement) override; +}; + +#endif diff --git a/variants/rak4631/platformio.ini b/variants/rak4631/platformio.ini index ced93df66..4823ccdfa 100644 --- a/variants/rak4631/platformio.ini +++ b/variants/rak4631/platformio.ini @@ -20,6 +20,7 @@ lib_deps = https://github.com/RAKWireless/RAK13800-W5100S.git#1.0.2 rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 https://github.com/RAKWireless/RAK12034-BMX160.git#dcead07ffa267d3c906e9ca4a1330ab989e957e2 + beegee-tokyo/RAK12035_SoilMoisture@^1.0.3 ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ; Note: as of 6/2013 the serial/bootloader based programming takes approximately 30 seconds @@ -52,4 +53,4 @@ lib_deps = upload_protocol = stlink ; eventually use platformio/tool-pyocd@^2.3600.0 instad ;upload_protocol = custom -;upload_command = pyocd flash -t nrf52840 $UPLOADERFLAGS $SOURCE \ No newline at end of file +;upload_command = pyocd flash -t nrf52840 $UPLOADERFLAGS $SOURCE diff --git a/variants/rak4631/variant.h b/variants/rak4631/variant.h index bc5541336..c8a2f83ae 100644 --- a/variants/rak4631/variant.h +++ b/variants/rak4631/variant.h @@ -90,6 +90,8 @@ static const uint8_t A7 = PIN_A7; // Other pins #define PIN_AREF (2) #define PIN_NFC1 (9) +#define WB_IO5 PIN_NFC1 +#define WB_IO4 (4) #define PIN_NFC2 (10) static const uint8_t AREF = PIN_AREF; @@ -217,6 +219,7 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG // enables 3.3V periphery like GPS or IO Module // Do not toggle this for GPS power savings #define PIN_3V3_EN (34) +#define WB_IO2 PIN_3V3_EN // RAK1910 GPS module // If using the wisblock GPS module and pluged into Port A on WisBlock base @@ -270,4 +273,4 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif \ No newline at end of file +#endif diff --git a/variants/rak4631_epaper/platformio.ini b/variants/rak4631_epaper/platformio.ini index b851691ed..9fe7ac1c7 100644 --- a/variants/rak4631_epaper/platformio.ini +++ b/variants/rak4631_epaper/platformio.ini @@ -17,6 +17,7 @@ lib_deps = melopero/Melopero RV3028@^1.1.0 rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 beegee-tokyo/RAKwireless RAK12034@^1.0.0 + beegee-tokyo/RAK12035_SoilMoisture@^1.0.3 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink diff --git a/variants/rak4631_epaper/variant.h b/variants/rak4631_epaper/variant.h index 0bb97498c..c1e11bee5 100644 --- a/variants/rak4631_epaper/variant.h +++ b/variants/rak4631_epaper/variant.h @@ -90,6 +90,8 @@ static const uint8_t A7 = PIN_A7; // Other pins #define PIN_AREF (2) #define PIN_NFC1 (9) +#define WB_IO5 PIN_NFC1 +#define WB_IO4 (4) #define PIN_NFC2 (10) static const uint8_t AREF = PIN_AREF; @@ -188,6 +190,7 @@ static const uint8_t SCK = PIN_SPI_SCK; // enables 3.3V periphery like GPS or IO Module #define PIN_3V3_EN (34) +#define WB_IO2 PIN_3V3_EN // RAK1910 GPS module // If using the wisblock GPS module and pluged into Port A on WisBlock base @@ -231,4 +234,4 @@ static const uint8_t SCK = PIN_SPI_SCK; * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif \ No newline at end of file +#endif diff --git a/variants/rak4631_epaper_onrxtx/platformio.ini b/variants/rak4631_epaper_onrxtx/platformio.ini index 8612a3f3d..c5300243d 100644 --- a/variants/rak4631_epaper_onrxtx/platformio.ini +++ b/variants/rak4631_epaper_onrxtx/platformio.ini @@ -19,6 +19,7 @@ lib_deps = melopero/Melopero RV3028@^1.1.0 rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 beegee-tokyo/RAKwireless RAK12034@^1.0.0 + beegee-tokyo/RAK12035_SoilMoisture@^1.0.3 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink diff --git a/variants/rak4631_epaper_onrxtx/variant.h b/variants/rak4631_epaper_onrxtx/variant.h index 5888cff33..1f8257e8e 100644 --- a/variants/rak4631_epaper_onrxtx/variant.h +++ b/variants/rak4631_epaper_onrxtx/variant.h @@ -69,7 +69,9 @@ static const uint8_t A7 = PIN_A7; // Other pins #define PIN_AREF (2) -// #define PIN_NFC1 (9) +#define PIN_NFC1 (9) +#define WB_IO5 PIN_NFC1 +#define WB_IO4 (4) // #define PIN_NFC2 (10) static const uint8_t AREF = PIN_AREF; @@ -160,6 +162,7 @@ static const uint8_t SCK = PIN_SPI_SCK; // enables 3.3V periphery like GPS or IO Module #define PIN_3V3_EN (34) +#define WB_IO2 PIN_3V3_EN // NO GPS #undef GPS_RX_PIN @@ -202,4 +205,4 @@ static const uint8_t SCK = PIN_SPI_SCK; * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif \ No newline at end of file +#endif diff --git a/variants/rak4631_eth_gw/variant.h b/variants/rak4631_eth_gw/variant.h index bc5541336..c8a2f83ae 100644 --- a/variants/rak4631_eth_gw/variant.h +++ b/variants/rak4631_eth_gw/variant.h @@ -90,6 +90,8 @@ static const uint8_t A7 = PIN_A7; // Other pins #define PIN_AREF (2) #define PIN_NFC1 (9) +#define WB_IO5 PIN_NFC1 +#define WB_IO4 (4) #define PIN_NFC2 (10) static const uint8_t AREF = PIN_AREF; @@ -217,6 +219,7 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG // enables 3.3V periphery like GPS or IO Module // Do not toggle this for GPS power savings #define PIN_3V3_EN (34) +#define WB_IO2 PIN_3V3_EN // RAK1910 GPS module // If using the wisblock GPS module and pluged into Port A on WisBlock base @@ -270,4 +273,4 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif \ No newline at end of file +#endif diff --git a/variants/rak_wismeshtap/platformio.ini b/variants/rak_wismeshtap/platformio.ini index bcf46b90d..a40a27ae4 100644 --- a/variants/rak_wismeshtap/platformio.ini +++ b/variants/rak_wismeshtap/platformio.ini @@ -23,6 +23,7 @@ lib_deps = bodmer/TFT_eSPI beegee-tokyo/RAKwireless RAK12034@^1.0.0 beegee-tokyo/RAK14014-FT6336U @ 1.0.1 + beegee-tokyo/RAK12035_SoilMoisture@^1.0.3 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink diff --git a/variants/rak_wismeshtap/variant.h b/variants/rak_wismeshtap/variant.h index c21a11ac1..3006189cf 100644 --- a/variants/rak_wismeshtap/variant.h +++ b/variants/rak_wismeshtap/variant.h @@ -90,6 +90,8 @@ static const uint8_t A7 = PIN_A7; // Other pins #define PIN_AREF (2) #define PIN_NFC1 (9) +#define WB_IO5 PIN_NFC1 +#define WB_IO4 (4) #define PIN_NFC2 (10) static const uint8_t AREF = PIN_AREF; @@ -311,4 +313,4 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif \ No newline at end of file +#endif From 37e6769b12c46acf317eb36fb79e987d3c3a19f1 Mon Sep 17 00:00:00 2001 From: Tom Fifield Date: Fri, 7 Mar 2025 20:22:52 +0800 Subject: [PATCH 02/38] [WIP] Add RAK12035VB Soil Moisture Sensor support Introduce the RAK12035 sensor as an environmental telemetry sensor, including necessary calibration checks and default values. Update relevant files to integrate the sensor into the existing telemetry system. This hardware is not just one module, but a couple.. RAK12023 and RAK12035 is the component stack, the RAK12023 does not seem to matter much and allows for multiple RAK12035 devices to be used. Co-Authored-By: @Justin-Mann --- src/configuration.h | 9 ++ src/detect/ScanI2C.h | 1 + src/detect/ScanI2CTwoWire.cpp | 14 ++- src/main.cpp | 1 + .../Telemetry/EnvironmentTelemetry.cpp | 30 ++++- .../Telemetry/Sensor/RAK12035Sensor.cpp | 118 ++++++++++++++++++ src/modules/Telemetry/Sensor/RAK12035Sensor.h | 29 +++++ variants/rak4631/platformio.ini | 3 +- variants/rak4631/variant.h | 5 +- variants/rak4631_epaper/platformio.ini | 1 + variants/rak4631_epaper/variant.h | 5 +- variants/rak4631_epaper_onrxtx/platformio.ini | 1 + variants/rak4631_epaper_onrxtx/variant.h | 7 +- variants/rak4631_eth_gw/variant.h | 5 +- variants/rak_wismeshtap/platformio.ini | 1 + variants/rak_wismeshtap/variant.h | 4 +- 16 files changed, 225 insertions(+), 9 deletions(-) create mode 100644 src/modules/Telemetry/Sensor/RAK12035Sensor.cpp create mode 100644 src/modules/Telemetry/Sensor/RAK12035Sensor.h diff --git a/src/configuration.h b/src/configuration.h index fd4a5b196..3a0a2ac6e 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -186,6 +186,15 @@ along with this program. If not, see . // ----------------------------------------------------------------------------- #define FT6336U_ADDR 0x48 +// ----------------------------------------------------------------------------- +// RAK12035VB Soil Monitor (using RAK12023 up to 3 RAK12035 monitors can be connected) +// - the default i2c address for this sensor is 0x20, and users are instructed to +// set 0x21 and 0x22 for the second and third sensor if present. +// ----------------------------------------------------------------------------- +#define RAK120351_ADDR 0x20 +#define RAK120352_ADDR 0x21 +#define RAK120353_ADDR 0x22 + // ----------------------------------------------------------------------------- // BIAS-T Generator // ----------------------------------------------------------------------------- diff --git a/src/detect/ScanI2C.h b/src/detect/ScanI2C.h index 5b6bbe629..8f6f5e7c2 100644 --- a/src/detect/ScanI2C.h +++ b/src/detect/ScanI2C.h @@ -69,6 +69,7 @@ class ScanI2C DFROBOT_RAIN, DPS310, LTR390UV, + RAK12035, } DeviceType; // typedef uint8_t DeviceAddress; diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 8b779277d..d28d0f687 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -417,9 +417,21 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) logFoundDevice("BMA423", (uint8_t)addr.address); } break; + case TCA9535_ADDR: + case RAK120352_ADDR: + case RAK120353_ADDR: + registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x02), 1); + if (registerValue == addr.address) { // RAK12035 returns its I2C address at 0x02 (eg 0x20) + type = RAK12035; + logFoundDevice("RAK12035", (uint8_t)addr.address); + } else { + type = TCA9535; + logFoundDevice("TCA9535", (uint8_t)addr.address); + } + + break; SCAN_SIMPLE_CASE(LSM6DS3_ADDR, LSM6DS3, "LSM6DS3", (uint8_t)addr.address); - SCAN_SIMPLE_CASE(TCA9535_ADDR, TCA9535, "TCA9535", (uint8_t)addr.address); SCAN_SIMPLE_CASE(TCA9555_ADDR, TCA9555, "TCA9555", (uint8_t)addr.address); SCAN_SIMPLE_CASE(VEML7700_ADDR, VEML7700, "VEML7700", (uint8_t)addr.address); SCAN_SIMPLE_CASE(TSL25911_ADDR, TSL2591, "TSL2591", (uint8_t)addr.address); diff --git a/src/main.cpp b/src/main.cpp index 6b8089eaa..2e275964b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -643,6 +643,7 @@ void setup() scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::DFROBOT_RAIN, meshtastic_TelemetrySensorType_DFROBOT_RAIN); scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::LTR390UV, meshtastic_TelemetrySensorType_LTR390UV); scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::DPS310, meshtastic_TelemetrySensorType_DPS310); + scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::RAK12035, meshtastic_TelemetrySensorType_RAK12035); i2cScanner.reset(); #endif diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 8835c985d..adbe65c67 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -41,6 +41,9 @@ #include "Sensor/SHTC3Sensor.h" #include "Sensor/TSL2591Sensor.h" #include "Sensor/VEML7700Sensor.h" +#ifdef RAK4630 +#include "Sensor/RAK12035Sensor.h" +#endif BMP085Sensor bmp085Sensor; BMP280Sensor bmp280Sensor; @@ -63,6 +66,9 @@ DFRobotGravitySensor dfRobotGravitySensor; NAU7802Sensor nau7802Sensor; BMP3XXSensor bmp3xxSensor; CGRadSensSensor cgRadSens; +#ifdef RAK4630 +RAK12035Sensor rak12035Sensor; +#endif #endif #ifdef T1000X_SENSOR_EN #include "Sensor/T1000xSensor.h" @@ -72,6 +78,7 @@ T1000xSensor t1000xSensor; #include "Sensor/IndicatorSensor.h" IndicatorSensor indicatorSensor; #endif + #define FAILED_STATE_SENSOR_READ_MULTIPLIER 10 #define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true @@ -171,6 +178,11 @@ int32_t EnvironmentTelemetryModule::runOnce() result = rak9154Sensor.runOnce(); #endif +#ifdef RAK4630 + if (rak12035Sensor.hasSensor()) { + result = rak12035Sensor.runOnce(); + } +#endif #endif } // it's possible to have this module enabled, only for displaying values on the screen. @@ -498,6 +510,12 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m valid = valid && rak9154Sensor.getMetrics(m); hasSensor = true; #endif +#ifdef RAK4630 + if (rak12035Sensor.hasSensor()) { + valid = valid && rak12035Sensor.getMetrics(m); + hasSensor = true; + } +#endif #endif return valid && hasSensor; } @@ -552,6 +570,9 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) LOG_INFO("Send: radiation=%fµR/h", m.variant.environment_metrics.radiation); + LOG_INFO("Send: soil_temperature=%f, soil_moisture=%u", m.variant.environment_metrics.soil_temperature, + m.variant.environment_metrics.soil_moisture); + sensor_read_error_count = 0; meshtastic_MeshPacket *p = allocDataProtobuf(m); @@ -710,8 +731,15 @@ AdminMessageHandleResult EnvironmentTelemetryModule::handleAdminMessageForModule if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } +#ifdef RAK4630 + if (rak12035Sensor.hasSensor()) { + result = rak12035Sensor.handleAdminMessage(mp, request, response); + if (result != AdminMessageHandleResult::NOT_HANDLED) + return result; + } +#endif #endif return result; } -#endif \ No newline at end of file +#endif diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp new file mode 100644 index 000000000..b31e34ee5 --- /dev/null +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -0,0 +1,118 @@ +#include "configuration.h" +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && defined(RAK4630) + +#include "../mesh/generated/meshtastic/telemetry.pb.h" +#include "RAK12035Sensor.h" + +RAK12035Sensor::RAK12035Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_RAK12035, "RAK12035") {} + +int32_t RAK12035Sensor::runOnce() +{ + LOG_INFO("Init sensor: %s", sensorName); + if (!hasSensor()) { + return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; + } + + sensor.set_sensor_addr(RAK120351_ADDR); + + sensor.begin(nodeTelemetrySensorsMap[sensorType].first); + // Get sensor firmware version + uint8_t data = 0; + sensor.get_sensor_version(&data); + LOG_INFO("Sensor Firmware version: %i", data); + + if (data != 0) { + LOG_DEBUG("RAK12035Sensor Init Succeed"); + status = true; + } else { + LOG_ERROR("RAK12035Sensor Init Failed"); + status = false; + } + sensor.sensor_sleep(); + return initI2CSensor(); +} + +void RAK12035Sensor::setup() +{ + // Set the calibration values + // Reading the saved calibration values from the sensor. + uint16_t zero_val = 0; + 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(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); + LOG_ERROR("This does not make sense. Youc can recalibrate this sensor using the calibration sketch included here: " + "https://github.com/RAKWireless/RAK12035_SoilMoisture."); + LOG_ERROR("For now, setting default calibration value for Dry Calibration: %d", default_zero_val); + sensor.set_dry_cal(default_zero_val); + sensor.get_dry_cal(&zero_val); + LOG_ERROR("Dry calibration reset complete. New value is %d", zero_val); + } + if (hundred_val == 0 || hundred_val >= zero_val) { + LOG_ERROR("Dry calibration value is %d", zero_val); + LOG_ERROR("Wet calibration value is %d", hundred_val); + LOG_ERROR("This does not make sense. Youc can recalibrate this sensor using the calibration sketch included here: " + "https://github.com/RAKWireless/RAK12035_SoilMoisture."); + LOG_ERROR("For now, setting default calibration value for Wet Calibration: %d", default_hundred_val); + sensor.set_wet_cal(default_hundred_val); + sensor.get_wet_cal(&hundred_val); + LOG_ERROR("Wet calibration reset complete. New value is %d", hundred_val); + } + sensor.sensor_sleep(); + delay(200); + LOG_INFO("Dry calibration value is %d", zero_val); + LOG_INFO("Wet calibration value is %d", hundred_val); +} + +bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement) +{ + measurement->variant.environment_metrics.has_soil_temperature = true; + measurement->variant.environment_metrics.has_soil_moisture = true; + + uint8_t moisture = 0; + uint16_t temp = 0; + bool success = false; + + sensor.sensor_on(); + delay(200); + success = sensor.get_sensor_moisture(&moisture); + delay(200); + success = sensor.get_sensor_temperature(&temp); + delay(200); + sensor.sensor_sleep(); + + if (success == false) { + LOG_ERROR("Failed to read sensor data"); + return false; + } + LOG_INFO("Successful read from sensor Temperature: %.2f, Moisture: %ld%", (double)(temp / 10), moisture); + measurement->variant.environment_metrics.soil_temperature = (float)(temp / 10); + measurement->variant.environment_metrics.soil_moisture = moisture; + + LOG_INFO("Check if the original temperature and moisture (relative_humidity) are being used.. if not just use them for the " + "soil monitoring."); + + if (!measurement->variant.environment_metrics.has_temperature) { + LOG_INFO("Overwrite the temp metrics (not being set right now and this will allow the soil temp value to be used in the " + "client interface)."); + measurement->variant.environment_metrics.has_temperature = true; + measurement->variant.environment_metrics.temperature = (float)(temp / 10); + } + + if (!measurement->variant.environment_metrics.has_relative_humidity) { + LOG_INFO("Overwrite the moisture metrics (not being used for air humidity and this will allow the soil humidity to " + "appear in the client interfaces without adjustments)."); + measurement->variant.environment_metrics.has_relative_humidity = true; + measurement->variant.environment_metrics.relative_humidity = (float)moisture; + } + + return true; +} +#endif diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.h b/src/modules/Telemetry/Sensor/RAK12035Sensor.h new file mode 100644 index 000000000..77ffe24fa --- /dev/null +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.h @@ -0,0 +1,29 @@ +#pragma once + +#include "configuration.h" + +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && defined(RAK4630) +#ifndef _MT_RAK12035VBSENSOR_H +#define _MT_RAK12035VBSENSOR_H +#endif + +#include "../mesh/generated/meshtastic/telemetry.pb.h" +#include "RAK12035_SoilMoisture.h" +#include "TelemetrySensor.h" +#include + +class RAK12035Sensor : public TelemetrySensor +{ + private: + RAK12035 sensor; + + protected: + virtual void setup() override; + + public: + RAK12035Sensor(); + virtual int32_t runOnce() override; + virtual bool getMetrics(meshtastic_Telemetry *measurement) override; +}; + +#endif diff --git a/variants/rak4631/platformio.ini b/variants/rak4631/platformio.ini index ced93df66..4823ccdfa 100644 --- a/variants/rak4631/platformio.ini +++ b/variants/rak4631/platformio.ini @@ -20,6 +20,7 @@ lib_deps = https://github.com/RAKWireless/RAK13800-W5100S.git#1.0.2 rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 https://github.com/RAKWireless/RAK12034-BMX160.git#dcead07ffa267d3c906e9ca4a1330ab989e957e2 + beegee-tokyo/RAK12035_SoilMoisture@^1.0.3 ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ; Note: as of 6/2013 the serial/bootloader based programming takes approximately 30 seconds @@ -52,4 +53,4 @@ lib_deps = upload_protocol = stlink ; eventually use platformio/tool-pyocd@^2.3600.0 instad ;upload_protocol = custom -;upload_command = pyocd flash -t nrf52840 $UPLOADERFLAGS $SOURCE \ No newline at end of file +;upload_command = pyocd flash -t nrf52840 $UPLOADERFLAGS $SOURCE diff --git a/variants/rak4631/variant.h b/variants/rak4631/variant.h index bc5541336..c8a2f83ae 100644 --- a/variants/rak4631/variant.h +++ b/variants/rak4631/variant.h @@ -90,6 +90,8 @@ static const uint8_t A7 = PIN_A7; // Other pins #define PIN_AREF (2) #define PIN_NFC1 (9) +#define WB_IO5 PIN_NFC1 +#define WB_IO4 (4) #define PIN_NFC2 (10) static const uint8_t AREF = PIN_AREF; @@ -217,6 +219,7 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG // enables 3.3V periphery like GPS or IO Module // Do not toggle this for GPS power savings #define PIN_3V3_EN (34) +#define WB_IO2 PIN_3V3_EN // RAK1910 GPS module // If using the wisblock GPS module and pluged into Port A on WisBlock base @@ -270,4 +273,4 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif \ No newline at end of file +#endif diff --git a/variants/rak4631_epaper/platformio.ini b/variants/rak4631_epaper/platformio.ini index b851691ed..9fe7ac1c7 100644 --- a/variants/rak4631_epaper/platformio.ini +++ b/variants/rak4631_epaper/platformio.ini @@ -17,6 +17,7 @@ lib_deps = melopero/Melopero RV3028@^1.1.0 rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 beegee-tokyo/RAKwireless RAK12034@^1.0.0 + beegee-tokyo/RAK12035_SoilMoisture@^1.0.3 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink diff --git a/variants/rak4631_epaper/variant.h b/variants/rak4631_epaper/variant.h index 0bb97498c..c1e11bee5 100644 --- a/variants/rak4631_epaper/variant.h +++ b/variants/rak4631_epaper/variant.h @@ -90,6 +90,8 @@ static const uint8_t A7 = PIN_A7; // Other pins #define PIN_AREF (2) #define PIN_NFC1 (9) +#define WB_IO5 PIN_NFC1 +#define WB_IO4 (4) #define PIN_NFC2 (10) static const uint8_t AREF = PIN_AREF; @@ -188,6 +190,7 @@ static const uint8_t SCK = PIN_SPI_SCK; // enables 3.3V periphery like GPS or IO Module #define PIN_3V3_EN (34) +#define WB_IO2 PIN_3V3_EN // RAK1910 GPS module // If using the wisblock GPS module and pluged into Port A on WisBlock base @@ -231,4 +234,4 @@ static const uint8_t SCK = PIN_SPI_SCK; * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif \ No newline at end of file +#endif diff --git a/variants/rak4631_epaper_onrxtx/platformio.ini b/variants/rak4631_epaper_onrxtx/platformio.ini index 8612a3f3d..c5300243d 100644 --- a/variants/rak4631_epaper_onrxtx/platformio.ini +++ b/variants/rak4631_epaper_onrxtx/platformio.ini @@ -19,6 +19,7 @@ lib_deps = melopero/Melopero RV3028@^1.1.0 rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 beegee-tokyo/RAKwireless RAK12034@^1.0.0 + beegee-tokyo/RAK12035_SoilMoisture@^1.0.3 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink diff --git a/variants/rak4631_epaper_onrxtx/variant.h b/variants/rak4631_epaper_onrxtx/variant.h index 5888cff33..1f8257e8e 100644 --- a/variants/rak4631_epaper_onrxtx/variant.h +++ b/variants/rak4631_epaper_onrxtx/variant.h @@ -69,7 +69,9 @@ static const uint8_t A7 = PIN_A7; // Other pins #define PIN_AREF (2) -// #define PIN_NFC1 (9) +#define PIN_NFC1 (9) +#define WB_IO5 PIN_NFC1 +#define WB_IO4 (4) // #define PIN_NFC2 (10) static const uint8_t AREF = PIN_AREF; @@ -160,6 +162,7 @@ static const uint8_t SCK = PIN_SPI_SCK; // enables 3.3V periphery like GPS or IO Module #define PIN_3V3_EN (34) +#define WB_IO2 PIN_3V3_EN // NO GPS #undef GPS_RX_PIN @@ -202,4 +205,4 @@ static const uint8_t SCK = PIN_SPI_SCK; * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif \ No newline at end of file +#endif diff --git a/variants/rak4631_eth_gw/variant.h b/variants/rak4631_eth_gw/variant.h index bc5541336..c8a2f83ae 100644 --- a/variants/rak4631_eth_gw/variant.h +++ b/variants/rak4631_eth_gw/variant.h @@ -90,6 +90,8 @@ static const uint8_t A7 = PIN_A7; // Other pins #define PIN_AREF (2) #define PIN_NFC1 (9) +#define WB_IO5 PIN_NFC1 +#define WB_IO4 (4) #define PIN_NFC2 (10) static const uint8_t AREF = PIN_AREF; @@ -217,6 +219,7 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG // enables 3.3V periphery like GPS or IO Module // Do not toggle this for GPS power savings #define PIN_3V3_EN (34) +#define WB_IO2 PIN_3V3_EN // RAK1910 GPS module // If using the wisblock GPS module and pluged into Port A on WisBlock base @@ -270,4 +273,4 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif \ No newline at end of file +#endif diff --git a/variants/rak_wismeshtap/platformio.ini b/variants/rak_wismeshtap/platformio.ini index bcf46b90d..a40a27ae4 100644 --- a/variants/rak_wismeshtap/platformio.ini +++ b/variants/rak_wismeshtap/platformio.ini @@ -23,6 +23,7 @@ lib_deps = bodmer/TFT_eSPI beegee-tokyo/RAKwireless RAK12034@^1.0.0 beegee-tokyo/RAK14014-FT6336U @ 1.0.1 + beegee-tokyo/RAK12035_SoilMoisture@^1.0.3 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink diff --git a/variants/rak_wismeshtap/variant.h b/variants/rak_wismeshtap/variant.h index c21a11ac1..3006189cf 100644 --- a/variants/rak_wismeshtap/variant.h +++ b/variants/rak_wismeshtap/variant.h @@ -90,6 +90,8 @@ static const uint8_t A7 = PIN_A7; // Other pins #define PIN_AREF (2) #define PIN_NFC1 (9) +#define WB_IO5 PIN_NFC1 +#define WB_IO4 (4) #define PIN_NFC2 (10) static const uint8_t AREF = PIN_AREF; @@ -311,4 +313,4 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif \ No newline at end of file +#endif From 0c41f90ef5ed3485f5155781e9876d0e9e63f2ca Mon Sep 17 00:00:00 2001 From: Tom Fifield Date: Fri, 7 Mar 2025 20:22:52 +0800 Subject: [PATCH 03/38] [WIP] Add RAK12035VB Soil Moisture Sensor support Introduce the RAK12035 sensor as an environmental telemetry sensor, including necessary calibration checks and default values. Update relevant files to integrate the sensor into the existing telemetry system. This hardware is not just one module, but a couple.. RAK12023 and RAK12035 is the component stack, the RAK12023 does not seem to matter much and allows for multiple RAK12035 devices to be used. Co-Authored-By: @Justin-Mann --- src/configuration.h | 9 ++ src/detect/ScanI2C.h | 1 + src/detect/ScanI2CTwoWire.cpp | 14 ++- src/main.cpp | 1 + .../Telemetry/EnvironmentTelemetry.cpp | 30 ++++- .../Telemetry/Sensor/RAK12035Sensor.cpp | 118 ++++++++++++++++++ src/modules/Telemetry/Sensor/RAK12035Sensor.h | 29 +++++ variants/rak4631/platformio.ini | 3 +- variants/rak4631/variant.h | 5 +- variants/rak4631_epaper/platformio.ini | 1 + variants/rak4631_epaper/variant.h | 5 +- variants/rak4631_epaper_onrxtx/platformio.ini | 1 + variants/rak4631_epaper_onrxtx/variant.h | 7 +- variants/rak4631_eth_gw/variant.h | 5 +- variants/rak_wismeshtap/platformio.ini | 1 + variants/rak_wismeshtap/variant.h | 4 +- 16 files changed, 225 insertions(+), 9 deletions(-) create mode 100644 src/modules/Telemetry/Sensor/RAK12035Sensor.cpp create mode 100644 src/modules/Telemetry/Sensor/RAK12035Sensor.h diff --git a/src/configuration.h b/src/configuration.h index fd4a5b196..3a0a2ac6e 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -186,6 +186,15 @@ along with this program. If not, see . // ----------------------------------------------------------------------------- #define FT6336U_ADDR 0x48 +// ----------------------------------------------------------------------------- +// RAK12035VB Soil Monitor (using RAK12023 up to 3 RAK12035 monitors can be connected) +// - the default i2c address for this sensor is 0x20, and users are instructed to +// set 0x21 and 0x22 for the second and third sensor if present. +// ----------------------------------------------------------------------------- +#define RAK120351_ADDR 0x20 +#define RAK120352_ADDR 0x21 +#define RAK120353_ADDR 0x22 + // ----------------------------------------------------------------------------- // BIAS-T Generator // ----------------------------------------------------------------------------- diff --git a/src/detect/ScanI2C.h b/src/detect/ScanI2C.h index 5b6bbe629..8f6f5e7c2 100644 --- a/src/detect/ScanI2C.h +++ b/src/detect/ScanI2C.h @@ -69,6 +69,7 @@ class ScanI2C DFROBOT_RAIN, DPS310, LTR390UV, + RAK12035, } DeviceType; // typedef uint8_t DeviceAddress; diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 8b779277d..d28d0f687 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -417,9 +417,21 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) logFoundDevice("BMA423", (uint8_t)addr.address); } break; + case TCA9535_ADDR: + case RAK120352_ADDR: + case RAK120353_ADDR: + registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x02), 1); + if (registerValue == addr.address) { // RAK12035 returns its I2C address at 0x02 (eg 0x20) + type = RAK12035; + logFoundDevice("RAK12035", (uint8_t)addr.address); + } else { + type = TCA9535; + logFoundDevice("TCA9535", (uint8_t)addr.address); + } + + break; SCAN_SIMPLE_CASE(LSM6DS3_ADDR, LSM6DS3, "LSM6DS3", (uint8_t)addr.address); - SCAN_SIMPLE_CASE(TCA9535_ADDR, TCA9535, "TCA9535", (uint8_t)addr.address); SCAN_SIMPLE_CASE(TCA9555_ADDR, TCA9555, "TCA9555", (uint8_t)addr.address); SCAN_SIMPLE_CASE(VEML7700_ADDR, VEML7700, "VEML7700", (uint8_t)addr.address); SCAN_SIMPLE_CASE(TSL25911_ADDR, TSL2591, "TSL2591", (uint8_t)addr.address); diff --git a/src/main.cpp b/src/main.cpp index 4634c7c14..59d76c4c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -643,6 +643,7 @@ void setup() scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::DFROBOT_RAIN, meshtastic_TelemetrySensorType_DFROBOT_RAIN); scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::LTR390UV, meshtastic_TelemetrySensorType_LTR390UV); scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::DPS310, meshtastic_TelemetrySensorType_DPS310); + scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::RAK12035, meshtastic_TelemetrySensorType_RAK12035); i2cScanner.reset(); #endif diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 8835c985d..adbe65c67 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -41,6 +41,9 @@ #include "Sensor/SHTC3Sensor.h" #include "Sensor/TSL2591Sensor.h" #include "Sensor/VEML7700Sensor.h" +#ifdef RAK4630 +#include "Sensor/RAK12035Sensor.h" +#endif BMP085Sensor bmp085Sensor; BMP280Sensor bmp280Sensor; @@ -63,6 +66,9 @@ DFRobotGravitySensor dfRobotGravitySensor; NAU7802Sensor nau7802Sensor; BMP3XXSensor bmp3xxSensor; CGRadSensSensor cgRadSens; +#ifdef RAK4630 +RAK12035Sensor rak12035Sensor; +#endif #endif #ifdef T1000X_SENSOR_EN #include "Sensor/T1000xSensor.h" @@ -72,6 +78,7 @@ T1000xSensor t1000xSensor; #include "Sensor/IndicatorSensor.h" IndicatorSensor indicatorSensor; #endif + #define FAILED_STATE_SENSOR_READ_MULTIPLIER 10 #define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true @@ -171,6 +178,11 @@ int32_t EnvironmentTelemetryModule::runOnce() result = rak9154Sensor.runOnce(); #endif +#ifdef RAK4630 + if (rak12035Sensor.hasSensor()) { + result = rak12035Sensor.runOnce(); + } +#endif #endif } // it's possible to have this module enabled, only for displaying values on the screen. @@ -498,6 +510,12 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m valid = valid && rak9154Sensor.getMetrics(m); hasSensor = true; #endif +#ifdef RAK4630 + if (rak12035Sensor.hasSensor()) { + valid = valid && rak12035Sensor.getMetrics(m); + hasSensor = true; + } +#endif #endif return valid && hasSensor; } @@ -552,6 +570,9 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) LOG_INFO("Send: radiation=%fµR/h", m.variant.environment_metrics.radiation); + LOG_INFO("Send: soil_temperature=%f, soil_moisture=%u", m.variant.environment_metrics.soil_temperature, + m.variant.environment_metrics.soil_moisture); + sensor_read_error_count = 0; meshtastic_MeshPacket *p = allocDataProtobuf(m); @@ -710,8 +731,15 @@ AdminMessageHandleResult EnvironmentTelemetryModule::handleAdminMessageForModule if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } +#ifdef RAK4630 + if (rak12035Sensor.hasSensor()) { + result = rak12035Sensor.handleAdminMessage(mp, request, response); + if (result != AdminMessageHandleResult::NOT_HANDLED) + return result; + } +#endif #endif return result; } -#endif \ No newline at end of file +#endif diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp new file mode 100644 index 000000000..b31e34ee5 --- /dev/null +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -0,0 +1,118 @@ +#include "configuration.h" +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && defined(RAK4630) + +#include "../mesh/generated/meshtastic/telemetry.pb.h" +#include "RAK12035Sensor.h" + +RAK12035Sensor::RAK12035Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_RAK12035, "RAK12035") {} + +int32_t RAK12035Sensor::runOnce() +{ + LOG_INFO("Init sensor: %s", sensorName); + if (!hasSensor()) { + return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; + } + + sensor.set_sensor_addr(RAK120351_ADDR); + + sensor.begin(nodeTelemetrySensorsMap[sensorType].first); + // Get sensor firmware version + uint8_t data = 0; + sensor.get_sensor_version(&data); + LOG_INFO("Sensor Firmware version: %i", data); + + if (data != 0) { + LOG_DEBUG("RAK12035Sensor Init Succeed"); + status = true; + } else { + LOG_ERROR("RAK12035Sensor Init Failed"); + status = false; + } + sensor.sensor_sleep(); + return initI2CSensor(); +} + +void RAK12035Sensor::setup() +{ + // Set the calibration values + // Reading the saved calibration values from the sensor. + uint16_t zero_val = 0; + 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(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); + LOG_ERROR("This does not make sense. Youc can recalibrate this sensor using the calibration sketch included here: " + "https://github.com/RAKWireless/RAK12035_SoilMoisture."); + LOG_ERROR("For now, setting default calibration value for Dry Calibration: %d", default_zero_val); + sensor.set_dry_cal(default_zero_val); + sensor.get_dry_cal(&zero_val); + LOG_ERROR("Dry calibration reset complete. New value is %d", zero_val); + } + if (hundred_val == 0 || hundred_val >= zero_val) { + LOG_ERROR("Dry calibration value is %d", zero_val); + LOG_ERROR("Wet calibration value is %d", hundred_val); + LOG_ERROR("This does not make sense. Youc can recalibrate this sensor using the calibration sketch included here: " + "https://github.com/RAKWireless/RAK12035_SoilMoisture."); + LOG_ERROR("For now, setting default calibration value for Wet Calibration: %d", default_hundred_val); + sensor.set_wet_cal(default_hundred_val); + sensor.get_wet_cal(&hundred_val); + LOG_ERROR("Wet calibration reset complete. New value is %d", hundred_val); + } + sensor.sensor_sleep(); + delay(200); + LOG_INFO("Dry calibration value is %d", zero_val); + LOG_INFO("Wet calibration value is %d", hundred_val); +} + +bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement) +{ + measurement->variant.environment_metrics.has_soil_temperature = true; + measurement->variant.environment_metrics.has_soil_moisture = true; + + uint8_t moisture = 0; + uint16_t temp = 0; + bool success = false; + + sensor.sensor_on(); + delay(200); + success = sensor.get_sensor_moisture(&moisture); + delay(200); + success = sensor.get_sensor_temperature(&temp); + delay(200); + sensor.sensor_sleep(); + + if (success == false) { + LOG_ERROR("Failed to read sensor data"); + return false; + } + LOG_INFO("Successful read from sensor Temperature: %.2f, Moisture: %ld%", (double)(temp / 10), moisture); + measurement->variant.environment_metrics.soil_temperature = (float)(temp / 10); + measurement->variant.environment_metrics.soil_moisture = moisture; + + LOG_INFO("Check if the original temperature and moisture (relative_humidity) are being used.. if not just use them for the " + "soil monitoring."); + + if (!measurement->variant.environment_metrics.has_temperature) { + LOG_INFO("Overwrite the temp metrics (not being set right now and this will allow the soil temp value to be used in the " + "client interface)."); + measurement->variant.environment_metrics.has_temperature = true; + measurement->variant.environment_metrics.temperature = (float)(temp / 10); + } + + if (!measurement->variant.environment_metrics.has_relative_humidity) { + LOG_INFO("Overwrite the moisture metrics (not being used for air humidity and this will allow the soil humidity to " + "appear in the client interfaces without adjustments)."); + measurement->variant.environment_metrics.has_relative_humidity = true; + measurement->variant.environment_metrics.relative_humidity = (float)moisture; + } + + return true; +} +#endif diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.h b/src/modules/Telemetry/Sensor/RAK12035Sensor.h new file mode 100644 index 000000000..77ffe24fa --- /dev/null +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.h @@ -0,0 +1,29 @@ +#pragma once + +#include "configuration.h" + +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && defined(RAK4630) +#ifndef _MT_RAK12035VBSENSOR_H +#define _MT_RAK12035VBSENSOR_H +#endif + +#include "../mesh/generated/meshtastic/telemetry.pb.h" +#include "RAK12035_SoilMoisture.h" +#include "TelemetrySensor.h" +#include + +class RAK12035Sensor : public TelemetrySensor +{ + private: + RAK12035 sensor; + + protected: + virtual void setup() override; + + public: + RAK12035Sensor(); + virtual int32_t runOnce() override; + virtual bool getMetrics(meshtastic_Telemetry *measurement) override; +}; + +#endif diff --git a/variants/rak4631/platformio.ini b/variants/rak4631/platformio.ini index ced93df66..4823ccdfa 100644 --- a/variants/rak4631/platformio.ini +++ b/variants/rak4631/platformio.ini @@ -20,6 +20,7 @@ lib_deps = https://github.com/RAKWireless/RAK13800-W5100S.git#1.0.2 rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 https://github.com/RAKWireless/RAK12034-BMX160.git#dcead07ffa267d3c906e9ca4a1330ab989e957e2 + beegee-tokyo/RAK12035_SoilMoisture@^1.0.3 ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ; Note: as of 6/2013 the serial/bootloader based programming takes approximately 30 seconds @@ -52,4 +53,4 @@ lib_deps = upload_protocol = stlink ; eventually use platformio/tool-pyocd@^2.3600.0 instad ;upload_protocol = custom -;upload_command = pyocd flash -t nrf52840 $UPLOADERFLAGS $SOURCE \ No newline at end of file +;upload_command = pyocd flash -t nrf52840 $UPLOADERFLAGS $SOURCE diff --git a/variants/rak4631/variant.h b/variants/rak4631/variant.h index bc5541336..c8a2f83ae 100644 --- a/variants/rak4631/variant.h +++ b/variants/rak4631/variant.h @@ -90,6 +90,8 @@ static const uint8_t A7 = PIN_A7; // Other pins #define PIN_AREF (2) #define PIN_NFC1 (9) +#define WB_IO5 PIN_NFC1 +#define WB_IO4 (4) #define PIN_NFC2 (10) static const uint8_t AREF = PIN_AREF; @@ -217,6 +219,7 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG // enables 3.3V periphery like GPS or IO Module // Do not toggle this for GPS power savings #define PIN_3V3_EN (34) +#define WB_IO2 PIN_3V3_EN // RAK1910 GPS module // If using the wisblock GPS module and pluged into Port A on WisBlock base @@ -270,4 +273,4 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif \ No newline at end of file +#endif diff --git a/variants/rak4631_epaper/platformio.ini b/variants/rak4631_epaper/platformio.ini index b851691ed..9fe7ac1c7 100644 --- a/variants/rak4631_epaper/platformio.ini +++ b/variants/rak4631_epaper/platformio.ini @@ -17,6 +17,7 @@ lib_deps = melopero/Melopero RV3028@^1.1.0 rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 beegee-tokyo/RAKwireless RAK12034@^1.0.0 + beegee-tokyo/RAK12035_SoilMoisture@^1.0.3 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink diff --git a/variants/rak4631_epaper/variant.h b/variants/rak4631_epaper/variant.h index 0bb97498c..c1e11bee5 100644 --- a/variants/rak4631_epaper/variant.h +++ b/variants/rak4631_epaper/variant.h @@ -90,6 +90,8 @@ static const uint8_t A7 = PIN_A7; // Other pins #define PIN_AREF (2) #define PIN_NFC1 (9) +#define WB_IO5 PIN_NFC1 +#define WB_IO4 (4) #define PIN_NFC2 (10) static const uint8_t AREF = PIN_AREF; @@ -188,6 +190,7 @@ static const uint8_t SCK = PIN_SPI_SCK; // enables 3.3V periphery like GPS or IO Module #define PIN_3V3_EN (34) +#define WB_IO2 PIN_3V3_EN // RAK1910 GPS module // If using the wisblock GPS module and pluged into Port A on WisBlock base @@ -231,4 +234,4 @@ static const uint8_t SCK = PIN_SPI_SCK; * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif \ No newline at end of file +#endif diff --git a/variants/rak4631_epaper_onrxtx/platformio.ini b/variants/rak4631_epaper_onrxtx/platformio.ini index 8612a3f3d..c5300243d 100644 --- a/variants/rak4631_epaper_onrxtx/platformio.ini +++ b/variants/rak4631_epaper_onrxtx/platformio.ini @@ -19,6 +19,7 @@ lib_deps = melopero/Melopero RV3028@^1.1.0 rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 beegee-tokyo/RAKwireless RAK12034@^1.0.0 + beegee-tokyo/RAK12035_SoilMoisture@^1.0.3 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink diff --git a/variants/rak4631_epaper_onrxtx/variant.h b/variants/rak4631_epaper_onrxtx/variant.h index 5888cff33..1f8257e8e 100644 --- a/variants/rak4631_epaper_onrxtx/variant.h +++ b/variants/rak4631_epaper_onrxtx/variant.h @@ -69,7 +69,9 @@ static const uint8_t A7 = PIN_A7; // Other pins #define PIN_AREF (2) -// #define PIN_NFC1 (9) +#define PIN_NFC1 (9) +#define WB_IO5 PIN_NFC1 +#define WB_IO4 (4) // #define PIN_NFC2 (10) static const uint8_t AREF = PIN_AREF; @@ -160,6 +162,7 @@ static const uint8_t SCK = PIN_SPI_SCK; // enables 3.3V periphery like GPS or IO Module #define PIN_3V3_EN (34) +#define WB_IO2 PIN_3V3_EN // NO GPS #undef GPS_RX_PIN @@ -202,4 +205,4 @@ static const uint8_t SCK = PIN_SPI_SCK; * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif \ No newline at end of file +#endif diff --git a/variants/rak4631_eth_gw/variant.h b/variants/rak4631_eth_gw/variant.h index bc5541336..c8a2f83ae 100644 --- a/variants/rak4631_eth_gw/variant.h +++ b/variants/rak4631_eth_gw/variant.h @@ -90,6 +90,8 @@ static const uint8_t A7 = PIN_A7; // Other pins #define PIN_AREF (2) #define PIN_NFC1 (9) +#define WB_IO5 PIN_NFC1 +#define WB_IO4 (4) #define PIN_NFC2 (10) static const uint8_t AREF = PIN_AREF; @@ -217,6 +219,7 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG // enables 3.3V periphery like GPS or IO Module // Do not toggle this for GPS power savings #define PIN_3V3_EN (34) +#define WB_IO2 PIN_3V3_EN // RAK1910 GPS module // If using the wisblock GPS module and pluged into Port A on WisBlock base @@ -270,4 +273,4 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif \ No newline at end of file +#endif diff --git a/variants/rak_wismeshtap/platformio.ini b/variants/rak_wismeshtap/platformio.ini index bcf46b90d..a40a27ae4 100644 --- a/variants/rak_wismeshtap/platformio.ini +++ b/variants/rak_wismeshtap/platformio.ini @@ -23,6 +23,7 @@ lib_deps = bodmer/TFT_eSPI beegee-tokyo/RAKwireless RAK12034@^1.0.0 beegee-tokyo/RAK14014-FT6336U @ 1.0.1 + beegee-tokyo/RAK12035_SoilMoisture@^1.0.3 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink diff --git a/variants/rak_wismeshtap/variant.h b/variants/rak_wismeshtap/variant.h index c21a11ac1..3006189cf 100644 --- a/variants/rak_wismeshtap/variant.h +++ b/variants/rak_wismeshtap/variant.h @@ -90,6 +90,8 @@ static const uint8_t A7 = PIN_A7; // Other pins #define PIN_AREF (2) #define PIN_NFC1 (9) +#define WB_IO5 PIN_NFC1 +#define WB_IO4 (4) #define PIN_NFC2 (10) static const uint8_t AREF = PIN_AREF; @@ -311,4 +313,4 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif \ No newline at end of file +#endif From 3ca6d2f23017781d79c468d60a44eb663caf5292 Mon Sep 17 00:00:00 2001 From: Tom Fifield Date: Fri, 7 Mar 2025 20:22:52 +0800 Subject: [PATCH 04/38] [WIP] Add RAK12035VB Soil Moisture Sensor support Introduce the RAK12035 sensor as an environmental telemetry sensor, including necessary calibration checks and default values. Update relevant files to integrate the sensor into the existing telemetry system. This hardware is not just one module, but a couple.. RAK12023 and RAK12035 is the component stack, the RAK12023 does not seem to matter much and allows for multiple RAK12035 devices to be used. Co-Authored-By: @Justin-Mann --- src/configuration.h | 9 ++ src/detect/ScanI2C.h | 1 + src/detect/ScanI2CTwoWire.cpp | 14 ++- src/main.cpp | 1 + .../Telemetry/EnvironmentTelemetry.cpp | 30 ++++- .../Telemetry/Sensor/RAK12035Sensor.cpp | 118 ++++++++++++++++++ src/modules/Telemetry/Sensor/RAK12035Sensor.h | 29 +++++ variants/rak4631/platformio.ini | 3 +- variants/rak4631/variant.h | 5 +- variants/rak4631_epaper/platformio.ini | 1 + variants/rak4631_epaper/variant.h | 5 +- variants/rak4631_epaper_onrxtx/platformio.ini | 1 + variants/rak4631_epaper_onrxtx/variant.h | 7 +- variants/rak4631_eth_gw/variant.h | 5 +- variants/rak_wismeshtap/platformio.ini | 1 + variants/rak_wismeshtap/variant.h | 4 +- 16 files changed, 225 insertions(+), 9 deletions(-) create mode 100644 src/modules/Telemetry/Sensor/RAK12035Sensor.cpp create mode 100644 src/modules/Telemetry/Sensor/RAK12035Sensor.h diff --git a/src/configuration.h b/src/configuration.h index fd4a5b196..3a0a2ac6e 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -186,6 +186,15 @@ along with this program. If not, see . // ----------------------------------------------------------------------------- #define FT6336U_ADDR 0x48 +// ----------------------------------------------------------------------------- +// RAK12035VB Soil Monitor (using RAK12023 up to 3 RAK12035 monitors can be connected) +// - the default i2c address for this sensor is 0x20, and users are instructed to +// set 0x21 and 0x22 for the second and third sensor if present. +// ----------------------------------------------------------------------------- +#define RAK120351_ADDR 0x20 +#define RAK120352_ADDR 0x21 +#define RAK120353_ADDR 0x22 + // ----------------------------------------------------------------------------- // BIAS-T Generator // ----------------------------------------------------------------------------- diff --git a/src/detect/ScanI2C.h b/src/detect/ScanI2C.h index 5b6bbe629..8f6f5e7c2 100644 --- a/src/detect/ScanI2C.h +++ b/src/detect/ScanI2C.h @@ -69,6 +69,7 @@ class ScanI2C DFROBOT_RAIN, DPS310, LTR390UV, + RAK12035, } DeviceType; // typedef uint8_t DeviceAddress; diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 8b779277d..d28d0f687 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -417,9 +417,21 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) logFoundDevice("BMA423", (uint8_t)addr.address); } break; + case TCA9535_ADDR: + case RAK120352_ADDR: + case RAK120353_ADDR: + registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x02), 1); + if (registerValue == addr.address) { // RAK12035 returns its I2C address at 0x02 (eg 0x20) + type = RAK12035; + logFoundDevice("RAK12035", (uint8_t)addr.address); + } else { + type = TCA9535; + logFoundDevice("TCA9535", (uint8_t)addr.address); + } + + break; SCAN_SIMPLE_CASE(LSM6DS3_ADDR, LSM6DS3, "LSM6DS3", (uint8_t)addr.address); - SCAN_SIMPLE_CASE(TCA9535_ADDR, TCA9535, "TCA9535", (uint8_t)addr.address); SCAN_SIMPLE_CASE(TCA9555_ADDR, TCA9555, "TCA9555", (uint8_t)addr.address); SCAN_SIMPLE_CASE(VEML7700_ADDR, VEML7700, "VEML7700", (uint8_t)addr.address); SCAN_SIMPLE_CASE(TSL25911_ADDR, TSL2591, "TSL2591", (uint8_t)addr.address); diff --git a/src/main.cpp b/src/main.cpp index e9e0c9d4b..dfebac3df 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -643,6 +643,7 @@ void setup() scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::DFROBOT_RAIN, meshtastic_TelemetrySensorType_DFROBOT_RAIN); scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::LTR390UV, meshtastic_TelemetrySensorType_LTR390UV); scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::DPS310, meshtastic_TelemetrySensorType_DPS310); + scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::RAK12035, meshtastic_TelemetrySensorType_RAK12035); i2cScanner.reset(); #endif diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 8c0507e77..37f84a374 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -41,6 +41,9 @@ #include "Sensor/SHTC3Sensor.h" #include "Sensor/TSL2591Sensor.h" #include "Sensor/VEML7700Sensor.h" +#ifdef RAK4630 +#include "Sensor/RAK12035Sensor.h" +#endif BMP085Sensor bmp085Sensor; BMP280Sensor bmp280Sensor; @@ -63,6 +66,9 @@ DFRobotGravitySensor dfRobotGravitySensor; NAU7802Sensor nau7802Sensor; BMP3XXSensor bmp3xxSensor; CGRadSensSensor cgRadSens; +#ifdef RAK4630 +RAK12035Sensor rak12035Sensor; +#endif #endif #ifdef T1000X_SENSOR_EN #include "Sensor/T1000xSensor.h" @@ -72,6 +78,7 @@ T1000xSensor t1000xSensor; #include "Sensor/IndicatorSensor.h" IndicatorSensor indicatorSensor; #endif + #define FAILED_STATE_SENSOR_READ_MULTIPLIER 10 #define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true @@ -172,6 +179,11 @@ int32_t EnvironmentTelemetryModule::runOnce() result = rak9154Sensor.runOnce(); #endif +#ifdef RAK4630 + if (rak12035Sensor.hasSensor()) { + result = rak12035Sensor.runOnce(); + } +#endif #endif } // it's possible to have this module enabled, only for displaying values on the screen. @@ -499,6 +511,12 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m valid = valid && rak9154Sensor.getMetrics(m); hasSensor = true; #endif +#ifdef RAK4630 + if (rak12035Sensor.hasSensor()) { + valid = valid && rak12035Sensor.getMetrics(m); + hasSensor = true; + } +#endif #endif return valid && hasSensor; } @@ -553,6 +571,9 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) LOG_INFO("Send: radiation=%fµR/h", m.variant.environment_metrics.radiation); + LOG_INFO("Send: soil_temperature=%f, soil_moisture=%u", m.variant.environment_metrics.soil_temperature, + m.variant.environment_metrics.soil_moisture); + sensor_read_error_count = 0; meshtastic_MeshPacket *p = allocDataProtobuf(m); @@ -711,8 +732,15 @@ AdminMessageHandleResult EnvironmentTelemetryModule::handleAdminMessageForModule if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } +#ifdef RAK4630 + if (rak12035Sensor.hasSensor()) { + result = rak12035Sensor.handleAdminMessage(mp, request, response); + if (result != AdminMessageHandleResult::NOT_HANDLED) + return result; + } +#endif #endif return result; } -#endif \ No newline at end of file +#endif diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp new file mode 100644 index 000000000..b31e34ee5 --- /dev/null +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -0,0 +1,118 @@ +#include "configuration.h" +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && defined(RAK4630) + +#include "../mesh/generated/meshtastic/telemetry.pb.h" +#include "RAK12035Sensor.h" + +RAK12035Sensor::RAK12035Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_RAK12035, "RAK12035") {} + +int32_t RAK12035Sensor::runOnce() +{ + LOG_INFO("Init sensor: %s", sensorName); + if (!hasSensor()) { + return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; + } + + sensor.set_sensor_addr(RAK120351_ADDR); + + sensor.begin(nodeTelemetrySensorsMap[sensorType].first); + // Get sensor firmware version + uint8_t data = 0; + sensor.get_sensor_version(&data); + LOG_INFO("Sensor Firmware version: %i", data); + + if (data != 0) { + LOG_DEBUG("RAK12035Sensor Init Succeed"); + status = true; + } else { + LOG_ERROR("RAK12035Sensor Init Failed"); + status = false; + } + sensor.sensor_sleep(); + return initI2CSensor(); +} + +void RAK12035Sensor::setup() +{ + // Set the calibration values + // Reading the saved calibration values from the sensor. + uint16_t zero_val = 0; + 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(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); + LOG_ERROR("This does not make sense. Youc can recalibrate this sensor using the calibration sketch included here: " + "https://github.com/RAKWireless/RAK12035_SoilMoisture."); + LOG_ERROR("For now, setting default calibration value for Dry Calibration: %d", default_zero_val); + sensor.set_dry_cal(default_zero_val); + sensor.get_dry_cal(&zero_val); + LOG_ERROR("Dry calibration reset complete. New value is %d", zero_val); + } + if (hundred_val == 0 || hundred_val >= zero_val) { + LOG_ERROR("Dry calibration value is %d", zero_val); + LOG_ERROR("Wet calibration value is %d", hundred_val); + LOG_ERROR("This does not make sense. Youc can recalibrate this sensor using the calibration sketch included here: " + "https://github.com/RAKWireless/RAK12035_SoilMoisture."); + LOG_ERROR("For now, setting default calibration value for Wet Calibration: %d", default_hundred_val); + sensor.set_wet_cal(default_hundred_val); + sensor.get_wet_cal(&hundred_val); + LOG_ERROR("Wet calibration reset complete. New value is %d", hundred_val); + } + sensor.sensor_sleep(); + delay(200); + LOG_INFO("Dry calibration value is %d", zero_val); + LOG_INFO("Wet calibration value is %d", hundred_val); +} + +bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement) +{ + measurement->variant.environment_metrics.has_soil_temperature = true; + measurement->variant.environment_metrics.has_soil_moisture = true; + + uint8_t moisture = 0; + uint16_t temp = 0; + bool success = false; + + sensor.sensor_on(); + delay(200); + success = sensor.get_sensor_moisture(&moisture); + delay(200); + success = sensor.get_sensor_temperature(&temp); + delay(200); + sensor.sensor_sleep(); + + if (success == false) { + LOG_ERROR("Failed to read sensor data"); + return false; + } + LOG_INFO("Successful read from sensor Temperature: %.2f, Moisture: %ld%", (double)(temp / 10), moisture); + measurement->variant.environment_metrics.soil_temperature = (float)(temp / 10); + measurement->variant.environment_metrics.soil_moisture = moisture; + + LOG_INFO("Check if the original temperature and moisture (relative_humidity) are being used.. if not just use them for the " + "soil monitoring."); + + if (!measurement->variant.environment_metrics.has_temperature) { + LOG_INFO("Overwrite the temp metrics (not being set right now and this will allow the soil temp value to be used in the " + "client interface)."); + measurement->variant.environment_metrics.has_temperature = true; + measurement->variant.environment_metrics.temperature = (float)(temp / 10); + } + + if (!measurement->variant.environment_metrics.has_relative_humidity) { + LOG_INFO("Overwrite the moisture metrics (not being used for air humidity and this will allow the soil humidity to " + "appear in the client interfaces without adjustments)."); + measurement->variant.environment_metrics.has_relative_humidity = true; + measurement->variant.environment_metrics.relative_humidity = (float)moisture; + } + + return true; +} +#endif diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.h b/src/modules/Telemetry/Sensor/RAK12035Sensor.h new file mode 100644 index 000000000..77ffe24fa --- /dev/null +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.h @@ -0,0 +1,29 @@ +#pragma once + +#include "configuration.h" + +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && defined(RAK4630) +#ifndef _MT_RAK12035VBSENSOR_H +#define _MT_RAK12035VBSENSOR_H +#endif + +#include "../mesh/generated/meshtastic/telemetry.pb.h" +#include "RAK12035_SoilMoisture.h" +#include "TelemetrySensor.h" +#include + +class RAK12035Sensor : public TelemetrySensor +{ + private: + RAK12035 sensor; + + protected: + virtual void setup() override; + + public: + RAK12035Sensor(); + virtual int32_t runOnce() override; + virtual bool getMetrics(meshtastic_Telemetry *measurement) override; +}; + +#endif diff --git a/variants/rak4631/platformio.ini b/variants/rak4631/platformio.ini index ced93df66..4823ccdfa 100644 --- a/variants/rak4631/platformio.ini +++ b/variants/rak4631/platformio.ini @@ -20,6 +20,7 @@ lib_deps = https://github.com/RAKWireless/RAK13800-W5100S.git#1.0.2 rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 https://github.com/RAKWireless/RAK12034-BMX160.git#dcead07ffa267d3c906e9ca4a1330ab989e957e2 + beegee-tokyo/RAK12035_SoilMoisture@^1.0.3 ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ; Note: as of 6/2013 the serial/bootloader based programming takes approximately 30 seconds @@ -52,4 +53,4 @@ lib_deps = upload_protocol = stlink ; eventually use platformio/tool-pyocd@^2.3600.0 instad ;upload_protocol = custom -;upload_command = pyocd flash -t nrf52840 $UPLOADERFLAGS $SOURCE \ No newline at end of file +;upload_command = pyocd flash -t nrf52840 $UPLOADERFLAGS $SOURCE diff --git a/variants/rak4631/variant.h b/variants/rak4631/variant.h index bc5541336..c8a2f83ae 100644 --- a/variants/rak4631/variant.h +++ b/variants/rak4631/variant.h @@ -90,6 +90,8 @@ static const uint8_t A7 = PIN_A7; // Other pins #define PIN_AREF (2) #define PIN_NFC1 (9) +#define WB_IO5 PIN_NFC1 +#define WB_IO4 (4) #define PIN_NFC2 (10) static const uint8_t AREF = PIN_AREF; @@ -217,6 +219,7 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG // enables 3.3V periphery like GPS or IO Module // Do not toggle this for GPS power savings #define PIN_3V3_EN (34) +#define WB_IO2 PIN_3V3_EN // RAK1910 GPS module // If using the wisblock GPS module and pluged into Port A on WisBlock base @@ -270,4 +273,4 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif \ No newline at end of file +#endif diff --git a/variants/rak4631_epaper/platformio.ini b/variants/rak4631_epaper/platformio.ini index b851691ed..9fe7ac1c7 100644 --- a/variants/rak4631_epaper/platformio.ini +++ b/variants/rak4631_epaper/platformio.ini @@ -17,6 +17,7 @@ lib_deps = melopero/Melopero RV3028@^1.1.0 rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 beegee-tokyo/RAKwireless RAK12034@^1.0.0 + beegee-tokyo/RAK12035_SoilMoisture@^1.0.3 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink diff --git a/variants/rak4631_epaper/variant.h b/variants/rak4631_epaper/variant.h index 0bb97498c..c1e11bee5 100644 --- a/variants/rak4631_epaper/variant.h +++ b/variants/rak4631_epaper/variant.h @@ -90,6 +90,8 @@ static const uint8_t A7 = PIN_A7; // Other pins #define PIN_AREF (2) #define PIN_NFC1 (9) +#define WB_IO5 PIN_NFC1 +#define WB_IO4 (4) #define PIN_NFC2 (10) static const uint8_t AREF = PIN_AREF; @@ -188,6 +190,7 @@ static const uint8_t SCK = PIN_SPI_SCK; // enables 3.3V periphery like GPS or IO Module #define PIN_3V3_EN (34) +#define WB_IO2 PIN_3V3_EN // RAK1910 GPS module // If using the wisblock GPS module and pluged into Port A on WisBlock base @@ -231,4 +234,4 @@ static const uint8_t SCK = PIN_SPI_SCK; * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif \ No newline at end of file +#endif diff --git a/variants/rak4631_epaper_onrxtx/platformio.ini b/variants/rak4631_epaper_onrxtx/platformio.ini index 8612a3f3d..c5300243d 100644 --- a/variants/rak4631_epaper_onrxtx/platformio.ini +++ b/variants/rak4631_epaper_onrxtx/platformio.ini @@ -19,6 +19,7 @@ lib_deps = melopero/Melopero RV3028@^1.1.0 rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 beegee-tokyo/RAKwireless RAK12034@^1.0.0 + beegee-tokyo/RAK12035_SoilMoisture@^1.0.3 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink diff --git a/variants/rak4631_epaper_onrxtx/variant.h b/variants/rak4631_epaper_onrxtx/variant.h index 5888cff33..1f8257e8e 100644 --- a/variants/rak4631_epaper_onrxtx/variant.h +++ b/variants/rak4631_epaper_onrxtx/variant.h @@ -69,7 +69,9 @@ static const uint8_t A7 = PIN_A7; // Other pins #define PIN_AREF (2) -// #define PIN_NFC1 (9) +#define PIN_NFC1 (9) +#define WB_IO5 PIN_NFC1 +#define WB_IO4 (4) // #define PIN_NFC2 (10) static const uint8_t AREF = PIN_AREF; @@ -160,6 +162,7 @@ static const uint8_t SCK = PIN_SPI_SCK; // enables 3.3V periphery like GPS or IO Module #define PIN_3V3_EN (34) +#define WB_IO2 PIN_3V3_EN // NO GPS #undef GPS_RX_PIN @@ -202,4 +205,4 @@ static const uint8_t SCK = PIN_SPI_SCK; * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif \ No newline at end of file +#endif diff --git a/variants/rak4631_eth_gw/variant.h b/variants/rak4631_eth_gw/variant.h index bc5541336..c8a2f83ae 100644 --- a/variants/rak4631_eth_gw/variant.h +++ b/variants/rak4631_eth_gw/variant.h @@ -90,6 +90,8 @@ static const uint8_t A7 = PIN_A7; // Other pins #define PIN_AREF (2) #define PIN_NFC1 (9) +#define WB_IO5 PIN_NFC1 +#define WB_IO4 (4) #define PIN_NFC2 (10) static const uint8_t AREF = PIN_AREF; @@ -217,6 +219,7 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG // enables 3.3V periphery like GPS or IO Module // Do not toggle this for GPS power savings #define PIN_3V3_EN (34) +#define WB_IO2 PIN_3V3_EN // RAK1910 GPS module // If using the wisblock GPS module and pluged into Port A on WisBlock base @@ -270,4 +273,4 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif \ No newline at end of file +#endif diff --git a/variants/rak_wismeshtap/platformio.ini b/variants/rak_wismeshtap/platformio.ini index bcf46b90d..a40a27ae4 100644 --- a/variants/rak_wismeshtap/platformio.ini +++ b/variants/rak_wismeshtap/platformio.ini @@ -23,6 +23,7 @@ lib_deps = bodmer/TFT_eSPI beegee-tokyo/RAKwireless RAK12034@^1.0.0 beegee-tokyo/RAK14014-FT6336U @ 1.0.1 + beegee-tokyo/RAK12035_SoilMoisture@^1.0.3 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink diff --git a/variants/rak_wismeshtap/variant.h b/variants/rak_wismeshtap/variant.h index c21a11ac1..3006189cf 100644 --- a/variants/rak_wismeshtap/variant.h +++ b/variants/rak_wismeshtap/variant.h @@ -90,6 +90,8 @@ static const uint8_t A7 = PIN_A7; // Other pins #define PIN_AREF (2) #define PIN_NFC1 (9) +#define WB_IO5 PIN_NFC1 +#define WB_IO4 (4) #define PIN_NFC2 (10) static const uint8_t AREF = PIN_AREF; @@ -311,4 +313,4 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif \ No newline at end of file +#endif From 8704c15ca5984e4d2382383583a239fe5d990463 Mon Sep 17 00:00:00 2001 From: Tom Fifield Date: Mon, 14 Apr 2025 16:30:32 +1000 Subject: [PATCH 05/38] Update to 1.0.4 release of RAK12035_SoilMoisture --- variants/rak4631/platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/rak4631/platformio.ini b/variants/rak4631/platformio.ini index 95e5d8d2d..1d73bedb8 100644 --- a/variants/rak4631/platformio.ini +++ b/variants/rak4631/platformio.ini @@ -19,7 +19,7 @@ lib_deps = melopero/Melopero RV3028@^1.1.0 https://github.com/RAKWireless/RAK13800-W5100S/archive/1.0.2.zip rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 - beegee-tokyo/RAK12035_SoilMoisture@^1.0.3 + beegee-tokyo/RAK12035_SoilMoisture@^1.0.4 https://github.com/RAKWireless/RAK12034-BMX160/archive/dcead07ffa267d3c906e9ca4a1330ab989e957e2.zip ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) From e2b6375fac9fd4516bf774601099b289fe6ee66e Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Thu, 17 Apr 2025 17:00:20 -0600 Subject: [PATCH 06/38] cleanup --- .../Telemetry/Sensor/RAK12035Sensor.cpp | 22 ++----------------- variants/rak4631_epaper/platformio.ini | 2 +- variants/rak4631_epaper_onrxtx/platformio.ini | 2 +- variants/rak_wismeshtap/platformio.ini | 2 +- 4 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp index b31e34ee5..f3bd023e2 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -8,13 +8,13 @@ RAK12035Sensor::RAK12035Sensor() : TelemetrySensor(meshtastic_TelemetrySensorTyp int32_t RAK12035Sensor::runOnce() { + LOG_INFO("Init sensor: %s", sensorName); if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } - sensor.set_sensor_addr(RAK120351_ADDR); - + delay(500); sensor.begin(nodeTelemetrySensorsMap[sensorType].first); // Get sensor firmware version uint8_t data = 0; @@ -92,27 +92,9 @@ bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement) LOG_ERROR("Failed to read sensor data"); return false; } - LOG_INFO("Successful read from sensor Temperature: %.2f, Moisture: %ld%", (double)(temp / 10), moisture); measurement->variant.environment_metrics.soil_temperature = (float)(temp / 10); measurement->variant.environment_metrics.soil_moisture = moisture; - LOG_INFO("Check if the original temperature and moisture (relative_humidity) are being used.. if not just use them for the " - "soil monitoring."); - - if (!measurement->variant.environment_metrics.has_temperature) { - LOG_INFO("Overwrite the temp metrics (not being set right now and this will allow the soil temp value to be used in the " - "client interface)."); - measurement->variant.environment_metrics.has_temperature = true; - measurement->variant.environment_metrics.temperature = (float)(temp / 10); - } - - if (!measurement->variant.environment_metrics.has_relative_humidity) { - LOG_INFO("Overwrite the moisture metrics (not being used for air humidity and this will allow the soil humidity to " - "appear in the client interfaces without adjustments)."); - measurement->variant.environment_metrics.has_relative_humidity = true; - measurement->variant.environment_metrics.relative_humidity = (float)moisture; - } - return true; } #endif diff --git a/variants/rak4631_epaper/platformio.ini b/variants/rak4631_epaper/platformio.ini index 9fe7ac1c7..35fba1a2c 100644 --- a/variants/rak4631_epaper/platformio.ini +++ b/variants/rak4631_epaper/platformio.ini @@ -17,7 +17,7 @@ lib_deps = melopero/Melopero RV3028@^1.1.0 rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 beegee-tokyo/RAKwireless RAK12034@^1.0.0 - beegee-tokyo/RAK12035_SoilMoisture@^1.0.3 + beegee-tokyo/RAK12035_SoilMoisture@^1.0.4 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink diff --git a/variants/rak4631_epaper_onrxtx/platformio.ini b/variants/rak4631_epaper_onrxtx/platformio.ini index c5300243d..256b3b7d4 100644 --- a/variants/rak4631_epaper_onrxtx/platformio.ini +++ b/variants/rak4631_epaper_onrxtx/platformio.ini @@ -19,7 +19,7 @@ lib_deps = melopero/Melopero RV3028@^1.1.0 rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 beegee-tokyo/RAKwireless RAK12034@^1.0.0 - beegee-tokyo/RAK12035_SoilMoisture@^1.0.3 + beegee-tokyo/RAK12035_SoilMoisture@^1.0.4 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink diff --git a/variants/rak_wismeshtap/platformio.ini b/variants/rak_wismeshtap/platformio.ini index 446ff43ec..421683f96 100644 --- a/variants/rak_wismeshtap/platformio.ini +++ b/variants/rak_wismeshtap/platformio.ini @@ -23,7 +23,7 @@ lib_deps = bodmer/TFT_eSPI beegee-tokyo/RAKwireless RAK12034@^1.0.0 beegee-tokyo/RAK14014-FT6336U @ 1.0.1 - beegee-tokyo/RAK12035_SoilMoisture@^1.0.3 + beegee-tokyo/RAK12035_SoilMoisture@^1.0.4 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink From 492b35a41880da5b5802d31e356f9ccd4e49cdfc Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Sat, 19 Apr 2025 15:45:18 -0600 Subject: [PATCH 07/38] cool --- protobufs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobufs b/protobufs index 27fac3914..76f806e1b 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 27fac39141d99fe727a0a1824c5397409b1aea75 +Subproject commit 76f806e1bb1e2a7b157a14fadd095775f63db5e4 From adfacf761621bb27672701db9f4f45e45dc54f16 Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Mon, 5 May 2025 09:07:58 -0600 Subject: [PATCH 08/38] . --- src/modules/Telemetry/EnvironmentTelemetry.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index c74280d00..77a7db00b 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -94,21 +94,13 @@ SHTC3Sensor shtc3Sensor; NullSensor shtc3Sensor; #endif -#if __has_include() -#include "Sensor/VEML7700Sensor.h" + #ifdef RAK4630 #include "Sensor/RAK12035Sensor.h" #endif -BMP085Sensor bmp085Sensor; -BMP280Sensor bmp280Sensor; -BME280Sensor bme280Sensor; -BME680Sensor bme680Sensor; -DPS310Sensor dps310Sensor; -MCP9808Sensor mcp9808Sensor; -SHTC3Sensor shtc3Sensor; -LPS22HBSensor lps22hbSensor; -SHT31Sensor sht31Sensor; +#if __has_include() +#include "Sensor/VEML7700Sensor.h" VEML7700Sensor veml7700Sensor; #else NullSensor veml7700Sensor; From 0a3f27bf5b72ab4c5a6158f38b2810dc40ecb0bc Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Mon, 5 May 2025 09:14:01 -0600 Subject: [PATCH 09/38] .. --- src/modules/Telemetry/EnvironmentTelemetry.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 77a7db00b..d6eb4590f 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -94,9 +94,11 @@ SHTC3Sensor shtc3Sensor; NullSensor shtc3Sensor; #endif - -#ifdef RAK4630 +#if __has_include() && defined(RAK4630) #include "Sensor/RAK12035Sensor.h" +RAK12035Sensor rak12035Sensor; +#else +NullSensor shtc3Sensor; #endif #if __has_include() @@ -164,9 +166,7 @@ NullSensor bmp3xxSensor; RCWL9620Sensor rcwl9620Sensor; CGRadSensSensor cgRadSens; -#ifdef RAK4630 -RAK12035Sensor rak12035Sensor; -#endif + #endif #ifdef T1000X_SENSOR_EN #include "Sensor/T1000xSensor.h" From 440f3fd47f1e086003e84b4c607aa287d351ac72 Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Mon, 5 May 2025 12:05:25 -0600 Subject: [PATCH 10/38] little bit of cleanup and recompile/upload/test on RAK WISBLAOCK STACK: RAK19007/RAK4631/RAK12035VB/RAK12500 looks like soil monitor is working correctly, new environmental metrics are comming thru [new protos soil_moisture, soil_temperature] and GPS is working again with the RAK 12500. improvements could be made around the configuration of the monitor. next steps include updating the client(s) to react to, log and display the new proto metrics for soil temp and humidity. --- src/modules/Telemetry/EnvironmentTelemetry.cpp | 10 +++++----- src/modules/Telemetry/Sensor/RAK12035Sensor.cpp | 2 +- src/modules/Telemetry/Sensor/RAK12035Sensor.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index d6eb4590f..1e2d34e79 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -94,11 +94,11 @@ SHTC3Sensor shtc3Sensor; NullSensor shtc3Sensor; #endif -#if __has_include() && defined(RAK4630) +#if __has_include() && defined(RAK_4631) #include "Sensor/RAK12035Sensor.h" RAK12035Sensor rak12035Sensor; #else -NullSensor shtc3Sensor; +NullSensor rak12035Sensor; #endif #if __has_include() @@ -279,7 +279,7 @@ int32_t EnvironmentTelemetryModule::runOnce() result = rak9154Sensor.runOnce(); #endif -#ifdef RAK4630 +#if __has_include("RAK12035_SoilMoisture.h") && defined(RAK_4631) if (rak12035Sensor.hasSensor()) { result = rak12035Sensor.runOnce(); } @@ -613,7 +613,7 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m valid = valid && rak9154Sensor.getMetrics(m); hasSensor = true; #endif -#ifdef RAK4630 +#if __has_include() && defined(RAK_4631) // Not really needed, but may as well just skip at a lower level it if no library or not a RAK_4631 if (rak12035Sensor.hasSensor()) { valid = valid && rak12035Sensor.getMetrics(m); hasSensor = true; @@ -834,7 +834,7 @@ AdminMessageHandleResult EnvironmentTelemetryModule::handleAdminMessageForModule if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } -#ifdef RAK4630 +#if __has_include() && defined(RAK_4631) // Not really needed, but may as well just skip it at a lower level if no library or not a RAK_4631 if (rak12035Sensor.hasSensor()) { result = rak12035Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp index f3bd023e2..d1e9b3718 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -1,5 +1,5 @@ #include "configuration.h" -#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && defined(RAK4630) +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && __has_include("RAK12035_SoilMoisture.h") && defined(RAK_4631) #include "../mesh/generated/meshtastic/telemetry.pb.h" #include "RAK12035Sensor.h" diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.h b/src/modules/Telemetry/Sensor/RAK12035Sensor.h index 77ffe24fa..5d7082f20 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.h +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.h @@ -2,7 +2,7 @@ #include "configuration.h" -#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && defined(RAK4630) +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && __has_include() && defined(RAK_4631) #ifndef _MT_RAK12035VBSENSOR_H #define _MT_RAK12035VBSENSOR_H #endif From b33ddfeceb755fc6e5aa29325f7cbcac4d0fc1fc Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Mon, 5 May 2025 13:00:36 -0600 Subject: [PATCH 11/38] . comments about current limitations and TODOs --- src/modules/Telemetry/Sensor/RAK12035Sensor.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp index d1e9b3718..6fb3f008e 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -16,6 +16,11 @@ int32_t RAK12035Sensor::runOnce() sensor.set_sensor_addr(RAK120351_ADDR); delay(500); sensor.begin(nodeTelemetrySensorsMap[sensorType].first); + + + // TODO:: check for up to 2 additional sensors and start them if present. + + // Get sensor firmware version uint8_t data = 0; sensor.get_sensor_version(&data); @@ -36,6 +41,7 @@ void RAK12035Sensor::setup() { // Set the calibration values // Reading the saved calibration values from the sensor. + // TODO:: Check for and run calibration check for up to 2 additional sensors if present. uint16_t zero_val = 0; uint16_t hundred_val = 0; uint16_t default_zero_val = 550; @@ -73,6 +79,10 @@ void RAK12035Sensor::setup() bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement) { + // TODO:: read and send metrics for up to 2 additional soil monitors if present. + // -- how to do this.. this could get a little complex.. + // ie - 1> we combine them into an average and send that, 2> we send them as separate metrics + // ^-- these scenarios would require different handling of the metrics in the receiving end and maybe a setting in the device ui and an additional proto for that? measurement->variant.environment_metrics.has_soil_temperature = true; measurement->variant.environment_metrics.has_soil_moisture = true; From b5be032cb3f9d0d995f8d85baa5f5e4b597f3dce Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Mon, 5 May 2025 13:23:06 -0600 Subject: [PATCH 12/38] trunk update --- .trunk/trunk.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index c55635d9c..af392acb1 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -8,10 +8,11 @@ plugins: uri: https://github.com/trunk-io/plugins lint: enabled: + - checkov@3.2.414 - renovate@40.0.6 - prettier@3.5.3 - - trufflehog@3.88.26 - - yamllint@1.37.0 + - trufflehog@3.88.27 + - yamllint@1.37.1 - bandit@1.8.3 - terrascan@1.19.9 - trivy@0.61.1 From 07b76e848bd6cd3f7b552b5390c859b0d7d15101 Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Mon, 5 May 2025 14:21:24 -0600 Subject: [PATCH 13/38] trying to autoformat.. --- src/modules/Telemetry/EnvironmentTelemetry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 1e2d34e79..6d9c0745e 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -19,8 +19,8 @@ #include #if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR_EXTERNAL -// Sensors +// Sensors #include "Sensor/CGRadSensSensor.h" #include "Sensor/RCWL9620Sensor.h" #include "Sensor/nullSensor.h" From f21235a3678a03d63c12c0e12cdd206efff6365a Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Mon, 5 May 2025 14:29:07 -0600 Subject: [PATCH 14/38] fix formatting attempt 2 --- .vscode/settings.json | 2 +- .../Telemetry/EnvironmentTelemetry.cpp | 303 ++++++++++++------ .../Telemetry/Sensor/RAK12035Sensor.cpp | 25 +- 3 files changed, 220 insertions(+), 110 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 81deca8f9..3ad7fbac0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,7 +6,7 @@ "files.trimFinalNewlines": false, "cmake.configureOnOpen": false, "[cpp]": { - "editor.defaultFormatter": "trunk.io" + "editor.defaultFormatter": "ms-vscode.cpptools" }, "[powershell]": { "editor.defaultFormatter": "ms-vscode.powershell" diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 6d9c0745e..cbbb834df 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -185,7 +185,8 @@ IndicatorSensor indicatorSensor; int32_t EnvironmentTelemetryModule::runOnce() { - if (sleepOnNextExecution == true) { + if (sleepOnNextExecution == true) + { sleepOnNextExecution = false; uint32_t nightyNightMs = Default::getConfiguredOrDefaultMs(moduleConfig.telemetry.environment_update_interval, default_telemetry_broadcast_interval_secs); @@ -204,16 +205,19 @@ int32_t EnvironmentTelemetryModule::runOnce() // moduleConfig.telemetry.environment_update_interval = 15; if (!(moduleConfig.telemetry.environment_measurement_enabled || moduleConfig.telemetry.environment_screen_enabled || - ENVIRONMENTAL_TELEMETRY_MODULE_ENABLE)) { + ENVIRONMENTAL_TELEMETRY_MODULE_ENABLE)) + { // If this module is not enabled, and the user doesn't want the display screen don't waste any OSThread time on it return disable(); } - if (firstTime) { + if (firstTime) + { // This is the first time the OSThread library has called this function, so do some setup firstTime = 0; - if (moduleConfig.telemetry.environment_measurement_enabled || ENVIRONMENTAL_TELEMETRY_MODULE_ENABLE) { + if (moduleConfig.telemetry.environment_measurement_enabled || ENVIRONMENTAL_TELEMETRY_MODULE_ENABLE) + { LOG_INFO("Environment Telemetry: init"); #ifdef SENSECAP_INDICATOR result = indicatorSensor.runOnce(); @@ -273,14 +277,15 @@ int32_t EnvironmentTelemetryModule::runOnce() result = max17048Sensor.runOnce(); if (cgRadSens.hasSensor()) result = cgRadSens.runOnce(); - // this only works on the wismesh hub with the solar option. This is not an I2C sensor, so we don't need the - // sensormap here. + // this only works on the wismesh hub with the solar option. This is not an I2C sensor, so we don't need the + // sensormap here. #ifdef HAS_RAKPROT result = rak9154Sensor.runOnce(); #endif #if __has_include("RAK12035_SoilMoisture.h") && defined(RAK_4631) - if (rak12035Sensor.hasSensor()) { + if (rak12035Sensor.hasSensor()) + { result = rak12035Sensor.runOnce(); } #endif @@ -289,11 +294,16 @@ int32_t EnvironmentTelemetryModule::runOnce() // it's possible to have this module enabled, only for displaying values on the screen. // therefore, we should only enable the sensor loop if measurement is also enabled return result == UINT32_MAX ? disable() : setStartDelay(); - } else { + } + else + { // if we somehow got to a second run of this module with measurement disabled, then just wait forever - if (!moduleConfig.telemetry.environment_measurement_enabled && !ENVIRONMENTAL_TELEMETRY_MODULE_ENABLE) { + if (!moduleConfig.telemetry.environment_measurement_enabled && !ENVIRONMENTAL_TELEMETRY_MODULE_ENABLE) + { return disable(); - } else { + } + else + { #if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR_EXTERNAL if (bme680Sensor.hasSensor()) result = bme680Sensor.runTrigger(); @@ -305,11 +315,14 @@ int32_t EnvironmentTelemetryModule::runOnce() moduleConfig.telemetry.environment_update_interval, default_telemetry_broadcast_interval_secs, numOnlineNodes))) && airTime->isTxAllowedChannelUtil(config.device.role != meshtastic_Config_DeviceConfig_Role_SENSOR) && - airTime->isTxAllowedAirUtil()) { + airTime->isTxAllowedAirUtil()) + { sendTelemetry(); lastSentToMesh = millis(); - } else if (((lastSentToPhone == 0) || !Throttle::isWithinTimespanMs(lastSentToPhone, sendToPhoneIntervalMs)) && - (service->isToPhoneQueueEmpty())) { + } + else if (((lastSentToPhone == 0) || !Throttle::isWithinTimespanMs(lastSentToPhone, sendToPhoneIntervalMs)) && + (service->isToPhoneQueueEmpty())) + { // Just send to phone when it's not our time to send to mesh yet // Only send while queue is empty (phone assumed connected) sendTelemetry(NODENUM_BROADCAST, true); @@ -329,7 +342,8 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt display->setTextAlignment(TEXT_ALIGN_LEFT); display->setFont(FONT_SMALL); - if (lastMeasurementPacket == nullptr) { + if (lastMeasurementPacket == nullptr) + { // If there's no valid packet, display "Environment" display->drawString(x, y, "Environment"); display->drawString(x, y += _fontHeight(FONT_SMALL), "No measurement"); @@ -342,7 +356,8 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt const char *lastSender = getSenderShortName(*lastMeasurementPacket); const meshtastic_Data &p = lastMeasurementPacket->decoded; - if (!pb_decode_from_bytes(p.payload.bytes, p.payload.size, &meshtastic_Telemetry_msg, &lastMeasurement)) { + if (!pb_decode_from_bytes(p.payload.bytes, p.payload.size, &meshtastic_Telemetry_msg, &lastMeasurement)) + { display->drawString(x, y, "Measurement Error"); LOG_ERROR("Unable to decode last packet"); return; @@ -356,9 +371,11 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt int sensorCount = 0; if (lastMeasurement.variant.environment_metrics.has_temperature || - lastMeasurement.variant.environment_metrics.has_relative_humidity) { + lastMeasurement.variant.environment_metrics.has_relative_humidity) + { String last_temp = String(lastMeasurement.variant.environment_metrics.temperature, 0) + "°C"; - if (moduleConfig.telemetry.environment_display_fahrenheit) { + if (moduleConfig.telemetry.environment_display_fahrenheit) + { last_temp = String(UnitConversions::CelsiusToFahrenheit(lastMeasurement.variant.environment_metrics.temperature), 0) + "°F"; } @@ -367,37 +384,45 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt "Temp/Hum: " + last_temp + " / " + String(lastMeasurement.variant.environment_metrics.relative_humidity, 0) + "%"; } - if (lastMeasurement.variant.environment_metrics.barometric_pressure != 0) { + if (lastMeasurement.variant.environment_metrics.barometric_pressure != 0) + { sensorData[sensorCount++] = "Press: " + String(lastMeasurement.variant.environment_metrics.barometric_pressure, 0) + "hPA"; } - if (lastMeasurement.variant.environment_metrics.voltage != 0) { + if (lastMeasurement.variant.environment_metrics.voltage != 0) + { sensorData[sensorCount++] = "Volt/Cur: " + String(lastMeasurement.variant.environment_metrics.voltage, 0) + "V / " + String(lastMeasurement.variant.environment_metrics.current, 0) + "mA"; } - if (lastMeasurement.variant.environment_metrics.iaq != 0) { + if (lastMeasurement.variant.environment_metrics.iaq != 0) + { sensorData[sensorCount++] = "IAQ: " + String(lastMeasurement.variant.environment_metrics.iaq); } - if (lastMeasurement.variant.environment_metrics.distance != 0) { + if (lastMeasurement.variant.environment_metrics.distance != 0) + { sensorData[sensorCount++] = "Water Level: " + String(lastMeasurement.variant.environment_metrics.distance, 0) + "mm"; } - if (lastMeasurement.variant.environment_metrics.weight != 0) { + if (lastMeasurement.variant.environment_metrics.weight != 0) + { sensorData[sensorCount++] = "Weight: " + String(lastMeasurement.variant.environment_metrics.weight, 0) + "kg"; } - if (lastMeasurement.variant.environment_metrics.radiation != 0) { + if (lastMeasurement.variant.environment_metrics.radiation != 0) + { sensorData[sensorCount++] = "Rad: " + String(lastMeasurement.variant.environment_metrics.radiation, 2) + "µR/h"; } - if (lastMeasurement.variant.environment_metrics.lux != 0) { + if (lastMeasurement.variant.environment_metrics.lux != 0) + { sensorData[sensorCount++] = "Illuminance: " + String(lastMeasurement.variant.environment_metrics.lux, 2) + "lx"; } - if (lastMeasurement.variant.environment_metrics.white_lux != 0) { + if (lastMeasurement.variant.environment_metrics.white_lux != 0) + { sensorData[sensorCount++] = "W_Lux: " + String(lastMeasurement.variant.environment_metrics.white_lux, 2) + "lx"; } @@ -408,7 +433,8 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt // Determine how many lines we can fit on display // Calculated once only: display dimensions don't change during runtime. static int maxLines = 0; - if (!maxLines) { + if (!maxLines) + { const int16_t paddingTop = _fontHeight(FONT_SMALL); // Heading text const int16_t paddingBottom = 8; // Indicator dots maxLines = (display->getHeight() - paddingTop - paddingBottom) / _fontHeight(FONT_SMALL); @@ -417,23 +443,31 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt // Draw as many lines of data as we can fit int linesToShow = min(maxLines, sensorCount); - for (int i = 0; i < linesToShow; i++) { + for (int i = 0; i < linesToShow; i++) + { int index = (scrollOffset + i) % sensorCount; display->drawString(x, y += _fontHeight(FONT_SMALL), sensorData[index]); } // Only scroll if there are more than 3 sensor data lines - if (sensorCount > 3) { + if (sensorCount > 3) + { // Update scroll offset every 5 seconds - if (millis() - lastScrollTime > 5000) { - if (scrollingDown) { + if (millis() - lastScrollTime > 5000) + { + if (scrollingDown) + { scrollOffset++; - if (scrollOffset + linesToShow >= sensorCount) { + if (scrollOffset + linesToShow >= sensorCount) + { scrollingDown = false; } - } else { + } + else + { scrollOffset--; - if (scrollOffset <= 0) { + if (scrollOffset <= 0) + { scrollingDown = true; } } @@ -444,7 +478,8 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt bool EnvironmentTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *t) { - if (t->which_variant == meshtastic_Telemetry_environment_metrics_tag) { + if (t->which_variant == meshtastic_Telemetry_environment_metrics_tag) + { #ifdef DEBUG_PORT const char *sender = getSenderShortName(mp); @@ -491,108 +526,136 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m valid = valid && t1000xSensor.getMetrics(m); hasSensor = true; #else - if (dfRobotLarkSensor.hasSensor()) { + if (dfRobotLarkSensor.hasSensor()) + { valid = valid && dfRobotLarkSensor.getMetrics(m); hasSensor = true; } - if (dfRobotGravitySensor.hasSensor()) { + if (dfRobotGravitySensor.hasSensor()) + { valid = valid && dfRobotGravitySensor.getMetrics(m); hasSensor = true; } - if (sht31Sensor.hasSensor()) { + if (sht31Sensor.hasSensor()) + { valid = valid && sht31Sensor.getMetrics(m); hasSensor = true; } - if (sht4xSensor.hasSensor()) { + if (sht4xSensor.hasSensor()) + { valid = valid && sht4xSensor.getMetrics(m); hasSensor = true; } - if (lps22hbSensor.hasSensor()) { + if (lps22hbSensor.hasSensor()) + { valid = valid && lps22hbSensor.getMetrics(m); hasSensor = true; } - if (shtc3Sensor.hasSensor()) { + if (shtc3Sensor.hasSensor()) + { valid = valid && shtc3Sensor.getMetrics(m); hasSensor = true; } - if (bmp085Sensor.hasSensor()) { + if (bmp085Sensor.hasSensor()) + { valid = valid && bmp085Sensor.getMetrics(m); hasSensor = true; } #if __has_include() - if (bmp280Sensor.hasSensor()) { + if (bmp280Sensor.hasSensor()) + { valid = valid && bmp280Sensor.getMetrics(m); hasSensor = true; } #endif - if (bme280Sensor.hasSensor()) { + if (bme280Sensor.hasSensor()) + { valid = valid && bme280Sensor.getMetrics(m); hasSensor = true; } - if (bmp3xxSensor.hasSensor()) { + if (bmp3xxSensor.hasSensor()) + { valid = valid && bmp3xxSensor.getMetrics(m); hasSensor = true; } - if (bme680Sensor.hasSensor()) { + if (bme680Sensor.hasSensor()) + { valid = valid && bme680Sensor.getMetrics(m); hasSensor = true; } - if (dps310Sensor.hasSensor()) { + if (dps310Sensor.hasSensor()) + { valid = valid && dps310Sensor.getMetrics(m); hasSensor = true; } - if (mcp9808Sensor.hasSensor()) { + if (mcp9808Sensor.hasSensor()) + { valid = valid && mcp9808Sensor.getMetrics(m); hasSensor = true; } - if (ina219Sensor.hasSensor()) { + if (ina219Sensor.hasSensor()) + { valid = valid && ina219Sensor.getMetrics(m); hasSensor = true; } - if (ina260Sensor.hasSensor()) { + if (ina260Sensor.hasSensor()) + { valid = valid && ina260Sensor.getMetrics(m); hasSensor = true; } - if (ina3221Sensor.hasSensor()) { + if (ina3221Sensor.hasSensor()) + { valid = valid && ina3221Sensor.getMetrics(m); hasSensor = true; } - if (veml7700Sensor.hasSensor()) { + if (veml7700Sensor.hasSensor()) + { valid = valid && veml7700Sensor.getMetrics(m); hasSensor = true; } - if (tsl2591Sensor.hasSensor()) { + if (tsl2591Sensor.hasSensor()) + { valid = valid && tsl2591Sensor.getMetrics(m); hasSensor = true; } - if (opt3001Sensor.hasSensor()) { + if (opt3001Sensor.hasSensor()) + { valid = valid && opt3001Sensor.getMetrics(m); hasSensor = true; } - if (mlx90632Sensor.hasSensor()) { + if (mlx90632Sensor.hasSensor()) + { valid = valid && mlx90632Sensor.getMetrics(m); hasSensor = true; } - if (rcwl9620Sensor.hasSensor()) { + if (rcwl9620Sensor.hasSensor()) + { valid = valid && rcwl9620Sensor.getMetrics(m); hasSensor = true; } - if (nau7802Sensor.hasSensor()) { + if (nau7802Sensor.hasSensor()) + { valid = valid && nau7802Sensor.getMetrics(m); hasSensor = true; } - if (aht10Sensor.hasSensor()) { - if (!bmp280Sensor.hasSensor() && !bmp3xxSensor.hasSensor()) { + if (aht10Sensor.hasSensor()) + { + if (!bmp280Sensor.hasSensor() && !bmp3xxSensor.hasSensor()) + { valid = valid && aht10Sensor.getMetrics(m); hasSensor = true; - } else if (bmp280Sensor.hasSensor()) { + } + else if (bmp280Sensor.hasSensor()) + { // prefer bmp280 temp if both sensors are present, fetch only humidity meshtastic_Telemetry m_ahtx = meshtastic_Telemetry_init_zero; LOG_INFO("AHTX0+BMP280 module detected: using temp from BMP280 and humy from AHTX0"); aht10Sensor.getMetrics(&m_ahtx); m->variant.environment_metrics.relative_humidity = m_ahtx.variant.environment_metrics.relative_humidity; m->variant.environment_metrics.has_relative_humidity = m_ahtx.variant.environment_metrics.has_relative_humidity; - } else { + } + else + { // prefer bmp3xx temp if both sensors are present, fetch only humidity meshtastic_Telemetry m_ahtx = meshtastic_Telemetry_init_zero; LOG_INFO("AHTX0+BMP3XX module detected: using temp from BMP3XX and humy from AHTX0"); @@ -601,11 +664,13 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m m->variant.environment_metrics.has_relative_humidity = m_ahtx.variant.environment_metrics.has_relative_humidity; } } - if (max17048Sensor.hasSensor()) { + if (max17048Sensor.hasSensor()) + { valid = valid && max17048Sensor.getMetrics(m); hasSensor = true; } - if (cgRadSens.hasSensor()) { + if (cgRadSens.hasSensor()) + { valid = valid && cgRadSens.getMetrics(m); hasSensor = true; } @@ -614,7 +679,8 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m hasSensor = true; #endif #if __has_include() && defined(RAK_4631) // Not really needed, but may as well just skip at a lower level it if no library or not a RAK_4631 - if (rak12035Sensor.hasSensor()) { + if (rak12035Sensor.hasSensor()) + { valid = valid && rak12035Sensor.getMetrics(m); hasSensor = true; } @@ -625,25 +691,33 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m meshtastic_MeshPacket *EnvironmentTelemetryModule::allocReply() { - if (currentRequest) { + if (currentRequest) + { auto req = *currentRequest; const auto &p = req.decoded; meshtastic_Telemetry scratch; meshtastic_Telemetry *decoded = NULL; memset(&scratch, 0, sizeof(scratch)); - if (pb_decode_from_bytes(p.payload.bytes, p.payload.size, &meshtastic_Telemetry_msg, &scratch)) { + if (pb_decode_from_bytes(p.payload.bytes, p.payload.size, &meshtastic_Telemetry_msg, &scratch)) + { decoded = &scratch; - } else { + } + else + { LOG_ERROR("Error decoding EnvironmentTelemetry module!"); return NULL; } // Check for a request for environment metrics - if (decoded->which_variant == meshtastic_Telemetry_environment_metrics_tag) { + if (decoded->which_variant == meshtastic_Telemetry_environment_metrics_tag) + { meshtastic_Telemetry m = meshtastic_Telemetry_init_zero; - if (getEnvironmentTelemetry(&m)) { + if (getEnvironmentTelemetry(&m)) + { LOG_INFO("Environment telemetry reply to request"); return allocDataProtobuf(m); - } else { + } + else + { return NULL; } } @@ -657,9 +731,11 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) m.which_variant = meshtastic_Telemetry_environment_metrics_tag; m.time = getTime(); #ifdef T1000X_SENSOR_EN - if (t1000xSensor.getMetrics(&m)) { + if (t1000xSensor.getMetrics(&m)) + { #else - if (getEnvironmentTelemetry(&m)) { + if (getEnvironmentTelemetry(&m)) + { #endif LOG_INFO("Send: barometric_pressure=%f, current=%f, gas_resistance=%f, relative_humidity=%f, temperature=%f", m.variant.environment_metrics.barometric_pressure, m.variant.environment_metrics.current, @@ -690,14 +766,18 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) packetPool.release(lastMeasurementPacket); lastMeasurementPacket = packetPool.allocCopy(*p); - if (phoneOnly) { + if (phoneOnly) + { LOG_INFO("Send packet to phone"); service->sendToPhone(p); - } else { + } + else + { LOG_INFO("Send packet to mesh"); service->sendToMesh(p, RX_SRC_LOCAL, true); - if (config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR && config.power.is_power_saving) { + if (config.device.role == meshtastic_Config_DeviceConfig_Role_SENSOR && config.power.is_power_saving) + { LOG_DEBUG("Start next execution in 5s, then sleep"); sleepOnNextExecution = true; setIntervalFromNow(5000); @@ -714,128 +794,153 @@ AdminMessageHandleResult EnvironmentTelemetryModule::handleAdminMessageForModule { AdminMessageHandleResult result = AdminMessageHandleResult::NOT_HANDLED; #if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR_EXTERNAL - if (dfRobotLarkSensor.hasSensor()) { + if (dfRobotLarkSensor.hasSensor()) + { result = dfRobotLarkSensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (dfRobotGravitySensor.hasSensor()) { + if (dfRobotGravitySensor.hasSensor()) + { result = dfRobotGravitySensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (sht31Sensor.hasSensor()) { + if (sht31Sensor.hasSensor()) + { result = sht31Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (lps22hbSensor.hasSensor()) { + if (lps22hbSensor.hasSensor()) + { result = lps22hbSensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (shtc3Sensor.hasSensor()) { + if (shtc3Sensor.hasSensor()) + { result = shtc3Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (bmp085Sensor.hasSensor()) { + if (bmp085Sensor.hasSensor()) + { result = bmp085Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (bmp280Sensor.hasSensor()) { + if (bmp280Sensor.hasSensor()) + { result = bmp280Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (bme280Sensor.hasSensor()) { + if (bme280Sensor.hasSensor()) + { result = bme280Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (bmp3xxSensor.hasSensor()) { + if (bmp3xxSensor.hasSensor()) + { result = bmp3xxSensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (bme680Sensor.hasSensor()) { + if (bme680Sensor.hasSensor()) + { result = bme680Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (dps310Sensor.hasSensor()) { + if (dps310Sensor.hasSensor()) + { result = dps310Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (mcp9808Sensor.hasSensor()) { + if (mcp9808Sensor.hasSensor()) + { result = mcp9808Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (ina219Sensor.hasSensor()) { + if (ina219Sensor.hasSensor()) + { result = ina219Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (ina260Sensor.hasSensor()) { + if (ina260Sensor.hasSensor()) + { result = ina260Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (ina3221Sensor.hasSensor()) { + if (ina3221Sensor.hasSensor()) + { result = ina3221Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (veml7700Sensor.hasSensor()) { + if (veml7700Sensor.hasSensor()) + { result = veml7700Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (tsl2591Sensor.hasSensor()) { + if (tsl2591Sensor.hasSensor()) + { result = tsl2591Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (opt3001Sensor.hasSensor()) { + if (opt3001Sensor.hasSensor()) + { result = opt3001Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (mlx90632Sensor.hasSensor()) { + if (mlx90632Sensor.hasSensor()) + { result = mlx90632Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (rcwl9620Sensor.hasSensor()) { + if (rcwl9620Sensor.hasSensor()) + { result = rcwl9620Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (nau7802Sensor.hasSensor()) { + if (nau7802Sensor.hasSensor()) + { result = nau7802Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (aht10Sensor.hasSensor()) { + if (aht10Sensor.hasSensor()) + { result = aht10Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (max17048Sensor.hasSensor()) { + if (max17048Sensor.hasSensor()) + { result = max17048Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (cgRadSens.hasSensor()) { + if (cgRadSens.hasSensor()) + { result = cgRadSens.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } #if __has_include() && defined(RAK_4631) // Not really needed, but may as well just skip it at a lower level if no library or not a RAK_4631 - if (rak12035Sensor.hasSensor()) { + if (rak12035Sensor.hasSensor()) + { result = rak12035Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp index 6fb3f008e..f0abea3dd 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -10,26 +10,28 @@ int32_t RAK12035Sensor::runOnce() { LOG_INFO("Init sensor: %s", sensorName); - if (!hasSensor()) { + if (!hasSensor()) + { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } sensor.set_sensor_addr(RAK120351_ADDR); delay(500); sensor.begin(nodeTelemetrySensorsMap[sensorType].first); - // TODO:: check for up to 2 additional sensors and start them if present. - // Get sensor firmware version uint8_t data = 0; sensor.get_sensor_version(&data); LOG_INFO("Sensor Firmware version: %i", data); - if (data != 0) { + if (data != 0) + { LOG_DEBUG("RAK12035Sensor Init Succeed"); status = true; - } else { + } + else + { LOG_ERROR("RAK12035Sensor Init Failed"); status = false; } @@ -51,7 +53,8 @@ void RAK12035Sensor::setup() sensor.get_dry_cal(&zero_val); sensor.get_wet_cal(&hundred_val); delay(200); - if (zero_val == 0 || zero_val <= hundred_val) { + 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); LOG_ERROR("This does not make sense. Youc can recalibrate this sensor using the calibration sketch included here: " @@ -61,7 +64,8 @@ void RAK12035Sensor::setup() sensor.get_dry_cal(&zero_val); LOG_ERROR("Dry calibration reset complete. New value is %d", zero_val); } - if (hundred_val == 0 || hundred_val >= zero_val) { + if (hundred_val == 0 || hundred_val >= zero_val) + { LOG_ERROR("Dry calibration value is %d", zero_val); LOG_ERROR("Wet calibration value is %d", hundred_val); LOG_ERROR("This does not make sense. Youc can recalibrate this sensor using the calibration sketch included here: " @@ -80,8 +84,8 @@ void RAK12035Sensor::setup() bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement) { // TODO:: read and send metrics for up to 2 additional soil monitors if present. - // -- how to do this.. this could get a little complex.. - // ie - 1> we combine them into an average and send that, 2> we send them as separate metrics + // -- how to do this.. this could get a little complex.. + // ie - 1> we combine them into an average and send that, 2> we send them as separate metrics // ^-- these scenarios would require different handling of the metrics in the receiving end and maybe a setting in the device ui and an additional proto for that? measurement->variant.environment_metrics.has_soil_temperature = true; measurement->variant.environment_metrics.has_soil_moisture = true; @@ -98,7 +102,8 @@ bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement) delay(200); sensor.sensor_sleep(); - if (success == false) { + if (success == false) + { LOG_ERROR("Failed to read sensor data"); return false; } From 3ca29372bab783ea5bf86abe858557a8523de40e Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Mon, 5 May 2025 15:33:57 -0600 Subject: [PATCH 15/38] .. --- src/modules/Telemetry/Sensor/RAK12035Sensor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp index f0abea3dd..b8569853f 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -112,4 +112,4 @@ bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement) return true; } -#endif +#endif \ No newline at end of file From 0b31f6d9d9c475ffbc75d085a4be1938be6c3a50 Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Mon, 5 May 2025 15:34:29 -0600 Subject: [PATCH 16/38] ... --- src/modules/Telemetry/Sensor/RAK12035Sensor.h | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.h b/src/modules/Telemetry/Sensor/RAK12035Sensor.h index 5d7082f20..9e7316782 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.h +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.h @@ -14,16 +14,15 @@ class RAK12035Sensor : public TelemetrySensor { - private: - RAK12035 sensor; +private: + RAK12035 sensor; - protected: - virtual void setup() override; +protected: + virtual void setup() override; - public: - RAK12035Sensor(); - virtual int32_t runOnce() override; - virtual bool getMetrics(meshtastic_Telemetry *measurement) override; +public: + RAK12035Sensor(); + virtual int32_t runOnce() override; + virtual bool getMetrics(meshtastic_Telemetry *measurement) override; }; - -#endif +#endif \ No newline at end of file From 3b642ae9f650021c3ce570fec8bd04494f0bf1a1 Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Mon, 5 May 2025 15:52:14 -0600 Subject: [PATCH 17/38] ... --- src/modules/Telemetry/Sensor/RAK12035Sensor.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp index b8569853f..29d1538a4 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -110,6 +110,14 @@ bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement) measurement->variant.environment_metrics.soil_temperature = (float)(temp / 10); measurement->variant.environment_metrics.soil_moisture = moisture; + if (variant.environment_metrics.temperature == 0 || variant.environment_metrics.temperature == null && variant.environment_metrics.relative_humidity == 0 || variant.environment_metrics.relative_humidity == null) + { + measurement->variant.environment_metrics.has_temperature = true; + measurement->variant.environment_metrics.has_relative_humidity = true; + measurement->variant.environment_metrics.temperature = measurement->variant.environment_metrics.soil_temperature; + measurement->variant.environment_metrics.relative_humidity = measurement->variant.environment_metrics.soil_moisture; + } + return true; } #endif \ No newline at end of file From 5bed595c12e015fa28700854e622141e0a1b2878 Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Mon, 5 May 2025 15:54:34 -0600 Subject: [PATCH 18/38] . --- src/modules/Telemetry/Sensor/RAK12035Sensor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp index 29d1538a4..5f2b25c1b 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -110,6 +110,7 @@ bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement) measurement->variant.environment_metrics.soil_temperature = (float)(temp / 10); measurement->variant.environment_metrics.soil_moisture = moisture; + // temp code to get the values to the gui. will remove this once at least one of the clients is updated to use the new proto if (variant.environment_metrics.temperature == 0 || variant.environment_metrics.temperature == null && variant.environment_metrics.relative_humidity == 0 || variant.environment_metrics.relative_humidity == null) { measurement->variant.environment_metrics.has_temperature = true; From 3f2dd953f13484b81c0bb2772f946a6b57bfd43b Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Mon, 5 May 2025 16:19:15 -0600 Subject: [PATCH 19/38] some corrections and local build success --- src/modules/Telemetry/Sensor/RAK12035Sensor.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp index 5f2b25c1b..491606117 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -111,11 +111,15 @@ bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement) measurement->variant.environment_metrics.soil_moisture = moisture; // temp code to get the values to the gui. will remove this once at least one of the clients is updated to use the new proto - if (variant.environment_metrics.temperature == 0 || variant.environment_metrics.temperature == null && variant.environment_metrics.relative_humidity == 0 || variant.environment_metrics.relative_humidity == null) + if (!measurement->variant.environment_metrics.has_temperature && measurement->variant.environment_metrics.temperature == 0) { measurement->variant.environment_metrics.has_temperature = true; - measurement->variant.environment_metrics.has_relative_humidity = true; measurement->variant.environment_metrics.temperature = measurement->variant.environment_metrics.soil_temperature; + } + + if (measurement->variant.environment_metrics.relative_humidity == 0 && measurement->variant.environment_metrics.has_relative_humidity) + { + measurement->variant.environment_metrics.has_relative_humidity = true; measurement->variant.environment_metrics.relative_humidity = measurement->variant.environment_metrics.soil_moisture; } From 171ea1bfd012d0f5778edda8e807ff28d976a2c2 Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Mon, 5 May 2025 16:31:13 -0600 Subject: [PATCH 20/38] correction in temp code --- src/modules/Telemetry/Sensor/RAK12035Sensor.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp index 491606117..29b88077f 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -110,14 +110,15 @@ bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement) measurement->variant.environment_metrics.soil_temperature = (float)(temp / 10); measurement->variant.environment_metrics.soil_moisture = moisture; - // temp code to get the values to the gui. will remove this once at least one of the clients is updated to use the new proto + // TODO:: remove this once the clients are updated to use the new proto + // temp code to get the values to the gui. will remove this once at least one of the clients is updated to use the new proto if (!measurement->variant.environment_metrics.has_temperature && measurement->variant.environment_metrics.temperature == 0) { measurement->variant.environment_metrics.has_temperature = true; measurement->variant.environment_metrics.temperature = measurement->variant.environment_metrics.soil_temperature; } - if (measurement->variant.environment_metrics.relative_humidity == 0 && measurement->variant.environment_metrics.has_relative_humidity) + if (!measurement->variant.environment_metrics.has_relative_humidity && measurement->variant.environment_metrics.relative_humidity == 0) { measurement->variant.environment_metrics.has_relative_humidity = true; measurement->variant.environment_metrics.relative_humidity = measurement->variant.environment_metrics.soil_moisture; From 58d6f64d1ab6bcbb0cbba5b144a7a87b99facbcb Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Mon, 5 May 2025 17:23:39 -0600 Subject: [PATCH 21/38] grr formatting --- src/modules/Telemetry/Sensor/RAK12035Sensor.cpp | 2 +- src/modules/Telemetry/Sensor/RAK12035Sensor.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp index 29b88077f..aa31dc2cd 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -126,4 +126,4 @@ bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement) return true; } -#endif \ No newline at end of file +#endif diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.h b/src/modules/Telemetry/Sensor/RAK12035Sensor.h index 9e7316782..40c9e6598 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.h +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.h @@ -25,4 +25,4 @@ public: virtual int32_t runOnce() override; virtual bool getMetrics(meshtastic_Telemetry *measurement) override; }; -#endif \ No newline at end of file +#endif From ad9bc53807e95771c7a43ea7e9159ae964089e6f Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Mon, 5 May 2025 21:08:37 -0600 Subject: [PATCH 22/38] cleanup after a few experiments --- .../Telemetry/Sensor/RAK12035Sensor.cpp | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp index aa31dc2cd..6f263e57c 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -14,20 +14,20 @@ int32_t RAK12035Sensor::runOnce() { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } - sensor.set_sensor_addr(RAK120351_ADDR); - delay(500); - sensor.begin(nodeTelemetrySensorsMap[sensorType].first); // TODO:: check for up to 2 additional sensors and start them if present. + sensor.set_sensor_addr(RAK120351_ADDR); + delay(100); + sensor.begin(nodeTelemetrySensorsMap[sensorType].first); // Get sensor firmware version uint8_t data = 0; sensor.get_sensor_version(&data); - LOG_INFO("Sensor Firmware version: %i", data); + LOG_INFO("Sensor1 Firmware version: %i", data); if (data != 0) { - LOG_DEBUG("RAK12035Sensor Init Succeed"); + LOG_INFO("RAK12035Sensor Init Succeed"); status = true; } else @@ -55,25 +55,25 @@ void RAK12035Sensor::setup() 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); - LOG_ERROR("This does not make sense. Youc can recalibrate this sensor using the calibration sketch included here: " - "https://github.com/RAKWireless/RAK12035_SoilMoisture."); - LOG_ERROR("For now, setting default calibration value for Dry Calibration: %d", default_zero_val); + LOG_INFO("Dry calibration value is %d", zero_val); + LOG_INFO("Wet calibration value is %d", hundred_val); + LOG_INFO("This does not make sense. You can recalibrate this sensor using the calibration sketch included here: " + "https://github.com/RAKWireless/RAK12035_SoilMoisture."); + LOG_INFO("For now, setting default calibration value for Dry Calibration: %d", default_zero_val); sensor.set_dry_cal(default_zero_val); sensor.get_dry_cal(&zero_val); - LOG_ERROR("Dry calibration reset complete. New value is %d", zero_val); + LOG_INFO("Dry calibration reset complete. New value is %d", zero_val); } if (hundred_val == 0 || hundred_val >= zero_val) { - LOG_ERROR("Dry calibration value is %d", zero_val); - LOG_ERROR("Wet calibration value is %d", hundred_val); - LOG_ERROR("This does not make sense. Youc can recalibrate this sensor using the calibration sketch included here: " - "https://github.com/RAKWireless/RAK12035_SoilMoisture."); - LOG_ERROR("For now, setting default calibration value for Wet Calibration: %d", default_hundred_val); + LOG_INFO("Dry calibration value is %d", zero_val); + LOG_INFO("Wet calibration value is %d", hundred_val); + LOG_INFO("This does not make sense. You can recalibrate this sensor using the calibration sketch included here: " + "https://github.com/RAKWireless/RAK12035_SoilMoisture."); + LOG_INFO("For now, setting default calibration value for Wet Calibration: %d", default_hundred_val); sensor.set_wet_cal(default_hundred_val); sensor.get_wet_cal(&hundred_val); - LOG_ERROR("Wet calibration reset complete. New value is %d", hundred_val); + LOG_INFO("Wet calibration reset complete. New value is %d", hundred_val); } sensor.sensor_sleep(); delay(200); From b02e33a8044217e01a22b3e5da54027edb8855fd Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Tue, 6 May 2025 16:49:49 -0600 Subject: [PATCH 23/38] remove temp code to overwrite values for temp and humidity protos.. next step just update the clients to know about soil_temperature and soil_humidity protos. --- src/modules/Telemetry/Sensor/RAK12035Sensor.cpp | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp index 6f263e57c..25c631a74 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -110,20 +110,6 @@ bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement) measurement->variant.environment_metrics.soil_temperature = (float)(temp / 10); measurement->variant.environment_metrics.soil_moisture = moisture; - // TODO:: remove this once the clients are updated to use the new proto - // temp code to get the values to the gui. will remove this once at least one of the clients is updated to use the new proto - if (!measurement->variant.environment_metrics.has_temperature && measurement->variant.environment_metrics.temperature == 0) - { - measurement->variant.environment_metrics.has_temperature = true; - measurement->variant.environment_metrics.temperature = measurement->variant.environment_metrics.soil_temperature; - } - - if (!measurement->variant.environment_metrics.has_relative_humidity && measurement->variant.environment_metrics.relative_humidity == 0) - { - measurement->variant.environment_metrics.has_relative_humidity = true; - measurement->variant.environment_metrics.relative_humidity = measurement->variant.environment_metrics.soil_moisture; - } - return true; } #endif From 34b56ef31a4ad8cc8eaddca10a3a382dd82a6bc3 Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Tue, 6 May 2025 17:06:38 -0600 Subject: [PATCH 24/38] update some values in varient for rak wistap --- variants/rak_wismeshtap/variant.h | 141 +++++++++++++++--------------- 1 file changed, 71 insertions(+), 70 deletions(-) diff --git a/variants/rak_wismeshtap/variant.h b/variants/rak_wismeshtap/variant.h index 3006189cf..f30516b82 100644 --- a/variants/rak_wismeshtap/variant.h +++ b/variants/rak_wismeshtap/variant.h @@ -34,7 +34,8 @@ #include "WVariant.h" #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif // __cplusplus // Number of pins defined in PinDescription array @@ -55,9 +56,9 @@ extern "C" { #define LED_STATE_ON 1 // State when LED is litted -/* - * Buttons - */ + /* + * Buttons + */ #define PIN_BUTTON1 9 // Pin for button on E-ink button module or IO expansion such as the RAK14014 or RAK14015 TFT modules #define BUTTON_NEED_PULLUP @@ -77,14 +78,14 @@ extern "C" { #define PIN_A6 (0xff) #define PIN_A7 (0xff) -static const uint8_t A0 = PIN_A0; -static const uint8_t A1 = PIN_A1; -static const uint8_t A2 = PIN_A2; -static const uint8_t A3 = PIN_A3; -static const uint8_t A4 = PIN_A4; -static const uint8_t A5 = PIN_A5; -static const uint8_t A6 = PIN_A6; -static const uint8_t A7 = PIN_A7; + static const uint8_t A0 = PIN_A0; + static const uint8_t A1 = PIN_A1; + static const uint8_t A2 = PIN_A2; + static const uint8_t A3 = PIN_A3; + static const uint8_t A4 = PIN_A4; + static const uint8_t A5 = PIN_A5; + static const uint8_t A6 = PIN_A6; + static const uint8_t A7 = PIN_A7; #define ADC_RESOLUTION 14 // Other pins @@ -94,7 +95,7 @@ static const uint8_t A7 = PIN_A7; #define WB_IO4 (4) #define PIN_NFC2 (10) -static const uint8_t AREF = PIN_AREF; + static const uint8_t AREF = PIN_AREF; /* * Serial interfaces @@ -119,14 +120,14 @@ static const uint8_t AREF = PIN_AREF; #define PIN_SPI1_MOSI (30) // (0 + 30) #define PIN_SPI1_SCK (3) // (0 + 3) -static const uint8_t SS = 42; -static const uint8_t MOSI = PIN_SPI_MOSI; -static const uint8_t MISO = PIN_SPI_MISO; -static const uint8_t SCK = PIN_SPI_SCK; + static const uint8_t SS = 42; + static const uint8_t MOSI = PIN_SPI_MOSI; + static const uint8_t MISO = PIN_SPI_MISO; + static const uint8_t SCK = PIN_SPI_SCK; -/* - * eink display pins - */ + /* + * eink display pins + */ #define PIN_EINK_CS (0 + 26) #define PIN_EINK_BUSY (0 + 4) @@ -160,65 +161,65 @@ static const uint8_t SCK = PIN_SPI_SCK; #define EXTERNAL_FLASH_DEVICES IS25LP080D #define EXTERNAL_FLASH_USE_QSPI -/* @note RAK5005-O GPIO mapping to RAK4631 GPIO ports - RAK5005-O <-> nRF52840 - IO1 <-> P0.17 (Arduino GPIO number 17) - IO2 <-> P1.02 (Arduino GPIO number 34) - IO3 <-> P0.21 (Arduino GPIO number 21) - IO4 <-> P0.04 (Arduino GPIO number 4) - IO5 <-> P0.09 (Arduino GPIO number 9) - IO6 <-> P0.10 (Arduino GPIO number 10) - IO7 <-> P0.28 (Arduino GPIO number 28) - SW1 <-> P0.01 (Arduino GPIO number 1) - A0 <-> P0.04/AIN2 (Arduino Analog A2 - A1 <-> P0.31/AIN7 (Arduino Analog A7 - SPI_CS <-> P0.26 (Arduino GPIO number 26) - */ + /* @note RAK5005-O GPIO mapping to RAK4631 GPIO ports + RAK5005-O <-> nRF52840 + IO1 <-> P0.17 (Arduino GPIO number 17) + IO2 <-> P1.02 (Arduino GPIO number 34) + IO3 <-> P0.21 (Arduino GPIO number 21) + IO4 <-> P0.04 (Arduino GPIO number 4) + IO5 <-> P0.09 (Arduino GPIO number 9) + IO6 <-> P0.10 (Arduino GPIO number 10) + IO7 <-> P0.28 (Arduino GPIO number 28) + SW1 <-> P0.01 (Arduino GPIO number 1) + A0 <-> P0.04/AIN2 (Arduino Analog A2 + A1 <-> P0.31/AIN7 (Arduino Analog A7 + SPI_CS <-> P0.26 (Arduino GPIO number 26) + */ -// No reason not to have the RAK Wireless pin defs here too. This allows code from example RAK sketches to run without -// modification. + // No reason not to have the RAK Wireless pin defs here too. This allows code from example RAK sketches to run without + // modification. -static const uint8_t WB_IO1 = 17; // SLOT_A SLOT_B -static const uint8_t WB_IO2 = 34; // SLOT_A SLOT_B -static const uint8_t WB_IO3 = 21; // SLOT_C -static const uint8_t WB_IO4 = 4; // SLOT_C -static const uint8_t WB_IO5 = 9; // SLOT_D -static const uint8_t WB_IO6 = 10; // SLOT_D -static const uint8_t WB_SW1 = 33; // IO_SLOT -static const uint8_t WB_A0 = 5; // IO_SLOT -static const uint8_t WB_A1 = 31; // IO_SLOT -static const uint8_t WB_I2C1_SDA = 13; // SENSOR_SLOT IO_SLOT -static const uint8_t WB_I2C1_SCL = 14; // SENSOR_SLOT IO_SLOT -static const uint8_t WB_I2C2_SDA = 24; // IO_SLOT -static const uint8_t WB_I2C2_SCL = 25; // IO_SLOT -static const uint8_t WB_SPI_CS = 26; // IO_SLOT -static const uint8_t WB_SPI_CLK = 3; // IO_SLOT -static const uint8_t WB_SPI_MISO = 29; // IO_SLOT -static const uint8_t WB_SPI_MOSI = 30; // IO_SLOT + static const uint8_t WB_IO1 = 17; // SLOT_A SLOT_B + static const uint8_t WB_IO2 = 34; // SLOT_A SLOT_B + static const uint8_t WB_IO3 = 21; // SLOT_C + // static const uint8_t WB_IO4 = 4; // SLOT_C <- already defined above (ln. 94) + // static const uint8_t WB_IO5 = 9; // SLOT_D <- already defined above (ln. 93) + static const uint8_t WB_IO6 = 10; // SLOT_D + static const uint8_t WB_SW1 = 33; // IO_SLOT + static const uint8_t WB_A0 = 5; // IO_SLOT + static const uint8_t WB_A1 = 31; // IO_SLOT + static const uint8_t WB_I2C1_SDA = 13; // SENSOR_SLOT IO_SLOT + static const uint8_t WB_I2C1_SCL = 14; // SENSOR_SLOT IO_SLOT + static const uint8_t WB_I2C2_SDA = 24; // IO_SLOT + static const uint8_t WB_I2C2_SCL = 25; // IO_SLOT + static const uint8_t WB_SPI_CS = 26; // IO_SLOT + static const uint8_t WB_SPI_CLK = 3; // IO_SLOT + static const uint8_t WB_SPI_MISO = 29; // IO_SLOT + static const uint8_t WB_SPI_MOSI = 30; // IO_SLOT -// RAK4630 LoRa module + // RAK4630 LoRa module -/* Setup of the SX1262 LoRa module ( https://docs.rakwireless.com/Product-Categories/WisBlock/RAK4631/Datasheet/ ) + /* Setup of the SX1262 LoRa module ( https://docs.rakwireless.com/Product-Categories/WisBlock/RAK4631/Datasheet/ ) -P1.10 NSS SPI NSS (Arduino GPIO number 42) -P1.11 SCK SPI CLK (Arduino GPIO number 43) -P1.12 MOSI SPI MOSI (Arduino GPIO number 44) -P1.13 MISO SPI MISO (Arduino GPIO number 45) -P1.14 BUSY BUSY signal (Arduino GPIO number 46) -P1.15 DIO1 DIO1 event interrupt (Arduino GPIO number 47) -P1.06 NRESET NRESET manual reset of the SX1262 (Arduino GPIO number 38) + P1.10 NSS SPI NSS (Arduino GPIO number 42) + P1.11 SCK SPI CLK (Arduino GPIO number 43) + P1.12 MOSI SPI MOSI (Arduino GPIO number 44) + P1.13 MISO SPI MISO (Arduino GPIO number 45) + P1.14 BUSY BUSY signal (Arduino GPIO number 46) + P1.15 DIO1 DIO1 event interrupt (Arduino GPIO number 47) + P1.06 NRESET NRESET manual reset of the SX1262 (Arduino GPIO number 38) -Important for successful SX1262 initialization: + Important for successful SX1262 initialization: -* Setup DIO2 to control the antenna switch -* Setup DIO3 to control the TCXO power supply -* Setup the SX1262 to use it's DCDC regulator and not the LDO -* RAK4630 schematics show GPIO P1.07 connected to the antenna switch, but it should not be initialized, as DIO2 will do the -control of the antenna switch + * Setup DIO2 to control the antenna switch + * Setup DIO3 to control the TCXO power supply + * Setup the SX1262 to use it's DCDC regulator and not the LDO + * RAK4630 schematics show GPIO P1.07 connected to the antenna switch, but it should not be initialized, as DIO2 will do the + control of the antenna switch -SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG + SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG -*/ + */ #define USE_SX1262 #define SX126X_CS (42) From ab0d76f45f1f1c93d6f92d20e377890d0926b690 Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Wed, 7 May 2025 08:09:44 -0600 Subject: [PATCH 25/38] working out trunk formatting.. --- .vscode/settings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 3ad7fbac0..81deca8f9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,7 +6,7 @@ "files.trimFinalNewlines": false, "cmake.configureOnOpen": false, "[cpp]": { - "editor.defaultFormatter": "ms-vscode.cpptools" + "editor.defaultFormatter": "trunk.io" }, "[powershell]": { "editor.defaultFormatter": "ms-vscode.powershell" From 2b8c791ddf9128c821dac1caba251fe846d28357 Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Sun, 18 May 2025 19:13:13 -0600 Subject: [PATCH 26/38] wip . corrections to other build variants --- src/modules/Telemetry/EnvironmentTelemetry.cpp | 8 ++++---- src/modules/Telemetry/Sensor/RAK12035Sensor.cpp | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index cbbb834df..389b8cb91 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -94,7 +94,7 @@ SHTC3Sensor shtc3Sensor; NullSensor shtc3Sensor; #endif -#if __has_include() && defined(RAK_4631) +#if __has_include("RAK12035_SoilMoisture.h") && defined(RAK_4631) && RAK_4631 == 1 #include "Sensor/RAK12035Sensor.h" RAK12035Sensor rak12035Sensor; #else @@ -283,7 +283,7 @@ int32_t EnvironmentTelemetryModule::runOnce() result = rak9154Sensor.runOnce(); #endif -#if __has_include("RAK12035_SoilMoisture.h") && defined(RAK_4631) +#if __has_include("RAK12035_SoilMoisture.h") && defined(RAK_4631) && RAK_4631 == 1 if (rak12035Sensor.hasSensor()) { result = rak12035Sensor.runOnce(); @@ -678,7 +678,7 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m valid = valid && rak9154Sensor.getMetrics(m); hasSensor = true; #endif -#if __has_include() && defined(RAK_4631) // Not really needed, but may as well just skip at a lower level it if no library or not a RAK_4631 +#if __has_include("RAK12035_SoilMoisture.h") && defined(RAK_4631) && RAK_4631 == 1 // Not really needed, but may as well just skip at a lower level it if no library or not a RAK_4631 if (rak12035Sensor.hasSensor()) { valid = valid && rak12035Sensor.getMetrics(m); @@ -938,7 +938,7 @@ AdminMessageHandleResult EnvironmentTelemetryModule::handleAdminMessageForModule if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } -#if __has_include() && defined(RAK_4631) // Not really needed, but may as well just skip it at a lower level if no library or not a RAK_4631 +#if __has_include("RAK12035_SoilMoisture.h") && defined(RAK_4631) && RAK_4631 == 1 // Not really needed, but may as well just skip it at a lower level if no library or not a RAK_4631 if (rak12035Sensor.hasSensor()) { result = rak12035Sensor.handleAdminMessage(mp, request, response); diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp index 25c631a74..8ac844ac8 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -1,5 +1,5 @@ #include "configuration.h" -#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && __has_include("RAK12035_SoilMoisture.h") && defined(RAK_4631) +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && __has_include("RAK12035_SoilMoisture.h") && defined(RAK_4631) && RAK_4631 == 1 #include "../mesh/generated/meshtastic/telemetry.pb.h" #include "RAK12035Sensor.h" @@ -110,6 +110,20 @@ bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement) measurement->variant.environment_metrics.soil_temperature = (float)(temp / 10); measurement->variant.environment_metrics.soil_moisture = moisture; + // TODO:: remove this once the clients are updated to use the new proto + // temp code to get the values to the gui. will remove this once at least one of the clients is updated to use the new proto + // if (!measurement->variant.environment_metrics.has_temperature && measurement->variant.environment_metrics.temperature == 0) + // { + // measurement->variant.environment_metrics.has_temperature = true; + // measurement->variant.environment_metrics.temperature = measurement->variant.environment_metrics.soil_temperature; + // } + + // if (!measurement->variant.environment_metrics.has_relative_humidity && measurement->variant.environment_metrics.relative_humidity == 0) + // { + // measurement->variant.environment_metrics.has_relative_humidity = true; + // measurement->variant.environment_metrics.relative_humidity = measurement->variant.environment_metrics.soil_moisture; + // } + return true; } #endif From 8c9988e4aa67d044f4ee014a892a1e16cc5bd35b Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Sun, 18 May 2025 19:21:09 -0600 Subject: [PATCH 27/38] . --- protobufs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobufs b/protobufs index d8b709aa5..76f806e1b 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit d8b709aa5da85959a80a06a6624761678a96f9c0 +Subproject commit 76f806e1bb1e2a7b157a14fadd095775f63db5e4 From 85aa74c3852834c31e23982c6c98228a71dc6f68 Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Wed, 28 May 2025 08:41:25 -0600 Subject: [PATCH 28/38] protobuffs? --- protobufs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobufs b/protobufs index 76f806e1b..06572741d 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 76f806e1bb1e2a7b157a14fadd095775f63db5e4 +Subproject commit 06572741de59e16be9d205aa8ea0423cb00d17e2 From 3eed6345a083ab904096d67e7e7d465e8164d262 Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Wed, 28 May 2025 08:43:26 -0600 Subject: [PATCH 29/38] protobufs? --- protobufs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobufs b/protobufs index 76f806e1b..06572741d 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 76f806e1bb1e2a7b157a14fadd095775f63db5e4 +Subproject commit 06572741de59e16be9d205aa8ea0423cb00d17e2 From 5875c8dbc9156c3c0488e9836e48b2264506628b Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 28 May 2025 09:44:01 -0500 Subject: [PATCH 30/38] Update protobufs ref --- protobufs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobufs b/protobufs index 06572741d..24c7a3d28 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 06572741de59e16be9d205aa8ea0423cb00d17e2 +Subproject commit 24c7a3d287a4bd269ce191827e5dabd8ce8f57a7 From 3689b86ab37df121b37e1acb6848fdf992be78e0 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 28 May 2025 11:51:14 -0500 Subject: [PATCH 31/38] Protobufs ref --- protobufs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobufs b/protobufs index 06572741d..24c7a3d28 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 06572741de59e16be9d205aa8ea0423cb00d17e2 +Subproject commit 24c7a3d287a4bd269ce191827e5dabd8ce8f57a7 From a9c0654b447a742d154c610da0de558436fbbf14 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 28 May 2025 11:51:59 -0500 Subject: [PATCH 32/38] Trunk --- .../Telemetry/EnvironmentTelemetry.cpp | 308 ++++++------------ 1 file changed, 104 insertions(+), 204 deletions(-) diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 52737f909..1e78b04f0 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -192,8 +192,7 @@ IndicatorSensor indicatorSensor; int32_t EnvironmentTelemetryModule::runOnce() { - if (sleepOnNextExecution == true) - { + if (sleepOnNextExecution == true) { sleepOnNextExecution = false; uint32_t nightyNightMs = Default::getConfiguredOrDefaultMs(moduleConfig.telemetry.environment_update_interval, default_telemetry_broadcast_interval_secs); @@ -212,19 +211,16 @@ int32_t EnvironmentTelemetryModule::runOnce() // moduleConfig.telemetry.environment_update_interval = 15; if (!(moduleConfig.telemetry.environment_measurement_enabled || moduleConfig.telemetry.environment_screen_enabled || - ENVIRONMENTAL_TELEMETRY_MODULE_ENABLE)) - { + ENVIRONMENTAL_TELEMETRY_MODULE_ENABLE)) { // If this module is not enabled, and the user doesn't want the display screen don't waste any OSThread time on it return disable(); } - if (firstTime) - { + if (firstTime) { // This is the first time the OSThread library has called this function, so do some setup firstTime = 0; - if (moduleConfig.telemetry.environment_measurement_enabled || ENVIRONMENTAL_TELEMETRY_MODULE_ENABLE) - { + if (moduleConfig.telemetry.environment_measurement_enabled || ENVIRONMENTAL_TELEMETRY_MODULE_ENABLE) { LOG_INFO("Environment Telemetry: init"); #ifdef SENSECAP_INDICATOR result = indicatorSensor.runOnce(); @@ -286,15 +282,14 @@ int32_t EnvironmentTelemetryModule::runOnce() result = cgRadSens.runOnce(); if (pct2075Sensor.hasSensor()) result = pct2075Sensor.runOnce(); - // this only works on the wismesh hub with the solar option. This is not an I2C sensor, so we don't need the - // sensormap here. + // this only works on the wismesh hub with the solar option. This is not an I2C sensor, so we don't need the + // sensormap here. #ifdef HAS_RAKPROT result = rak9154Sensor.runOnce(); #endif #if __has_include("RAK12035_SoilMoisture.h") && defined(RAK_4631) && RAK_4631 == 1 - if (rak12035Sensor.hasSensor()) - { + if (rak12035Sensor.hasSensor()) { result = rak12035Sensor.runOnce(); } #endif @@ -303,16 +298,11 @@ int32_t EnvironmentTelemetryModule::runOnce() // it's possible to have this module enabled, only for displaying values on the screen. // therefore, we should only enable the sensor loop if measurement is also enabled return result == UINT32_MAX ? disable() : setStartDelay(); - } - else - { + } else { // if we somehow got to a second run of this module with measurement disabled, then just wait forever - if (!moduleConfig.telemetry.environment_measurement_enabled && !ENVIRONMENTAL_TELEMETRY_MODULE_ENABLE) - { + if (!moduleConfig.telemetry.environment_measurement_enabled && !ENVIRONMENTAL_TELEMETRY_MODULE_ENABLE) { return disable(); - } - else - { + } else { #if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR_EXTERNAL if (bme680Sensor.hasSensor()) result = bme680Sensor.runTrigger(); @@ -324,14 +314,11 @@ int32_t EnvironmentTelemetryModule::runOnce() moduleConfig.telemetry.environment_update_interval, default_telemetry_broadcast_interval_secs, numOnlineNodes))) && airTime->isTxAllowedChannelUtil(config.device.role != meshtastic_Config_DeviceConfig_Role_SENSOR) && - airTime->isTxAllowedAirUtil()) - { + airTime->isTxAllowedAirUtil()) { sendTelemetry(); lastSentToMesh = millis(); - } - else if (((lastSentToPhone == 0) || !Throttle::isWithinTimespanMs(lastSentToPhone, sendToPhoneIntervalMs)) && - (service->isToPhoneQueueEmpty())) - { + } else if (((lastSentToPhone == 0) || !Throttle::isWithinTimespanMs(lastSentToPhone, sendToPhoneIntervalMs)) && + (service->isToPhoneQueueEmpty())) { // Just send to phone when it's not our time to send to mesh yet // Only send while queue is empty (phone assumed connected) sendTelemetry(NODENUM_BROADCAST, true); @@ -351,8 +338,7 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt display->setTextAlignment(TEXT_ALIGN_LEFT); display->setFont(FONT_SMALL); - if (lastMeasurementPacket == nullptr) - { + if (lastMeasurementPacket == nullptr) { // If there's no valid packet, display "Environment" display->drawString(x, y, "Environment"); display->drawString(x, y += _fontHeight(FONT_SMALL), "No measurement"); @@ -365,8 +351,7 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt const char *lastSender = getSenderShortName(*lastMeasurementPacket); const meshtastic_Data &p = lastMeasurementPacket->decoded; - if (!pb_decode_from_bytes(p.payload.bytes, p.payload.size, &meshtastic_Telemetry_msg, &lastMeasurement)) - { + if (!pb_decode_from_bytes(p.payload.bytes, p.payload.size, &meshtastic_Telemetry_msg, &lastMeasurement)) { display->drawString(x, y, "Measurement Error"); LOG_ERROR("Unable to decode last packet"); return; @@ -380,11 +365,9 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt int sensorCount = 0; if (lastMeasurement.variant.environment_metrics.has_temperature || - lastMeasurement.variant.environment_metrics.has_relative_humidity) - { + lastMeasurement.variant.environment_metrics.has_relative_humidity) { String last_temp = String(lastMeasurement.variant.environment_metrics.temperature, 0) + "°C"; - if (moduleConfig.telemetry.environment_display_fahrenheit) - { + if (moduleConfig.telemetry.environment_display_fahrenheit) { last_temp = String(UnitConversions::CelsiusToFahrenheit(lastMeasurement.variant.environment_metrics.temperature), 0) + "°F"; } @@ -393,45 +376,37 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt "Temp/Hum: " + last_temp + " / " + String(lastMeasurement.variant.environment_metrics.relative_humidity, 0) + "%"; } - if (lastMeasurement.variant.environment_metrics.barometric_pressure != 0) - { + if (lastMeasurement.variant.environment_metrics.barometric_pressure != 0) { sensorData[sensorCount++] = "Press: " + String(lastMeasurement.variant.environment_metrics.barometric_pressure, 0) + "hPA"; } - if (lastMeasurement.variant.environment_metrics.voltage != 0) - { + if (lastMeasurement.variant.environment_metrics.voltage != 0) { sensorData[sensorCount++] = "Volt/Cur: " + String(lastMeasurement.variant.environment_metrics.voltage, 0) + "V / " + String(lastMeasurement.variant.environment_metrics.current, 0) + "mA"; } - if (lastMeasurement.variant.environment_metrics.iaq != 0) - { + if (lastMeasurement.variant.environment_metrics.iaq != 0) { sensorData[sensorCount++] = "IAQ: " + String(lastMeasurement.variant.environment_metrics.iaq); } - if (lastMeasurement.variant.environment_metrics.distance != 0) - { + if (lastMeasurement.variant.environment_metrics.distance != 0) { sensorData[sensorCount++] = "Water Level: " + String(lastMeasurement.variant.environment_metrics.distance, 0) + "mm"; } - if (lastMeasurement.variant.environment_metrics.weight != 0) - { + if (lastMeasurement.variant.environment_metrics.weight != 0) { sensorData[sensorCount++] = "Weight: " + String(lastMeasurement.variant.environment_metrics.weight, 0) + "kg"; } - if (lastMeasurement.variant.environment_metrics.radiation != 0) - { + if (lastMeasurement.variant.environment_metrics.radiation != 0) { sensorData[sensorCount++] = "Rad: " + String(lastMeasurement.variant.environment_metrics.radiation, 2) + "µR/h"; } - if (lastMeasurement.variant.environment_metrics.lux != 0) - { + if (lastMeasurement.variant.environment_metrics.lux != 0) { sensorData[sensorCount++] = "Illuminance: " + String(lastMeasurement.variant.environment_metrics.lux, 2) + "lx"; } - if (lastMeasurement.variant.environment_metrics.white_lux != 0) - { + if (lastMeasurement.variant.environment_metrics.white_lux != 0) { sensorData[sensorCount++] = "W_Lux: " + String(lastMeasurement.variant.environment_metrics.white_lux, 2) + "lx"; } @@ -442,8 +417,7 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt // Determine how many lines we can fit on display // Calculated once only: display dimensions don't change during runtime. static int maxLines = 0; - if (!maxLines) - { + if (!maxLines) { const int16_t paddingTop = _fontHeight(FONT_SMALL); // Heading text const int16_t paddingBottom = 8; // Indicator dots maxLines = (display->getHeight() - paddingTop - paddingBottom) / _fontHeight(FONT_SMALL); @@ -452,31 +426,23 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt // Draw as many lines of data as we can fit int linesToShow = min(maxLines, sensorCount); - for (int i = 0; i < linesToShow; i++) - { + for (int i = 0; i < linesToShow; i++) { int index = (scrollOffset + i) % sensorCount; display->drawString(x, y += _fontHeight(FONT_SMALL), sensorData[index]); } // Only scroll if there are more than 3 sensor data lines - if (sensorCount > 3) - { + if (sensorCount > 3) { // Update scroll offset every 5 seconds - if (millis() - lastScrollTime > 5000) - { - if (scrollingDown) - { + if (millis() - lastScrollTime > 5000) { + if (scrollingDown) { scrollOffset++; - if (scrollOffset + linesToShow >= sensorCount) - { + if (scrollOffset + linesToShow >= sensorCount) { scrollingDown = false; } - } - else - { + } else { scrollOffset--; - if (scrollOffset <= 0) - { + if (scrollOffset <= 0) { scrollingDown = true; } } @@ -487,8 +453,7 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt bool EnvironmentTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *t) { - if (t->which_variant == meshtastic_Telemetry_environment_metrics_tag) - { + if (t->which_variant == meshtastic_Telemetry_environment_metrics_tag) { #ifdef DEBUG_PORT const char *sender = getSenderShortName(mp); @@ -535,136 +500,108 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m valid = valid && t1000xSensor.getMetrics(m); hasSensor = true; #else - if (dfRobotLarkSensor.hasSensor()) - { + if (dfRobotLarkSensor.hasSensor()) { valid = valid && dfRobotLarkSensor.getMetrics(m); hasSensor = true; } - if (dfRobotGravitySensor.hasSensor()) - { + if (dfRobotGravitySensor.hasSensor()) { valid = valid && dfRobotGravitySensor.getMetrics(m); hasSensor = true; } - if (sht31Sensor.hasSensor()) - { + if (sht31Sensor.hasSensor()) { valid = valid && sht31Sensor.getMetrics(m); hasSensor = true; } - if (sht4xSensor.hasSensor()) - { + if (sht4xSensor.hasSensor()) { valid = valid && sht4xSensor.getMetrics(m); hasSensor = true; } - if (lps22hbSensor.hasSensor()) - { + if (lps22hbSensor.hasSensor()) { valid = valid && lps22hbSensor.getMetrics(m); hasSensor = true; } - if (shtc3Sensor.hasSensor()) - { + if (shtc3Sensor.hasSensor()) { valid = valid && shtc3Sensor.getMetrics(m); hasSensor = true; } - if (bmp085Sensor.hasSensor()) - { + if (bmp085Sensor.hasSensor()) { valid = valid && bmp085Sensor.getMetrics(m); hasSensor = true; } #if __has_include() - if (bmp280Sensor.hasSensor()) - { + if (bmp280Sensor.hasSensor()) { valid = valid && bmp280Sensor.getMetrics(m); hasSensor = true; } #endif - if (bme280Sensor.hasSensor()) - { + if (bme280Sensor.hasSensor()) { valid = valid && bme280Sensor.getMetrics(m); hasSensor = true; } - if (bmp3xxSensor.hasSensor()) - { + if (bmp3xxSensor.hasSensor()) { valid = valid && bmp3xxSensor.getMetrics(m); hasSensor = true; } - if (bme680Sensor.hasSensor()) - { + if (bme680Sensor.hasSensor()) { valid = valid && bme680Sensor.getMetrics(m); hasSensor = true; } - if (dps310Sensor.hasSensor()) - { + if (dps310Sensor.hasSensor()) { valid = valid && dps310Sensor.getMetrics(m); hasSensor = true; } - if (mcp9808Sensor.hasSensor()) - { + if (mcp9808Sensor.hasSensor()) { valid = valid && mcp9808Sensor.getMetrics(m); hasSensor = true; } - if (ina219Sensor.hasSensor()) - { + if (ina219Sensor.hasSensor()) { valid = valid && ina219Sensor.getMetrics(m); hasSensor = true; } - if (ina260Sensor.hasSensor()) - { + if (ina260Sensor.hasSensor()) { valid = valid && ina260Sensor.getMetrics(m); hasSensor = true; } - if (ina3221Sensor.hasSensor()) - { + if (ina3221Sensor.hasSensor()) { valid = valid && ina3221Sensor.getMetrics(m); hasSensor = true; } - if (veml7700Sensor.hasSensor()) - { + if (veml7700Sensor.hasSensor()) { valid = valid && veml7700Sensor.getMetrics(m); hasSensor = true; } - if (tsl2591Sensor.hasSensor()) - { + if (tsl2591Sensor.hasSensor()) { valid = valid && tsl2591Sensor.getMetrics(m); hasSensor = true; } - if (opt3001Sensor.hasSensor()) - { + if (opt3001Sensor.hasSensor()) { valid = valid && opt3001Sensor.getMetrics(m); hasSensor = true; } - if (mlx90632Sensor.hasSensor()) - { + if (mlx90632Sensor.hasSensor()) { valid = valid && mlx90632Sensor.getMetrics(m); hasSensor = true; } - if (rcwl9620Sensor.hasSensor()) - { + if (rcwl9620Sensor.hasSensor()) { valid = valid && rcwl9620Sensor.getMetrics(m); hasSensor = true; } - if (nau7802Sensor.hasSensor()) - { + if (nau7802Sensor.hasSensor()) { valid = valid && nau7802Sensor.getMetrics(m); hasSensor = true; } - if (aht10Sensor.hasSensor()) - { - if (!bmp280Sensor.hasSensor() && !bmp3xxSensor.hasSensor()) - { + if (aht10Sensor.hasSensor()) { + if (!bmp280Sensor.hasSensor() && !bmp3xxSensor.hasSensor()) { valid = valid && aht10Sensor.getMetrics(m); hasSensor = true; - } - else if (bmp280Sensor.hasSensor()) - { + } else if (bmp280Sensor.hasSensor()) { // prefer bmp280 temp if both sensors are present, fetch only humidity meshtastic_Telemetry m_ahtx = meshtastic_Telemetry_init_zero; LOG_INFO("AHTX0+BMP280 module detected: using temp from BMP280 and humy from AHTX0"); aht10Sensor.getMetrics(&m_ahtx); m->variant.environment_metrics.relative_humidity = m_ahtx.variant.environment_metrics.relative_humidity; m->variant.environment_metrics.has_relative_humidity = m_ahtx.variant.environment_metrics.has_relative_humidity; - } - else - { + } else { // prefer bmp3xx temp if both sensors are present, fetch only humidity meshtastic_Telemetry m_ahtx = meshtastic_Telemetry_init_zero; LOG_INFO("AHTX0+BMP3XX module detected: using temp from BMP3XX and humy from AHTX0"); @@ -673,13 +610,11 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m m->variant.environment_metrics.has_relative_humidity = m_ahtx.variant.environment_metrics.has_relative_humidity; } } - if (max17048Sensor.hasSensor()) - { + if (max17048Sensor.hasSensor()) { valid = valid && max17048Sensor.getMetrics(m); hasSensor = true; } - if (cgRadSens.hasSensor()) - { + if (cgRadSens.hasSensor()) { valid = valid && cgRadSens.getMetrics(m); hasSensor = true; } @@ -691,9 +626,10 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m valid = valid && rak9154Sensor.getMetrics(m); hasSensor = true; #endif -#if __has_include("RAK12035_SoilMoisture.h") && defined(RAK_4631) && RAK_4631 == 1 // Not really needed, but may as well just skip at a lower level it if no library or not a RAK_4631 - if (rak12035Sensor.hasSensor()) - { +#if __has_include("RAK12035_SoilMoisture.h") && defined(RAK_4631) && \ + RAK_4631 == \ + 1 // Not really needed, but may as well just skip at a lower level it if no library or not a RAK_4631 + if (rak12035Sensor.hasSensor()) { valid = valid && rak12035Sensor.getMetrics(m); hasSensor = true; } @@ -704,33 +640,25 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m meshtastic_MeshPacket *EnvironmentTelemetryModule::allocReply() { - if (currentRequest) - { + if (currentRequest) { auto req = *currentRequest; const auto &p = req.decoded; meshtastic_Telemetry scratch; meshtastic_Telemetry *decoded = NULL; memset(&scratch, 0, sizeof(scratch)); - if (pb_decode_from_bytes(p.payload.bytes, p.payload.size, &meshtastic_Telemetry_msg, &scratch)) - { + if (pb_decode_from_bytes(p.payload.bytes, p.payload.size, &meshtastic_Telemetry_msg, &scratch)) { decoded = &scratch; - } - else - { + } else { LOG_ERROR("Error decoding EnvironmentTelemetry module!"); return NULL; } // Check for a request for environment metrics - if (decoded->which_variant == meshtastic_Telemetry_environment_metrics_tag) - { + if (decoded->which_variant == meshtastic_Telemetry_environment_metrics_tag) { meshtastic_Telemetry m = meshtastic_Telemetry_init_zero; - if (getEnvironmentTelemetry(&m)) - { + if (getEnvironmentTelemetry(&m)) { LOG_INFO("Environment telemetry reply to request"); return allocDataProtobuf(m); - } - else - { + } else { return NULL; } } @@ -744,11 +672,9 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) m.which_variant = meshtastic_Telemetry_environment_metrics_tag; m.time = getTime(); #ifdef T1000X_SENSOR_EN - if (t1000xSensor.getMetrics(&m)) - { + if (t1000xSensor.getMetrics(&m)) { #else - if (getEnvironmentTelemetry(&m)) - { + if (getEnvironmentTelemetry(&m)) { #endif LOG_INFO("Send: barometric_pressure=%f, current=%f, gas_resistance=%f, relative_humidity=%f, temperature=%f", m.variant.environment_metrics.barometric_pressure, m.variant.environment_metrics.current, @@ -779,13 +705,10 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) packetPool.release(lastMeasurementPacket); lastMeasurementPacket = packetPool.allocCopy(*p); - if (phoneOnly) - { + if (phoneOnly) { LOG_INFO("Send packet to phone"); service->sendToPhone(p); - } - else - { + } else { LOG_INFO("Send packet to mesh"); service->sendToMesh(p, RX_SRC_LOCAL, true); @@ -814,153 +737,130 @@ AdminMessageHandleResult EnvironmentTelemetryModule::handleAdminMessageForModule { AdminMessageHandleResult result = AdminMessageHandleResult::NOT_HANDLED; #if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR_EXTERNAL - if (dfRobotLarkSensor.hasSensor()) - { + if (dfRobotLarkSensor.hasSensor()) { result = dfRobotLarkSensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (dfRobotGravitySensor.hasSensor()) - { + if (dfRobotGravitySensor.hasSensor()) { result = dfRobotGravitySensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (sht31Sensor.hasSensor()) - { + if (sht31Sensor.hasSensor()) { result = sht31Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (lps22hbSensor.hasSensor()) - { + if (lps22hbSensor.hasSensor()) { result = lps22hbSensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (shtc3Sensor.hasSensor()) - { + if (shtc3Sensor.hasSensor()) { result = shtc3Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (bmp085Sensor.hasSensor()) - { + if (bmp085Sensor.hasSensor()) { result = bmp085Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (bmp280Sensor.hasSensor()) - { + if (bmp280Sensor.hasSensor()) { result = bmp280Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (bme280Sensor.hasSensor()) - { + if (bme280Sensor.hasSensor()) { result = bme280Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (bmp3xxSensor.hasSensor()) - { + if (bmp3xxSensor.hasSensor()) { result = bmp3xxSensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (bme680Sensor.hasSensor()) - { + if (bme680Sensor.hasSensor()) { result = bme680Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (dps310Sensor.hasSensor()) - { + if (dps310Sensor.hasSensor()) { result = dps310Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (mcp9808Sensor.hasSensor()) - { + if (mcp9808Sensor.hasSensor()) { result = mcp9808Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (ina219Sensor.hasSensor()) - { + if (ina219Sensor.hasSensor()) { result = ina219Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (ina260Sensor.hasSensor()) - { + if (ina260Sensor.hasSensor()) { result = ina260Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (ina3221Sensor.hasSensor()) - { + if (ina3221Sensor.hasSensor()) { result = ina3221Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (veml7700Sensor.hasSensor()) - { + if (veml7700Sensor.hasSensor()) { result = veml7700Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (tsl2591Sensor.hasSensor()) - { + if (tsl2591Sensor.hasSensor()) { result = tsl2591Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (opt3001Sensor.hasSensor()) - { + if (opt3001Sensor.hasSensor()) { result = opt3001Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (mlx90632Sensor.hasSensor()) - { + if (mlx90632Sensor.hasSensor()) { result = mlx90632Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (rcwl9620Sensor.hasSensor()) - { + if (rcwl9620Sensor.hasSensor()) { result = rcwl9620Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (nau7802Sensor.hasSensor()) - { + if (nau7802Sensor.hasSensor()) { result = nau7802Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (aht10Sensor.hasSensor()) - { + if (aht10Sensor.hasSensor()) { result = aht10Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (max17048Sensor.hasSensor()) - { + if (max17048Sensor.hasSensor()) { result = max17048Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } - if (cgRadSens.hasSensor()) - { + if (cgRadSens.hasSensor()) { result = cgRadSens.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } -#if __has_include("RAK12035_SoilMoisture.h") && defined(RAK_4631) && RAK_4631 == 1 // Not really needed, but may as well just skip it at a lower level if no library or not a RAK_4631 - if (rak12035Sensor.hasSensor()) - { +#if __has_include("RAK12035_SoilMoisture.h") && defined(RAK_4631) && \ + RAK_4631 == \ + 1 // Not really needed, but may as well just skip it at a lower level if no library or not a RAK_4631 + if (rak12035Sensor.hasSensor()) { result = rak12035Sensor.handleAdminMessage(mp, request, response); if (result != AdminMessageHandleResult::NOT_HANDLED) return result; From 14f6c751f36c51db435c3528160bb8411135cd28 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 28 May 2025 11:53:22 -0500 Subject: [PATCH 33/38] Update RAK12035Sensor.cpp --- src/modules/Telemetry/Sensor/RAK12035Sensor.cpp | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp index 8ac844ac8..76005fb83 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -110,20 +110,6 @@ bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement) measurement->variant.environment_metrics.soil_temperature = (float)(temp / 10); measurement->variant.environment_metrics.soil_moisture = moisture; - // TODO:: remove this once the clients are updated to use the new proto - // temp code to get the values to the gui. will remove this once at least one of the clients is updated to use the new proto - // if (!measurement->variant.environment_metrics.has_temperature && measurement->variant.environment_metrics.temperature == 0) - // { - // measurement->variant.environment_metrics.has_temperature = true; - // measurement->variant.environment_metrics.temperature = measurement->variant.environment_metrics.soil_temperature; - // } - - // if (!measurement->variant.environment_metrics.has_relative_humidity && measurement->variant.environment_metrics.relative_humidity == 0) - // { - // measurement->variant.environment_metrics.has_relative_humidity = true; - // measurement->variant.environment_metrics.relative_humidity = measurement->variant.environment_metrics.soil_moisture; - // } - return true; } #endif From 0ed4fdf81d4b14c0349e50ed54fbc998af15cf32 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 28 May 2025 12:22:41 -0500 Subject: [PATCH 34/38] Fmt --- .../Telemetry/Sensor/RAK12035Sensor.cpp | 22 +-- src/modules/Telemetry/Sensor/RAK12035Sensor.h | 16 +- variants/rak_wismeshtap/variant.h | 141 +++++++++--------- 3 files changed, 86 insertions(+), 93 deletions(-) diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp index 76005fb83..cae34c80c 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -10,8 +10,7 @@ int32_t RAK12035Sensor::runOnce() { LOG_INFO("Init sensor: %s", sensorName); - if (!hasSensor()) - { + if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } @@ -25,13 +24,10 @@ int32_t RAK12035Sensor::runOnce() sensor.get_sensor_version(&data); LOG_INFO("Sensor1 Firmware version: %i", data); - if (data != 0) - { + if (data != 0) { LOG_INFO("RAK12035Sensor Init Succeed"); status = true; - } - else - { + } else { LOG_ERROR("RAK12035Sensor Init Failed"); status = false; } @@ -53,8 +49,7 @@ void RAK12035Sensor::setup() sensor.get_dry_cal(&zero_val); sensor.get_wet_cal(&hundred_val); delay(200); - if (zero_val == 0 || zero_val <= hundred_val) - { + if (zero_val == 0 || zero_val <= hundred_val) { LOG_INFO("Dry calibration value is %d", zero_val); LOG_INFO("Wet calibration value is %d", hundred_val); LOG_INFO("This does not make sense. You can recalibrate this sensor using the calibration sketch included here: " @@ -64,8 +59,7 @@ void RAK12035Sensor::setup() sensor.get_dry_cal(&zero_val); LOG_INFO("Dry calibration reset complete. New value is %d", zero_val); } - if (hundred_val == 0 || hundred_val >= zero_val) - { + if (hundred_val == 0 || hundred_val >= zero_val) { LOG_INFO("Dry calibration value is %d", zero_val); LOG_INFO("Wet calibration value is %d", hundred_val); LOG_INFO("This does not make sense. You can recalibrate this sensor using the calibration sketch included here: " @@ -86,7 +80,8 @@ bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement) // TODO:: read and send metrics for up to 2 additional soil monitors if present. // -- how to do this.. this could get a little complex.. // ie - 1> we combine them into an average and send that, 2> we send them as separate metrics - // ^-- these scenarios would require different handling of the metrics in the receiving end and maybe a setting in the device ui and an additional proto for that? + // ^-- these scenarios would require different handling of the metrics in the receiving end and maybe a setting in the + // device ui and an additional proto for that? measurement->variant.environment_metrics.has_soil_temperature = true; measurement->variant.environment_metrics.has_soil_moisture = true; @@ -102,8 +97,7 @@ bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement) delay(200); sensor.sensor_sleep(); - if (success == false) - { + if (success == false) { LOG_ERROR("Failed to read sensor data"); return false; } diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.h b/src/modules/Telemetry/Sensor/RAK12035Sensor.h index 40c9e6598..2c32a840d 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.h +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.h @@ -14,15 +14,15 @@ class RAK12035Sensor : public TelemetrySensor { -private: - RAK12035 sensor; + private: + RAK12035 sensor; -protected: - virtual void setup() override; + protected: + virtual void setup() override; -public: - RAK12035Sensor(); - virtual int32_t runOnce() override; - virtual bool getMetrics(meshtastic_Telemetry *measurement) override; + public: + RAK12035Sensor(); + virtual int32_t runOnce() override; + virtual bool getMetrics(meshtastic_Telemetry *measurement) override; }; #endif diff --git a/variants/rak_wismeshtap/variant.h b/variants/rak_wismeshtap/variant.h index 77ba7f555..f961ddf6e 100644 --- a/variants/rak_wismeshtap/variant.h +++ b/variants/rak_wismeshtap/variant.h @@ -34,8 +34,7 @@ #include "WVariant.h" #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif // __cplusplus // Number of pins defined in PinDescription array @@ -56,9 +55,9 @@ extern "C" #define LED_STATE_ON 1 // State when LED is litted - /* - * Buttons - */ +/* + * Buttons + */ #define PIN_BUTTON1 9 // Pin for button on E-ink button module or IO expansion such as the RAK14014 or RAK14015 TFT modules #define BUTTON_NEED_PULLUP @@ -78,14 +77,14 @@ extern "C" #define PIN_A6 (0xff) #define PIN_A7 (0xff) - static const uint8_t A0 = PIN_A0; - static const uint8_t A1 = PIN_A1; - static const uint8_t A2 = PIN_A2; - static const uint8_t A3 = PIN_A3; - static const uint8_t A4 = PIN_A4; - static const uint8_t A5 = PIN_A5; - static const uint8_t A6 = PIN_A6; - static const uint8_t A7 = PIN_A7; +static const uint8_t A0 = PIN_A0; +static const uint8_t A1 = PIN_A1; +static const uint8_t A2 = PIN_A2; +static const uint8_t A3 = PIN_A3; +static const uint8_t A4 = PIN_A4; +static const uint8_t A5 = PIN_A5; +static const uint8_t A6 = PIN_A6; +static const uint8_t A7 = PIN_A7; #define ADC_RESOLUTION 14 // Other pins @@ -95,7 +94,7 @@ extern "C" #define WB_IO4 (4) #define PIN_NFC2 (10) - static const uint8_t AREF = PIN_AREF; +static const uint8_t AREF = PIN_AREF; /* * Serial interfaces @@ -120,14 +119,14 @@ extern "C" #define PIN_SPI1_MOSI (30) // (0 + 30) #define PIN_SPI1_SCK (3) // (0 + 3) - static const uint8_t SS = 42; - static const uint8_t MOSI = PIN_SPI_MOSI; - static const uint8_t MISO = PIN_SPI_MISO; - static const uint8_t SCK = PIN_SPI_SCK; +static const uint8_t SS = 42; +static const uint8_t MOSI = PIN_SPI_MOSI; +static const uint8_t MISO = PIN_SPI_MISO; +static const uint8_t SCK = PIN_SPI_SCK; - /* - * eink display pins - */ +/* + * eink display pins + */ #define PIN_EINK_CS (0 + 26) #define PIN_EINK_BUSY (0 + 4) @@ -161,65 +160,65 @@ extern "C" #define EXTERNAL_FLASH_DEVICES IS25LP080D #define EXTERNAL_FLASH_USE_QSPI - /* @note RAK5005-O GPIO mapping to RAK4631 GPIO ports - RAK5005-O <-> nRF52840 - IO1 <-> P0.17 (Arduino GPIO number 17) - IO2 <-> P1.02 (Arduino GPIO number 34) - IO3 <-> P0.21 (Arduino GPIO number 21) - IO4 <-> P0.04 (Arduino GPIO number 4) - IO5 <-> P0.09 (Arduino GPIO number 9) - IO6 <-> P0.10 (Arduino GPIO number 10) - IO7 <-> P0.28 (Arduino GPIO number 28) - SW1 <-> P0.01 (Arduino GPIO number 1) - A0 <-> P0.04/AIN2 (Arduino Analog A2 - A1 <-> P0.31/AIN7 (Arduino Analog A7 - SPI_CS <-> P0.26 (Arduino GPIO number 26) - */ +/* @note RAK5005-O GPIO mapping to RAK4631 GPIO ports + RAK5005-O <-> nRF52840 + IO1 <-> P0.17 (Arduino GPIO number 17) + IO2 <-> P1.02 (Arduino GPIO number 34) + IO3 <-> P0.21 (Arduino GPIO number 21) + IO4 <-> P0.04 (Arduino GPIO number 4) + IO5 <-> P0.09 (Arduino GPIO number 9) + IO6 <-> P0.10 (Arduino GPIO number 10) + IO7 <-> P0.28 (Arduino GPIO number 28) + SW1 <-> P0.01 (Arduino GPIO number 1) + A0 <-> P0.04/AIN2 (Arduino Analog A2 + A1 <-> P0.31/AIN7 (Arduino Analog A7 + SPI_CS <-> P0.26 (Arduino GPIO number 26) + */ - // No reason not to have the RAK Wireless pin defs here too. This allows code from example RAK sketches to run without - // modification. +// No reason not to have the RAK Wireless pin defs here too. This allows code from example RAK sketches to run without +// modification. - static const uint8_t WB_IO1 = 17; // SLOT_A SLOT_B - static const uint8_t WB_IO2 = 34; // SLOT_A SLOT_B - static const uint8_t WB_IO3 = 21; // SLOT_C - // static const uint8_t WB_IO4 = 4; // SLOT_C <- already defined above (ln. 94) - // static const uint8_t WB_IO5 = 9; // SLOT_D <- already defined above (ln. 93) - static const uint8_t WB_IO6 = 10; // SLOT_D - static const uint8_t WB_SW1 = 33; // IO_SLOT - static const uint8_t WB_A0 = 5; // IO_SLOT - static const uint8_t WB_A1 = 31; // IO_SLOT - static const uint8_t WB_I2C1_SDA = 13; // SENSOR_SLOT IO_SLOT - static const uint8_t WB_I2C1_SCL = 14; // SENSOR_SLOT IO_SLOT - static const uint8_t WB_I2C2_SDA = 24; // IO_SLOT - static const uint8_t WB_I2C2_SCL = 25; // IO_SLOT - static const uint8_t WB_SPI_CS = 26; // IO_SLOT - static const uint8_t WB_SPI_CLK = 3; // IO_SLOT - static const uint8_t WB_SPI_MISO = 29; // IO_SLOT - static const uint8_t WB_SPI_MOSI = 30; // IO_SLOT +static const uint8_t WB_IO1 = 17; // SLOT_A SLOT_B +static const uint8_t WB_IO2 = 34; // SLOT_A SLOT_B +static const uint8_t WB_IO3 = 21; // SLOT_C +// static const uint8_t WB_IO4 = 4; // SLOT_C <- already defined above (ln. 94) +// static const uint8_t WB_IO5 = 9; // SLOT_D <- already defined above (ln. 93) +static const uint8_t WB_IO6 = 10; // SLOT_D +static const uint8_t WB_SW1 = 33; // IO_SLOT +static const uint8_t WB_A0 = 5; // IO_SLOT +static const uint8_t WB_A1 = 31; // IO_SLOT +static const uint8_t WB_I2C1_SDA = 13; // SENSOR_SLOT IO_SLOT +static const uint8_t WB_I2C1_SCL = 14; // SENSOR_SLOT IO_SLOT +static const uint8_t WB_I2C2_SDA = 24; // IO_SLOT +static const uint8_t WB_I2C2_SCL = 25; // IO_SLOT +static const uint8_t WB_SPI_CS = 26; // IO_SLOT +static const uint8_t WB_SPI_CLK = 3; // IO_SLOT +static const uint8_t WB_SPI_MISO = 29; // IO_SLOT +static const uint8_t WB_SPI_MOSI = 30; // IO_SLOT - // RAK4630 LoRa module +// RAK4630 LoRa module - /* Setup of the SX1262 LoRa module ( https://docs.rakwireless.com/Product-Categories/WisBlock/RAK4631/Datasheet/ ) +/* Setup of the SX1262 LoRa module ( https://docs.rakwireless.com/Product-Categories/WisBlock/RAK4631/Datasheet/ ) - P1.10 NSS SPI NSS (Arduino GPIO number 42) - P1.11 SCK SPI CLK (Arduino GPIO number 43) - P1.12 MOSI SPI MOSI (Arduino GPIO number 44) - P1.13 MISO SPI MISO (Arduino GPIO number 45) - P1.14 BUSY BUSY signal (Arduino GPIO number 46) - P1.15 DIO1 DIO1 event interrupt (Arduino GPIO number 47) - P1.06 NRESET NRESET manual reset of the SX1262 (Arduino GPIO number 38) +P1.10 NSS SPI NSS (Arduino GPIO number 42) +P1.11 SCK SPI CLK (Arduino GPIO number 43) +P1.12 MOSI SPI MOSI (Arduino GPIO number 44) +P1.13 MISO SPI MISO (Arduino GPIO number 45) +P1.14 BUSY BUSY signal (Arduino GPIO number 46) +P1.15 DIO1 DIO1 event interrupt (Arduino GPIO number 47) +P1.06 NRESET NRESET manual reset of the SX1262 (Arduino GPIO number 38) - Important for successful SX1262 initialization: +Important for successful SX1262 initialization: - * Setup DIO2 to control the antenna switch - * Setup DIO3 to control the TCXO power supply - * Setup the SX1262 to use it's DCDC regulator and not the LDO - * RAK4630 schematics show GPIO P1.07 connected to the antenna switch, but it should not be initialized, as DIO2 will do the - control of the antenna switch +* Setup DIO2 to control the antenna switch +* Setup DIO3 to control the TCXO power supply +* Setup the SX1262 to use it's DCDC regulator and not the LDO +* RAK4630 schematics show GPIO P1.07 connected to the antenna switch, but it should not be initialized, as DIO2 will do the +control of the antenna switch - SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG +SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG - */ +*/ #define USE_SX1262 #define SX126X_CS (42) From 5756cab277753afbc559c0e9a1faae58fb83b7aa Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Wed, 28 May 2025 16:10:19 -0600 Subject: [PATCH 35/38] comment changes --- src/modules/Telemetry/Sensor/RAK12035Sensor.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp index cae34c80c..e2461a918 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -8,8 +8,7 @@ RAK12035Sensor::RAK12035Sensor() : TelemetrySensor(meshtastic_TelemetrySensorTyp int32_t RAK12035Sensor::runOnce() { - - LOG_INFO("Init sensor: %s", sensorName); + string msg = "Init sensor: %s \n", sensorName; if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } @@ -22,10 +21,8 @@ int32_t RAK12035Sensor::runOnce() // Get sensor firmware version uint8_t data = 0; sensor.get_sensor_version(&data); - LOG_INFO("Sensor1 Firmware version: %i", data); - if (data != 0) { - LOG_INFO("RAK12035Sensor Init Succeed"); + msg += format("RAK12035Sensor Init Succeed \nSensor1 Firmware version: %i", data); status = true; } else { LOG_ERROR("RAK12035Sensor Init Failed"); @@ -93,7 +90,7 @@ bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement) delay(200); success = sensor.get_sensor_moisture(&moisture); delay(200); - success = sensor.get_sensor_temperature(&temp); + success &= sensor.get_sensor_temperature(&temp); delay(200); sensor.sensor_sleep(); From a6737f515d7e760633fa39d56f74332fe47d14a1 Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Wed, 28 May 2025 17:10:12 -0600 Subject: [PATCH 36/38] dumb mistakes... resolved, actually built and tested.. all good.. --- src/modules/Telemetry/Sensor/RAK12035Sensor.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp index e2461a918..847b1c260 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -8,7 +8,6 @@ RAK12035Sensor::RAK12035Sensor() : TelemetrySensor(meshtastic_TelemetrySensorTyp int32_t RAK12035Sensor::runOnce() { - string msg = "Init sensor: %s \n", sensorName; if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } @@ -22,9 +21,11 @@ int32_t RAK12035Sensor::runOnce() uint8_t data = 0; sensor.get_sensor_version(&data); if (data != 0) { - msg += format("RAK12035Sensor Init Succeed \nSensor1 Firmware version: %i", data); + LOG_INFO("Init sensor: %s", sensorName); + LOG_INFO("RAK12035Sensor Init Succeed \nSensor1 Firmware version: %i", data, sensorName); status = true; } else { + LOG_INFO("Init sensor: %s \n", sensorName); LOG_ERROR("RAK12035Sensor Init Failed"); status = false; } From d53ffa090aa25656003737092f5929d9be36566f Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 28 May 2025 19:13:59 -0500 Subject: [PATCH 37/38] Update src/modules/Telemetry/Sensor/RAK12035Sensor.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/modules/Telemetry/Sensor/RAK12035Sensor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp index 847b1c260..ce47957b3 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -22,7 +22,7 @@ int32_t RAK12035Sensor::runOnce() sensor.get_sensor_version(&data); if (data != 0) { LOG_INFO("Init sensor: %s", sensorName); - LOG_INFO("RAK12035Sensor Init Succeed \nSensor1 Firmware version: %i", data, sensorName); + LOG_INFO("RAK12035Sensor Init Succeed \nSensor1 Firmware version: %i, Sensor Name: %s", data, sensorName); status = true; } else { LOG_INFO("Init sensor: %s \n", sensorName); From 5bc95ebc5558c617e0cb36e5024377e4fb588590 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 28 May 2025 19:14:19 -0500 Subject: [PATCH 38/38] Update src/modules/Telemetry/Sensor/RAK12035Sensor.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/modules/Telemetry/Sensor/RAK12035Sensor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp index ce47957b3..e4fa473bd 100644 --- a/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp +++ b/src/modules/Telemetry/Sensor/RAK12035Sensor.cpp @@ -99,7 +99,7 @@ bool RAK12035Sensor::getMetrics(meshtastic_Telemetry *measurement) LOG_ERROR("Failed to read sensor data"); return false; } - measurement->variant.environment_metrics.soil_temperature = (float)(temp / 10); + measurement->variant.environment_metrics.soil_temperature = ((float)temp / 10.0f); measurement->variant.environment_metrics.soil_moisture = moisture; return true;