From 8ea77697b165d01ec1d144e6dd36827e5b9d03f4 Mon Sep 17 00:00:00 2001 From: Jake-B Date: Fri, 22 Nov 2024 07:38:29 -0500 Subject: [PATCH 1/9] Support for the ClimateGuard RadSens Geiger-Muller tube --- .gitmodules | 2 +- bin/regen-protos.sh | 2 +- protobufs | 2 +- src/configuration.h | 1 + src/detect/ScanI2C.h | 3 +- src/detect/ScanI2CTwoWire.cpp | 10 +++ src/main.cpp | 1 + src/mesh/generated/meshtastic/telemetry.pb.h | 23 ++++--- .../Telemetry/EnvironmentTelemetry.cpp | 22 +++++++ .../Telemetry/Sensor/CGRadSensSensor.cpp | 65 +++++++++++++++++++ .../Telemetry/Sensor/CGRadSensSensor.h | 26 ++++++++ 11 files changed, 145 insertions(+), 12 deletions(-) create mode 100644 src/modules/Telemetry/Sensor/CGRadSensSensor.cpp create mode 100644 src/modules/Telemetry/Sensor/CGRadSensSensor.h diff --git a/.gitmodules b/.gitmodules index 7c54ad5139..37a22f27ad 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "protobufs"] path = protobufs - url = https://github.com/meshtastic/protobufs.git + url = https://github.com/jake-b/meshtastic-protobufs.git [submodule "meshtestic"] path = meshtestic url = https://github.com/meshtastic/meshTestic diff --git a/bin/regen-protos.sh b/bin/regen-protos.sh index 12546bfdc5..8a41b7de03 100755 --- a/bin/regen-protos.sh +++ b/bin/regen-protos.sh @@ -8,4 +8,4 @@ echo "prebuilt binaries for your computer into nanopb-0.4.9" # the nanopb tool seems to require that the .options file be in the current directory! cd protobufs -../nanopb-0.4.9/generator-bin/protoc --experimental_allow_proto3_optional "--nanopb_out=-S.cpp -v:../src/mesh/generated/" -I=../protobufs meshtastic/*.proto +protoc --experimental_allow_proto3_optional "--nanopb_out=-S.cpp -v:../src/mesh/generated/" -I=../protobufs meshtastic/*.proto diff --git a/protobufs b/protobufs index af7521c3a7..bc484d8063 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit af7521c3a77d56eb7a64efae5637a311ac33f76d +Subproject commit bc484d8063585770cf97e98c5a332ccb27c57c20 diff --git a/src/configuration.h b/src/configuration.h index 15912be3f7..2e81557b17 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -148,6 +148,7 @@ along with this program. If not, see . #define NAU7802_ADDR 0x2A #define MAX30102_ADDR 0x57 #define MLX90614_ADDR_DEF 0x5A +#define CGRADSENS_ADDR 0x66 // ----------------------------------------------------------------------------- // ACCELEROMETER diff --git a/src/detect/ScanI2C.h b/src/detect/ScanI2C.h index 8591b8433c..f4516458bc 100644 --- a/src/detect/ScanI2C.h +++ b/src/detect/ScanI2C.h @@ -63,7 +63,8 @@ class ScanI2C ICM20948, MAX30102, TPS65233, - MPR121KB + MPR121KB, + CGRADSENS } DeviceType; // typedef uint8_t DeviceAddress; diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 2413c44c9a..c3a5b87a90 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -479,6 +479,16 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) } break; + case CGRADSENS_ADDR: + LOG_INFO("Looking for ClimateGuard RadSense Geiger-Muller Sensor"); + registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x00), 1); + if (registerValue == 0x7D) { + type = CGRADSENS; + LOG_INFO("ClimateGuard RadSense Geiger-Muller Sensor found"); + break; + } + break; + default: LOG_INFO("Device found at address 0x%x was not able to be enumerated", addr.address); } diff --git a/src/main.cpp b/src/main.cpp index 97a64a378d..df18dae98f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -614,6 +614,7 @@ void setup() SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::DFROBOT_LARK, meshtastic_TelemetrySensorType_DFROBOT_LARK) SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::ICM20948, meshtastic_TelemetrySensorType_ICM20948) SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::MAX30102, meshtastic_TelemetrySensorType_MAX30102) + SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::CGRADSENS, meshtastic_TelemetrySensorType_RADSENS) i2cScanner.reset(); #endif diff --git a/src/mesh/generated/meshtastic/telemetry.pb.h b/src/mesh/generated/meshtastic/telemetry.pb.h index 309c01dc7e..7980a84f77 100644 --- a/src/mesh/generated/meshtastic/telemetry.pb.h +++ b/src/mesh/generated/meshtastic/telemetry.pb.h @@ -77,7 +77,9 @@ typedef enum _meshtastic_TelemetrySensorType { /* MLX90614 non-contact IR temperature sensor */ meshtastic_TelemetrySensorType_MLX90614 = 31, /* SCD40/SCD41 CO2, humidity, temperature sensor */ - meshtastic_TelemetrySensorType_SCD4X = 32 + meshtastic_TelemetrySensorType_SCD4X = 32, + /* RADSENS, radiation, geiger-muller tube */ + meshtastic_TelemetrySensorType_RADSENS = 33 } meshtastic_TelemetrySensorType; /* Struct definitions */ @@ -155,6 +157,9 @@ typedef struct _meshtastic_EnvironmentMetrics { /* Wind lull in m/s */ bool has_wind_lull; float wind_lull; + /* Radiation in micro roentgen/hr */ + bool has_radiation; + float radiation; } meshtastic_EnvironmentMetrics; /* Power Metrics (voltage / current / etc) */ @@ -299,8 +304,8 @@ extern "C" { /* Helper constants for enums */ #define _meshtastic_TelemetrySensorType_MIN meshtastic_TelemetrySensorType_SENSOR_UNSET -#define _meshtastic_TelemetrySensorType_MAX meshtastic_TelemetrySensorType_SCD4X -#define _meshtastic_TelemetrySensorType_ARRAYSIZE ((meshtastic_TelemetrySensorType)(meshtastic_TelemetrySensorType_SCD4X+1)) +#define _meshtastic_TelemetrySensorType_MAX meshtastic_TelemetrySensorType_RADSENS +#define _meshtastic_TelemetrySensorType_ARRAYSIZE ((meshtastic_TelemetrySensorType)(meshtastic_TelemetrySensorType_RADSENS+1)) @@ -313,7 +318,7 @@ extern "C" { /* Initializer values for message structs */ #define meshtastic_DeviceMetrics_init_default {false, 0, false, 0, false, 0, false, 0, false, 0} -#define meshtastic_EnvironmentMetrics_init_default {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} +#define meshtastic_EnvironmentMetrics_init_default {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} #define meshtastic_PowerMetrics_init_default {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} #define meshtastic_AirQualityMetrics_init_default {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} #define meshtastic_LocalStats_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} @@ -321,7 +326,7 @@ extern "C" { #define meshtastic_Telemetry_init_default {0, 0, {meshtastic_DeviceMetrics_init_default}} #define meshtastic_Nau7802Config_init_default {0, 0} #define meshtastic_DeviceMetrics_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0} -#define meshtastic_EnvironmentMetrics_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} +#define meshtastic_EnvironmentMetrics_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} #define meshtastic_PowerMetrics_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} #define meshtastic_AirQualityMetrics_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} #define meshtastic_LocalStats_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} @@ -352,6 +357,7 @@ extern "C" { #define meshtastic_EnvironmentMetrics_weight_tag 15 #define meshtastic_EnvironmentMetrics_wind_gust_tag 16 #define meshtastic_EnvironmentMetrics_wind_lull_tag 17 +#define meshtastic_EnvironmentMetrics_radiation_tag 18 #define meshtastic_PowerMetrics_ch1_voltage_tag 1 #define meshtastic_PowerMetrics_ch1_current_tag 2 #define meshtastic_PowerMetrics_ch2_voltage_tag 3 @@ -422,7 +428,8 @@ X(a, STATIC, OPTIONAL, UINT32, wind_direction, 13) \ X(a, STATIC, OPTIONAL, FLOAT, wind_speed, 14) \ X(a, STATIC, OPTIONAL, FLOAT, weight, 15) \ X(a, STATIC, OPTIONAL, FLOAT, wind_gust, 16) \ -X(a, STATIC, OPTIONAL, FLOAT, wind_lull, 17) +X(a, STATIC, OPTIONAL, FLOAT, wind_lull, 17) \ +X(a, STATIC, OPTIONAL, FLOAT, radiation, 18) #define meshtastic_EnvironmentMetrics_CALLBACK NULL #define meshtastic_EnvironmentMetrics_DEFAULT NULL @@ -521,12 +528,12 @@ extern const pb_msgdesc_t meshtastic_Nau7802Config_msg; #define MESHTASTIC_MESHTASTIC_TELEMETRY_PB_H_MAX_SIZE meshtastic_Telemetry_size #define meshtastic_AirQualityMetrics_size 78 #define meshtastic_DeviceMetrics_size 27 -#define meshtastic_EnvironmentMetrics_size 85 +#define meshtastic_EnvironmentMetrics_size 91 #define meshtastic_HealthMetrics_size 11 #define meshtastic_LocalStats_size 60 #define meshtastic_Nau7802Config_size 16 #define meshtastic_PowerMetrics_size 30 -#define meshtastic_Telemetry_size 92 +#define meshtastic_Telemetry_size 98 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 4ef68d4b7c..defad40491 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -38,6 +38,7 @@ #include "Sensor/T1000xSensor.h" #include "Sensor/TSL2591Sensor.h" #include "Sensor/VEML7700Sensor.h" +#include "Sensor/CGRadSensSensor.h" BMP085Sensor bmp085Sensor; BMP280Sensor bmp280Sensor; @@ -60,6 +61,7 @@ BMP3XXSensor bmp3xxSensor; #ifdef T1000X_SENSOR_EN T1000xSensor t1000xSensor; #endif +CGRadSensSensor cgRadSens; #define FAILED_STATE_SENSOR_READ_MULTIPLIER 10 #define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true @@ -147,6 +149,8 @@ int32_t EnvironmentTelemetryModule::runOnce() result = nau7802Sensor.runOnce(); if (max17048Sensor.hasSensor()) result = max17048Sensor.runOnce(); + if (cgRadSens.hasSensor()) + result = cgRadSens.runOnce(); #endif } return result; @@ -243,6 +247,11 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt if (lastMeasurement.variant.environment_metrics.weight != 0) display->drawString(x, y += _fontHeight(FONT_SMALL), "Weight: " + String(lastMeasurement.variant.environment_metrics.weight, 0) + "kg"); + + if (lastMeasurement.variant.environment_metrics.radiation != 0) + display->drawString(x, y += _fontHeight(FONT_SMALL), + "Radiation: " + String(lastMeasurement.variant.environment_metrics.radiation, 0) + "µR/h"); + } bool EnvironmentTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *t) @@ -263,6 +272,8 @@ bool EnvironmentTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPac t->variant.environment_metrics.wind_speed, t->variant.environment_metrics.wind_direction, t->variant.environment_metrics.weight); + LOG_INFO("(Received from %s): radiation=%fµR/h", sender, t->variant.environment_metrics.radiation); + #endif // release previous packet before occupying a new spot if (lastMeasurementPacket != nullptr) @@ -390,6 +401,10 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m valid = valid && max17048Sensor.getMetrics(m); hasSensor = true; } + if (cgRadSens.hasSensor()) { + valid = valid && cgRadSens.getMetrics(m); + hasSensor = true; + } #endif return valid && hasSensor; @@ -443,6 +458,8 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) LOG_INFO("Send: wind speed=%fm/s, direction=%d degrees, weight=%fkg", m.variant.environment_metrics.wind_speed, m.variant.environment_metrics.wind_direction, m.variant.environment_metrics.weight); + LOG_INFO("Send: radiation=%fµR/h", m.variant.environment_metrics.radiation); + sensor_read_error_count = 0; meshtastic_MeshPacket *p = allocDataProtobuf(m); @@ -585,6 +602,11 @@ AdminMessageHandleResult EnvironmentTelemetryModule::handleAdminMessageForModule if (result != AdminMessageHandleResult::NOT_HANDLED) return result; } + if (cgRadSens.hasSensor()) { + result = cgRadSens.handleAdminMessage(mp, request, response); + if (result != AdminMessageHandleResult::NOT_HANDLED) + return result; + } return result; } diff --git a/src/modules/Telemetry/Sensor/CGRadSensSensor.cpp b/src/modules/Telemetry/Sensor/CGRadSensSensor.cpp new file mode 100644 index 0000000000..6f94ffe1fb --- /dev/null +++ b/src/modules/Telemetry/Sensor/CGRadSensSensor.cpp @@ -0,0 +1,65 @@ +#include "configuration.h" + +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR + +#include "../mesh/generated/meshtastic/telemetry.pb.h" +#include "CGRadSensSensor.h" +#include "TelemetrySensor.h" +#include +#include + +CGRadSensSensor::CGRadSensSensor() : TelemetrySensor(meshtastic_TelemetrySensorType_RADSENS, "RadSens") {} + +int32_t CGRadSensSensor::runOnce() +{ + LOG_INFO("Init sensor: %s", sensorName); + if (!hasSensor()) { + return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; + } + + status = true; + begin(nodeTelemetrySensorsMap[sensorType].second, nodeTelemetrySensorsMap[sensorType].first); + + return initI2CSensor(); +} + +void CGRadSensSensor::setup() {} + +void CGRadSensSensor::begin(TwoWire *wire, uint8_t addr) +{ + _wire = wire; + _addr = addr; + _wire->begin(); +} + +float CGRadSensSensor::getStaticRadiation() +{ + uint32_t data; + _wire->beginTransmission(_addr); // Transfer data to addr. + _wire->write(0x06); // Radiation intensity (static period T = 500 sec) + if (_wire->endTransmission() == 0) { + if (_wire->requestFrom(_addr, (uint8_t)3)) { ; // Request 3 bytes + data = _wire->read(); + data <<= 8; + data |= _wire->read(); + data <<= 8; + data |= _wire->read(); + + float microRadPerHr = float(data) / 10.0; + return microRadPerHr; + } + } + return -1.0; +} + +bool CGRadSensSensor::getMetrics(meshtastic_Telemetry *measurement) +{ + LOG_INFO("getMetrics: ClimateGuard RadSense Geiger-Muller Sensor"); + measurement->variant.environment_metrics.has_radiation = true; + + LOG_DEBUG("CGRADSENS getMetrics"); + measurement->variant.environment_metrics.radiation = getStaticRadiation(); + + return true; +} +#endif \ No newline at end of file diff --git a/src/modules/Telemetry/Sensor/CGRadSensSensor.h b/src/modules/Telemetry/Sensor/CGRadSensSensor.h new file mode 100644 index 0000000000..aabd550416 --- /dev/null +++ b/src/modules/Telemetry/Sensor/CGRadSensSensor.h @@ -0,0 +1,26 @@ +#include "configuration.h" + +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR + +#include "../mesh/generated/meshtastic/telemetry.pb.h" +#include "TelemetrySensor.h" +#include + +class CGRadSensSensor : public TelemetrySensor +{ + private: + uint8_t _addr = 0x66; + TwoWire *_wire = &Wire; + + protected: + virtual void setup() override; + void begin(TwoWire *wire = &Wire, uint8_t addr = 0x66); + float getStaticRadiation(); + + public: + CGRadSensSensor(); + virtual int32_t runOnce() override; + virtual bool getMetrics(meshtastic_Telemetry *measurement) override; +}; + +#endif \ No newline at end of file From ba097318adbf84b85d7d795d42703e73b1be0b4c Mon Sep 17 00:00:00 2001 From: Jake-B Date: Fri, 22 Nov 2024 18:02:11 -0500 Subject: [PATCH 2/9] Clean-up and comments --- protobufs | 2 +- src/detect/ScanI2CTwoWire.cpp | 4 ++-- src/mesh/generated/meshtastic/telemetry.pb.h | 4 ++-- .../Telemetry/EnvironmentTelemetry.cpp | 20 ++++++++++--------- .../Telemetry/Sensor/CGRadSensSensor.cpp | 11 +++++++++- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/protobufs b/protobufs index bc484d8063..1f0c500315 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit bc484d8063585770cf97e98c5a332ccb27c57c20 +Subproject commit 1f0c50031516ce96dc0fbd10a82683d3c741a735 diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index c3a5b87a90..55f13c5a0d 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -480,11 +480,11 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) break; case CGRADSENS_ADDR: - LOG_INFO("Looking for ClimateGuard RadSense Geiger-Muller Sensor"); + // Register 0x00 of the RadSens sensor contains is product identifier 0x7D registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x00), 1); if (registerValue == 0x7D) { type = CGRADSENS; - LOG_INFO("ClimateGuard RadSense Geiger-Muller Sensor found"); + LOG_INFO("ClimateGuard RadSens Geiger-Muller Sensor found"); break; } break; diff --git a/src/mesh/generated/meshtastic/telemetry.pb.h b/src/mesh/generated/meshtastic/telemetry.pb.h index 7980a84f77..874eef60fe 100644 --- a/src/mesh/generated/meshtastic/telemetry.pb.h +++ b/src/mesh/generated/meshtastic/telemetry.pb.h @@ -78,7 +78,7 @@ typedef enum _meshtastic_TelemetrySensorType { meshtastic_TelemetrySensorType_MLX90614 = 31, /* SCD40/SCD41 CO2, humidity, temperature sensor */ meshtastic_TelemetrySensorType_SCD4X = 32, - /* RADSENS, radiation, geiger-muller tube */ + /* ClimateGuard RadSens, radiation, Geiger-Muller Tube */ meshtastic_TelemetrySensorType_RADSENS = 33 } meshtastic_TelemetrySensorType; @@ -157,7 +157,7 @@ typedef struct _meshtastic_EnvironmentMetrics { /* Wind lull in m/s */ bool has_wind_lull; float wind_lull; - /* Radiation in micro roentgen/hr */ + /* Radiation in µR/h */ bool has_radiation; float radiation; } meshtastic_EnvironmentMetrics; diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index defad40491..a57dcfb5e0 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -214,16 +214,18 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt // Display "Env. From: ..." on its own display->drawString(x, y, "Env. From: " + String(lastSender) + "(" + String(agoSecs) + "s)"); - String last_temp = String(lastMeasurement.variant.environment_metrics.temperature, 0) + "°C"; - if (moduleConfig.telemetry.environment_display_fahrenheit) { - last_temp = - String(UnitConversions::CelsiusToFahrenheit(lastMeasurement.variant.environment_metrics.temperature), 0) + "°F"; - } + if (lastMeasurement.variant.environment_metrics.has_temperature || lastMeasurement.variant.environment_metrics.has_relative_humidity) { + String last_temp = String(lastMeasurement.variant.environment_metrics.temperature, 0) + "°C"; + if (moduleConfig.telemetry.environment_display_fahrenheit) { + last_temp = + String(UnitConversions::CelsiusToFahrenheit(lastMeasurement.variant.environment_metrics.temperature), 0) + "°F"; + } - // Continue with the remaining details - display->drawString(x, y += _fontHeight(FONT_SMALL), - "Temp/Hum: " + last_temp + " / " + - String(lastMeasurement.variant.environment_metrics.relative_humidity, 0) + "%"); + // Continue with the remaining details + display->drawString(x, y += _fontHeight(FONT_SMALL), + "Temp/Hum: " + last_temp + " / " + + String(lastMeasurement.variant.environment_metrics.relative_humidity, 0) + "%"); + } if (lastMeasurement.variant.environment_metrics.barometric_pressure != 0) { display->drawString(x, y += _fontHeight(FONT_SMALL), diff --git a/src/modules/Telemetry/Sensor/CGRadSensSensor.cpp b/src/modules/Telemetry/Sensor/CGRadSensSensor.cpp index 6f94ffe1fb..4804973c9f 100644 --- a/src/modules/Telemetry/Sensor/CGRadSensSensor.cpp +++ b/src/modules/Telemetry/Sensor/CGRadSensSensor.cpp @@ -1,3 +1,7 @@ +/* + * Support for the ClimateGuard RadSens Dosimeter + * A fun and educational sensor for Meshtastic; not for saftey critical applications. + */ #include "configuration.h" #if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR @@ -12,6 +16,7 @@ CGRadSensSensor::CGRadSensSensor() : TelemetrySensor(meshtastic_TelemetrySensorT int32_t CGRadSensSensor::runOnce() { + // Initialize the sensor following the same pattern as RCWL9620Sensor LOG_INFO("Init sensor: %s", sensorName); if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; @@ -27,6 +32,7 @@ void CGRadSensSensor::setup() {} void CGRadSensSensor::begin(TwoWire *wire, uint8_t addr) { + // Store the Wire and address to the sensor following the same pattern as RCWL9620Sensor _wire = wire; _addr = addr; _wire->begin(); @@ -34,6 +40,7 @@ void CGRadSensSensor::begin(TwoWire *wire, uint8_t addr) float CGRadSensSensor::getStaticRadiation() { + // Read a register, following the same pattern as the RCWL9620Sensor uint32_t data; _wire->beginTransmission(_addr); // Transfer data to addr. _wire->write(0x06); // Radiation intensity (static period T = 500 sec) @@ -45,6 +52,8 @@ float CGRadSensSensor::getStaticRadiation() data <<= 8; data |= _wire->read(); + // As per the data sheet for the RadSens + // Register 0x06 contains the reading in 0.1 * μR / h float microRadPerHr = float(data) / 10.0; return microRadPerHr; } @@ -54,7 +63,7 @@ float CGRadSensSensor::getStaticRadiation() bool CGRadSensSensor::getMetrics(meshtastic_Telemetry *measurement) { - LOG_INFO("getMetrics: ClimateGuard RadSense Geiger-Muller Sensor"); + // Store the meansurement in the the appropriate fields of the protobuf measurement->variant.environment_metrics.has_radiation = true; LOG_DEBUG("CGRADSENS getMetrics"); From 3a3fbc4ce869ecfd4a5556255ec443700aa02a3b Mon Sep 17 00:00:00 2001 From: Jake-B Date: Fri, 22 Nov 2024 18:06:37 -0500 Subject: [PATCH 3/9] Support for the ClimateGuard RadSens Geiger-Muller tube --- .gitmodules | 2 +- bin/regen-protos.sh | 2 +- src/modules/Telemetry/Sensor/CGRadSensSensor.cpp | 2 +- src/modules/Telemetry/Sensor/CGRadSensSensor.h | 4 ++++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index 37a22f27ad..7c54ad5139 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "protobufs"] path = protobufs - url = https://github.com/jake-b/meshtastic-protobufs.git + url = https://github.com/meshtastic/protobufs.git [submodule "meshtestic"] path = meshtestic url = https://github.com/meshtastic/meshTestic diff --git a/bin/regen-protos.sh b/bin/regen-protos.sh index 8a41b7de03..12546bfdc5 100755 --- a/bin/regen-protos.sh +++ b/bin/regen-protos.sh @@ -8,4 +8,4 @@ echo "prebuilt binaries for your computer into nanopb-0.4.9" # the nanopb tool seems to require that the .options file be in the current directory! cd protobufs -protoc --experimental_allow_proto3_optional "--nanopb_out=-S.cpp -v:../src/mesh/generated/" -I=../protobufs meshtastic/*.proto +../nanopb-0.4.9/generator-bin/protoc --experimental_allow_proto3_optional "--nanopb_out=-S.cpp -v:../src/mesh/generated/" -I=../protobufs meshtastic/*.proto diff --git a/src/modules/Telemetry/Sensor/CGRadSensSensor.cpp b/src/modules/Telemetry/Sensor/CGRadSensSensor.cpp index 4804973c9f..00d23ac62b 100644 --- a/src/modules/Telemetry/Sensor/CGRadSensSensor.cpp +++ b/src/modules/Telemetry/Sensor/CGRadSensSensor.cpp @@ -1,6 +1,6 @@ /* * Support for the ClimateGuard RadSens Dosimeter - * A fun and educational sensor for Meshtastic; not for saftey critical applications. + * A fun and educational sensor for Meshtastic; not for safety critical applications. */ #include "configuration.h" diff --git a/src/modules/Telemetry/Sensor/CGRadSensSensor.h b/src/modules/Telemetry/Sensor/CGRadSensSensor.h index aabd550416..3b15a19a21 100644 --- a/src/modules/Telemetry/Sensor/CGRadSensSensor.h +++ b/src/modules/Telemetry/Sensor/CGRadSensSensor.h @@ -1,3 +1,7 @@ +/* + * Support for the ClimateGuard RadSens Dosimeter + * A fun and educational sensor for Meshtastic; not for safety critical applications. + */ #include "configuration.h" #if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR From 0a6fff8178481ae68473be85d464f957b42788a0 Mon Sep 17 00:00:00 2001 From: Jake-B Date: Fri, 22 Nov 2024 18:31:42 -0500 Subject: [PATCH 4/9] Added 2 decimal places to uR/h on display page --- 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 a57dcfb5e0..751f722d8c 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -252,7 +252,7 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt if (lastMeasurement.variant.environment_metrics.radiation != 0) display->drawString(x, y += _fontHeight(FONT_SMALL), - "Radiation: " + String(lastMeasurement.variant.environment_metrics.radiation, 0) + "µR/h"); + "Radiation: " + String(lastMeasurement.variant.environment_metrics.radiation, 2) + "µR/h"); } From cb4218cc4c4383d61c1659c85fa5921a6a5e1c99 Mon Sep 17 00:00:00 2001 From: Jake-B Date: Sat, 23 Nov 2024 08:24:03 -0500 Subject: [PATCH 5/9] Code formatting fixes --- src/modules/Telemetry/EnvironmentTelemetry.cpp | 6 +++--- src/modules/Telemetry/Sensor/CGRadSensSensor.cpp | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 751f722d8c..428fdf6605 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -25,6 +25,7 @@ #include "Sensor/BMP085Sensor.h" #include "Sensor/BMP280Sensor.h" #include "Sensor/BMP3XXSensor.h" +#include "Sensor/CGRadSensSensor.h" #include "Sensor/DFRobotLarkSensor.h" #include "Sensor/LPS22HBSensor.h" #include "Sensor/MCP9808Sensor.h" @@ -38,7 +39,6 @@ #include "Sensor/T1000xSensor.h" #include "Sensor/TSL2591Sensor.h" #include "Sensor/VEML7700Sensor.h" -#include "Sensor/CGRadSensSensor.h" BMP085Sensor bmp085Sensor; BMP280Sensor bmp280Sensor; @@ -214,7 +214,8 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt // Display "Env. From: ..." on its own display->drawString(x, y, "Env. From: " + String(lastSender) + "(" + String(agoSecs) + "s)"); - if (lastMeasurement.variant.environment_metrics.has_temperature || lastMeasurement.variant.environment_metrics.has_relative_humidity) { + if (lastMeasurement.variant.environment_metrics.has_temperature || + lastMeasurement.variant.environment_metrics.has_relative_humidity) { String last_temp = String(lastMeasurement.variant.environment_metrics.temperature, 0) + "°C"; if (moduleConfig.telemetry.environment_display_fahrenheit) { last_temp = @@ -253,7 +254,6 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt if (lastMeasurement.variant.environment_metrics.radiation != 0) display->drawString(x, y += _fontHeight(FONT_SMALL), "Radiation: " + String(lastMeasurement.variant.environment_metrics.radiation, 2) + "µR/h"); - } bool EnvironmentTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *t) diff --git a/src/modules/Telemetry/Sensor/CGRadSensSensor.cpp b/src/modules/Telemetry/Sensor/CGRadSensSensor.cpp index 00d23ac62b..5e69cc22f0 100644 --- a/src/modules/Telemetry/Sensor/CGRadSensSensor.cpp +++ b/src/modules/Telemetry/Sensor/CGRadSensSensor.cpp @@ -9,8 +9,8 @@ #include "../mesh/generated/meshtastic/telemetry.pb.h" #include "CGRadSensSensor.h" #include "TelemetrySensor.h" -#include #include +#include CGRadSensSensor::CGRadSensSensor() : TelemetrySensor(meshtastic_TelemetrySensorType_RADSENS, "RadSens") {} @@ -45,7 +45,8 @@ float CGRadSensSensor::getStaticRadiation() _wire->beginTransmission(_addr); // Transfer data to addr. _wire->write(0x06); // Radiation intensity (static period T = 500 sec) if (_wire->endTransmission() == 0) { - if (_wire->requestFrom(_addr, (uint8_t)3)) { ; // Request 3 bytes + if (_wire->requestFrom(_addr, (uint8_t)3)) { + ; // Request 3 bytes data = _wire->read(); data <<= 8; data |= _wire->read(); @@ -56,7 +57,7 @@ float CGRadSensSensor::getStaticRadiation() // Register 0x06 contains the reading in 0.1 * μR / h float microRadPerHr = float(data) / 10.0; return microRadPerHr; - } + } } return -1.0; } From c1235c78f026ad7190ba452b756b6c89edeadce7 Mon Sep 17 00:00:00 2001 From: Jake-B Date: Sat, 23 Nov 2024 08:35:03 -0500 Subject: [PATCH 6/9] Added `radiation` to MeshPacketSerializer --- src/serialization/MeshPacketSerializer.cpp | 1 + src/serialization/MeshPacketSerializer_nRF52.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/serialization/MeshPacketSerializer.cpp b/src/serialization/MeshPacketSerializer.cpp index 05a98f7a66..b4603186b5 100644 --- a/src/serialization/MeshPacketSerializer.cpp +++ b/src/serialization/MeshPacketSerializer.cpp @@ -78,6 +78,7 @@ std::string MeshPacketSerializer::JsonSerialize(const meshtastic_MeshPacket *mp, msgPayload["wind_direction"] = new JSONValue((uint)decoded->variant.environment_metrics.wind_direction); msgPayload["wind_gust"] = new JSONValue(decoded->variant.environment_metrics.wind_gust); msgPayload["wind_lull"] = new JSONValue(decoded->variant.environment_metrics.wind_lull); + msgPayload["radiation"] = new JSONValue(decoded->variant.environment_metrics.radiation); } else if (decoded->which_variant == meshtastic_Telemetry_air_quality_metrics_tag) { msgPayload["pm10"] = new JSONValue((unsigned int)decoded->variant.air_quality_metrics.pm10_standard); msgPayload["pm25"] = new JSONValue((unsigned int)decoded->variant.air_quality_metrics.pm25_standard); diff --git a/src/serialization/MeshPacketSerializer_nRF52.cpp b/src/serialization/MeshPacketSerializer_nRF52.cpp index 15b8b1a34a..89ecddfad3 100644 --- a/src/serialization/MeshPacketSerializer_nRF52.cpp +++ b/src/serialization/MeshPacketSerializer_nRF52.cpp @@ -77,6 +77,7 @@ std::string MeshPacketSerializer::JsonSerialize(const meshtastic_MeshPacket *mp, jsonObj["payload"]["wind_direction"] = (uint)decoded->variant.environment_metrics.wind_direction; jsonObj["payload"]["wind_gust"] = decoded->variant.environment_metrics.wind_gust; jsonObj["payload"]["wind_lull"] = decoded->variant.environment_metrics.wind_lull; + jsonObj["payload"]["radiation"] = decoded->variant.environment_metrics.radiation; } else if (decoded->which_variant == meshtastic_Telemetry_air_quality_metrics_tag) { jsonObj["payload"]["pm10"] = (unsigned int)decoded->variant.air_quality_metrics.pm10_standard; jsonObj["payload"]["pm25"] = (unsigned int)decoded->variant.air_quality_metrics.pm25_standard; From af8d4588b5df29058af4a3fa174e6ed5d876d183 Mon Sep 17 00:00:00 2001 From: Jake-B Date: Sat, 23 Nov 2024 09:35:11 -0500 Subject: [PATCH 7/9] Revert generated file --- src/mesh/generated/meshtastic/telemetry.pb.h | 23 +++++++------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/mesh/generated/meshtastic/telemetry.pb.h b/src/mesh/generated/meshtastic/telemetry.pb.h index 874eef60fe..309c01dc7e 100644 --- a/src/mesh/generated/meshtastic/telemetry.pb.h +++ b/src/mesh/generated/meshtastic/telemetry.pb.h @@ -77,9 +77,7 @@ typedef enum _meshtastic_TelemetrySensorType { /* MLX90614 non-contact IR temperature sensor */ meshtastic_TelemetrySensorType_MLX90614 = 31, /* SCD40/SCD41 CO2, humidity, temperature sensor */ - meshtastic_TelemetrySensorType_SCD4X = 32, - /* ClimateGuard RadSens, radiation, Geiger-Muller Tube */ - meshtastic_TelemetrySensorType_RADSENS = 33 + meshtastic_TelemetrySensorType_SCD4X = 32 } meshtastic_TelemetrySensorType; /* Struct definitions */ @@ -157,9 +155,6 @@ typedef struct _meshtastic_EnvironmentMetrics { /* Wind lull in m/s */ bool has_wind_lull; float wind_lull; - /* Radiation in µR/h */ - bool has_radiation; - float radiation; } meshtastic_EnvironmentMetrics; /* Power Metrics (voltage / current / etc) */ @@ -304,8 +299,8 @@ extern "C" { /* Helper constants for enums */ #define _meshtastic_TelemetrySensorType_MIN meshtastic_TelemetrySensorType_SENSOR_UNSET -#define _meshtastic_TelemetrySensorType_MAX meshtastic_TelemetrySensorType_RADSENS -#define _meshtastic_TelemetrySensorType_ARRAYSIZE ((meshtastic_TelemetrySensorType)(meshtastic_TelemetrySensorType_RADSENS+1)) +#define _meshtastic_TelemetrySensorType_MAX meshtastic_TelemetrySensorType_SCD4X +#define _meshtastic_TelemetrySensorType_ARRAYSIZE ((meshtastic_TelemetrySensorType)(meshtastic_TelemetrySensorType_SCD4X+1)) @@ -318,7 +313,7 @@ extern "C" { /* Initializer values for message structs */ #define meshtastic_DeviceMetrics_init_default {false, 0, false, 0, false, 0, false, 0, false, 0} -#define meshtastic_EnvironmentMetrics_init_default {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} +#define meshtastic_EnvironmentMetrics_init_default {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} #define meshtastic_PowerMetrics_init_default {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} #define meshtastic_AirQualityMetrics_init_default {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} #define meshtastic_LocalStats_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} @@ -326,7 +321,7 @@ extern "C" { #define meshtastic_Telemetry_init_default {0, 0, {meshtastic_DeviceMetrics_init_default}} #define meshtastic_Nau7802Config_init_default {0, 0} #define meshtastic_DeviceMetrics_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0} -#define meshtastic_EnvironmentMetrics_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} +#define meshtastic_EnvironmentMetrics_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} #define meshtastic_PowerMetrics_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} #define meshtastic_AirQualityMetrics_init_zero {false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0, false, 0} #define meshtastic_LocalStats_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} @@ -357,7 +352,6 @@ extern "C" { #define meshtastic_EnvironmentMetrics_weight_tag 15 #define meshtastic_EnvironmentMetrics_wind_gust_tag 16 #define meshtastic_EnvironmentMetrics_wind_lull_tag 17 -#define meshtastic_EnvironmentMetrics_radiation_tag 18 #define meshtastic_PowerMetrics_ch1_voltage_tag 1 #define meshtastic_PowerMetrics_ch1_current_tag 2 #define meshtastic_PowerMetrics_ch2_voltage_tag 3 @@ -428,8 +422,7 @@ X(a, STATIC, OPTIONAL, UINT32, wind_direction, 13) \ X(a, STATIC, OPTIONAL, FLOAT, wind_speed, 14) \ X(a, STATIC, OPTIONAL, FLOAT, weight, 15) \ X(a, STATIC, OPTIONAL, FLOAT, wind_gust, 16) \ -X(a, STATIC, OPTIONAL, FLOAT, wind_lull, 17) \ -X(a, STATIC, OPTIONAL, FLOAT, radiation, 18) +X(a, STATIC, OPTIONAL, FLOAT, wind_lull, 17) #define meshtastic_EnvironmentMetrics_CALLBACK NULL #define meshtastic_EnvironmentMetrics_DEFAULT NULL @@ -528,12 +521,12 @@ extern const pb_msgdesc_t meshtastic_Nau7802Config_msg; #define MESHTASTIC_MESHTASTIC_TELEMETRY_PB_H_MAX_SIZE meshtastic_Telemetry_size #define meshtastic_AirQualityMetrics_size 78 #define meshtastic_DeviceMetrics_size 27 -#define meshtastic_EnvironmentMetrics_size 91 +#define meshtastic_EnvironmentMetrics_size 85 #define meshtastic_HealthMetrics_size 11 #define meshtastic_LocalStats_size 60 #define meshtastic_Nau7802Config_size 16 #define meshtastic_PowerMetrics_size 30 -#define meshtastic_Telemetry_size 98 +#define meshtastic_Telemetry_size 92 #ifdef __cplusplus } /* extern "C" */ From b3f45c617ffb56471bb83614ab088a16a402108c Mon Sep 17 00:00:00 2001 From: Jake-B Date: Sat, 23 Nov 2024 09:55:43 -0500 Subject: [PATCH 8/9] Revert submodule to previous commit --- protobufs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobufs b/protobufs index 1f0c500315..af7521c3a7 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 1f0c50031516ce96dc0fbd10a82683d3c741a735 +Subproject commit af7521c3a77d56eb7a64efae5637a311ac33f76d From 5ac5d850c0325d47fdc82016197ea6e5988e7805 Mon Sep 17 00:00:00 2001 From: Jake-B Date: Sat, 23 Nov 2024 09:56:24 -0500 Subject: [PATCH 9/9] Shorten display label --- 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 428fdf6605..92d964f7dd 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -253,7 +253,7 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt if (lastMeasurement.variant.environment_metrics.radiation != 0) display->drawString(x, y += _fontHeight(FONT_SMALL), - "Radiation: " + String(lastMeasurement.variant.environment_metrics.radiation, 2) + "µR/h"); + "Rad: " + String(lastMeasurement.variant.environment_metrics.radiation, 2) + "µR/h"); } bool EnvironmentTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *t)