From 2723ae6e9be95b7e924e940efe04cac393af6a44 Mon Sep 17 00:00:00 2001 From: Manuel <71137295+mverch67@users.noreply.github.com> Date: Sun, 2 Jun 2024 14:38:20 +0200 Subject: [PATCH 1/3] fix crash during reset nodedb (#4017) --- src/mesh/NodeDB.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 9473df8c51..cf576e94fe 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -444,9 +444,9 @@ void NodeDB::installDefaultChannels() void NodeDB::resetNodes() { + clearLocalPosition(); numMeshNodes = 1; std::fill(devicestate.node_db_lite.begin() + 1, devicestate.node_db_lite.end(), meshtastic_NodeInfoLite()); - clearLocalPosition(); saveDeviceStateToDisk(); if (neighborInfoModule && moduleConfig.neighbor_info.enabled) neighborInfoModule->resetNeighbors(); From 97a5abbc82c8b55edd396202bc7977a2868f5380 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sun, 2 Jun 2024 07:39:08 -0500 Subject: [PATCH 2/3] TI OPT3001 light sensor support (#4015) * TI OPT3001 light sensor support * Added register interrogation to deconflict with SHT sensors on same address --- platformio.ini | 3 +- src/configuration.h | 2 + src/detect/ScanI2C.h | 1 + src/detect/ScanI2CTwoWire.cpp | 4 ++ src/main.cpp | 1 + .../Telemetry/EnvironmentTelemetry.cpp | 8 ++++ .../Telemetry/Sensor/OPT3001Sensor.cpp | 44 +++++++++++++++++++ src/modules/Telemetry/Sensor/OPT3001Sensor.h | 17 +++++++ 8 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/modules/Telemetry/Sensor/OPT3001Sensor.cpp create mode 100644 src/modules/Telemetry/Sensor/OPT3001Sensor.h diff --git a/platformio.ini b/platformio.ini index f4306c2ea8..791c31a9b9 100644 --- a/platformio.ini +++ b/platformio.ini @@ -136,4 +136,5 @@ lib_deps = mprograms/QMC5883LCompass@^1.2.0 adafruit/Adafruit VEML7700 Library@^2.1.6 adafruit/Adafruit SHT4x Library@^1.0.4 - adafruit/Adafruit TSL2591 Library@^1.4.5 \ No newline at end of file + adafruit/Adafruit TSL2591 Library@^1.4.5 + ClosedCube OPT3001@^1.1.2 \ No newline at end of file diff --git a/src/configuration.h b/src/configuration.h index 2d0095e22e..b102746b39 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -132,6 +132,8 @@ along with this program. If not, see . #define RCWL9620_ADDR 0x57 #define VEML7700_ADDR 0x10 #define TSL25911_ADDR 0x29 +#define OPT3001_ADDRESS 0x45 +#define OPT3001_ADDRESS_ALT 0x44 // ----------------------------------------------------------------------------- // ACCELEROMETER diff --git a/src/detect/ScanI2C.h b/src/detect/ScanI2C.h index a2ccb18a81..917335a142 100644 --- a/src/detect/ScanI2C.h +++ b/src/detect/ScanI2C.h @@ -46,6 +46,7 @@ class ScanI2C RCWL9620, NCP5623, TSL2591, + OPT3001, AHT10, } DeviceType; diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index d2a6e7848a..4597a70cad 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -302,6 +302,9 @@ void ScanI2CTwoWire::scanPort(I2CPort port) if (registerValue == 0x11a2) { type = SHT4X; LOG_INFO("SHT4X sensor found\n"); + } else if (getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x7E), 2) == 0x5449) { + type = OPT3001; + LOG_INFO("OPT3001 light sensor found\n"); } else { type = SHT31; LOG_INFO("SHT31 sensor found\n"); @@ -343,6 +346,7 @@ void ScanI2CTwoWire::scanPort(I2CPort port) SCAN_SIMPLE_CASE(TCA9555_ADDR, TCA9555, "TCA9555 I2C expander found\n"); SCAN_SIMPLE_CASE(VEML7700_ADDR, VEML7700, "VEML7700 light sensor found\n"); SCAN_SIMPLE_CASE(TSL25911_ADDR, TSL2591, "TSL2591 light sensor found\n"); + SCAN_SIMPLE_CASE(OPT3001_ADDRESS, OPT3001, "OPT3001 light sensor found\n"); default: LOG_INFO("Device found at address 0x%x was not able to be enumerated\n", addr.address); diff --git a/src/main.cpp b/src/main.cpp index d9b4d84abf..8d870feba1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -534,6 +534,7 @@ void setup() SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::RCWL9620, meshtastic_TelemetrySensorType_RCWL9620) SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::VEML7700, meshtastic_TelemetrySensorType_VEML7700) SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::TSL2591, meshtastic_TelemetrySensorType_TSL25911FN) + SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::OPT3001, meshtastic_TelemetrySensorType_OPT3001) SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::SHT4X, meshtastic_TelemetrySensorType_SHT4X) SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::AHT10, meshtastic_TelemetrySensorType_AHT10) diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 5ecfe73289..1d45d3ee99 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -25,6 +25,7 @@ #include "Sensor/BMP280Sensor.h" #include "Sensor/LPS22HBSensor.h" #include "Sensor/MCP9808Sensor.h" +#include "Sensor/OPT3001Sensor.h" #include "Sensor/RCWL9620Sensor.h" #include "Sensor/SHT31Sensor.h" #include "Sensor/SHT4XSensor.h" @@ -42,6 +43,7 @@ LPS22HBSensor lps22hbSensor; SHT31Sensor sht31Sensor; VEML7700Sensor veml7700Sensor; TSL2591Sensor tsl2591Sensor; +OPT3001Sensor opt3001Sensor; SHT4XSensor sht4xSensor; RCWL9620Sensor rcwl9620Sensor; AHT10Sensor aht10Sensor; @@ -109,6 +111,8 @@ int32_t EnvironmentTelemetryModule::runOnce() result = veml7700Sensor.runOnce(); if (tsl2591Sensor.hasSensor()) result = tsl2591Sensor.runOnce(); + if (opt3001Sensor.hasSensor()) + result = opt3001Sensor.runOnce(); if (rcwl9620Sensor.hasSensor()) result = rcwl9620Sensor.runOnce(); if (aht10Sensor.hasSensor()) @@ -299,6 +303,10 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) valid = valid && tsl2591Sensor.getMetrics(&m); hasSensor = true; } + if (opt3001Sensor.hasSensor()) { + valid = valid && opt3001Sensor.getMetrics(&m); + hasSensor = true; + } if (rcwl9620Sensor.hasSensor()) { valid = valid && rcwl9620Sensor.getMetrics(&m); hasSensor = true; diff --git a/src/modules/Telemetry/Sensor/OPT3001Sensor.cpp b/src/modules/Telemetry/Sensor/OPT3001Sensor.cpp new file mode 100644 index 0000000000..0d76e2897f --- /dev/null +++ b/src/modules/Telemetry/Sensor/OPT3001Sensor.cpp @@ -0,0 +1,44 @@ +#include "OPT3001Sensor.h" +#include "../mesh/generated/meshtastic/telemetry.pb.h" +#include "TelemetrySensor.h" +#include "configuration.h" +#include + +OPT3001Sensor::OPT3001Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_OPT3001, "OPT3001") {} + +int32_t OPT3001Sensor::runOnce() +{ + LOG_INFO("Init sensor: %s\n", sensorName); + if (!hasSensor()) { + return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; + } + auto errorCode = opt3001.begin(nodeTelemetrySensorsMap[sensorType].first); + status = errorCode == NO_ERROR; + + return initI2CSensor(); +} + +void OPT3001Sensor::setup() +{ + OPT3001_Config newConfig; + + newConfig.RangeNumber = B1100; + newConfig.ConvertionTime = B0; + newConfig.Latch = B1; + newConfig.ModeOfConversionOperation = B11; + + OPT3001_ErrorCode errorConfig = opt3001.writeConfig(newConfig); + if (errorConfig != NO_ERROR) { + LOG_ERROR("OPT3001 configuration error #%d", errorConfig); + } +} + +bool OPT3001Sensor::getMetrics(meshtastic_Telemetry *measurement) +{ + OPT3001 result = opt3001.readResult(); + + measurement->variant.environment_metrics.lux = result.lux; + LOG_INFO("Lux: %f\n", measurement->variant.environment_metrics.lux); + + return true; +} \ No newline at end of file diff --git a/src/modules/Telemetry/Sensor/OPT3001Sensor.h b/src/modules/Telemetry/Sensor/OPT3001Sensor.h new file mode 100644 index 0000000000..4a8deef218 --- /dev/null +++ b/src/modules/Telemetry/Sensor/OPT3001Sensor.h @@ -0,0 +1,17 @@ +#include "../mesh/generated/meshtastic/telemetry.pb.h" +#include "TelemetrySensor.h" +#include + +class OPT3001Sensor : public TelemetrySensor +{ + private: + ClosedCube_OPT3001 opt3001; + + protected: + virtual void setup() override; + + public: + OPT3001Sensor(); + virtual int32_t runOnce() override; + virtual bool getMetrics(meshtastic_Telemetry *measurement) override; +}; \ No newline at end of file From 06c635eca0b489d90c82286eea679a0e190ead16 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sun, 2 Jun 2024 09:38:28 -0500 Subject: [PATCH 3/3] MLX90632 IR temperature sensor support (#4019) --- platformio.ini | 3 +- src/configuration.h | 5 ++- src/detect/ScanI2C.h | 1 + src/detect/ScanI2CTwoWire.cpp | 3 +- src/main.cpp | 1 + .../Telemetry/EnvironmentTelemetry.cpp | 8 ++++ .../Telemetry/Sensor/MLX90632Sensor.cpp | 40 +++++++++++++++++++ src/modules/Telemetry/Sensor/MLX90632Sensor.h | 23 +++++++++++ 8 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 src/modules/Telemetry/Sensor/MLX90632Sensor.cpp create mode 100644 src/modules/Telemetry/Sensor/MLX90632Sensor.h diff --git a/platformio.ini b/platformio.ini index 791c31a9b9..968a37d9bd 100644 --- a/platformio.ini +++ b/platformio.ini @@ -137,4 +137,5 @@ lib_deps = adafruit/Adafruit VEML7700 Library@^2.1.6 adafruit/Adafruit SHT4x Library@^1.0.4 adafruit/Adafruit TSL2591 Library@^1.4.5 - ClosedCube OPT3001@^1.1.2 \ No newline at end of file + ClosedCube OPT3001@^1.1.2 + emotibit/EmotiBit MLX90632@^1.0.8 \ No newline at end of file diff --git a/src/configuration.h b/src/configuration.h index b102746b39..744406f18b 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -132,8 +132,9 @@ along with this program. If not, see . #define RCWL9620_ADDR 0x57 #define VEML7700_ADDR 0x10 #define TSL25911_ADDR 0x29 -#define OPT3001_ADDRESS 0x45 -#define OPT3001_ADDRESS_ALT 0x44 +#define OPT3001_ADDR 0x45 +#define OPT3001_ADDR_ALT 0x44 +#define MLX90632_ADDR 0x3A // ----------------------------------------------------------------------------- // ACCELEROMETER diff --git a/src/detect/ScanI2C.h b/src/detect/ScanI2C.h index 917335a142..a90d9218a8 100644 --- a/src/detect/ScanI2C.h +++ b/src/detect/ScanI2C.h @@ -47,6 +47,7 @@ class ScanI2C NCP5623, TSL2591, OPT3001, + MLX90632, AHT10, } DeviceType; diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 4597a70cad..3aeb8560ea 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -346,7 +346,8 @@ void ScanI2CTwoWire::scanPort(I2CPort port) SCAN_SIMPLE_CASE(TCA9555_ADDR, TCA9555, "TCA9555 I2C expander found\n"); SCAN_SIMPLE_CASE(VEML7700_ADDR, VEML7700, "VEML7700 light sensor found\n"); SCAN_SIMPLE_CASE(TSL25911_ADDR, TSL2591, "TSL2591 light sensor found\n"); - SCAN_SIMPLE_CASE(OPT3001_ADDRESS, OPT3001, "OPT3001 light sensor found\n"); + SCAN_SIMPLE_CASE(OPT3001_ADDR, OPT3001, "OPT3001 light sensor found\n"); + SCAN_SIMPLE_CASE(MLX90632_ADDR, MLX90632, "MLX90632 IR temp sensor found\n"); default: LOG_INFO("Device found at address 0x%x was not able to be enumerated\n", addr.address); diff --git a/src/main.cpp b/src/main.cpp index 8d870feba1..3c18936901 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -535,6 +535,7 @@ void setup() SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::VEML7700, meshtastic_TelemetrySensorType_VEML7700) SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::TSL2591, meshtastic_TelemetrySensorType_TSL25911FN) SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::OPT3001, meshtastic_TelemetrySensorType_OPT3001) + SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::MLX90632, meshtastic_TelemetrySensorType_MLX90632) SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::SHT4X, meshtastic_TelemetrySensorType_SHT4X) SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::AHT10, meshtastic_TelemetrySensorType_AHT10) diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 1d45d3ee99..9032389c5d 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -25,6 +25,7 @@ #include "Sensor/BMP280Sensor.h" #include "Sensor/LPS22HBSensor.h" #include "Sensor/MCP9808Sensor.h" +#include "Sensor/MLX90632Sensor.h" #include "Sensor/OPT3001Sensor.h" #include "Sensor/RCWL9620Sensor.h" #include "Sensor/SHT31Sensor.h" @@ -47,6 +48,7 @@ OPT3001Sensor opt3001Sensor; SHT4XSensor sht4xSensor; RCWL9620Sensor rcwl9620Sensor; AHT10Sensor aht10Sensor; +MLX90632Sensor mlx90632Sensor; #define FAILED_STATE_SENSOR_READ_MULTIPLIER 10 #define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true @@ -117,6 +119,8 @@ int32_t EnvironmentTelemetryModule::runOnce() result = rcwl9620Sensor.runOnce(); if (aht10Sensor.hasSensor()) result = aht10Sensor.runOnce(); + if (mlx90632Sensor.hasSensor()) + result = mlx90632Sensor.runOnce(); } return result; } else { @@ -307,6 +311,10 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) valid = valid && opt3001Sensor.getMetrics(&m); hasSensor = true; } + if (mlx90632Sensor.hasSensor()) { + valid = valid && mlx90632Sensor.getMetrics(&m); + hasSensor = true; + } if (rcwl9620Sensor.hasSensor()) { valid = valid && rcwl9620Sensor.getMetrics(&m); hasSensor = true; diff --git a/src/modules/Telemetry/Sensor/MLX90632Sensor.cpp b/src/modules/Telemetry/Sensor/MLX90632Sensor.cpp new file mode 100644 index 0000000000..4c459c3655 --- /dev/null +++ b/src/modules/Telemetry/Sensor/MLX90632Sensor.cpp @@ -0,0 +1,40 @@ +#include "configuration.h" + +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR + +#include "../mesh/generated/meshtastic/telemetry.pb.h" +#include "MLX90632Sensor.h" +#include "TelemetrySensor.h" + +MLX90632Sensor::MLX90632Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_MLX90632, "MLX90632") {} + +int32_t MLX90632Sensor::runOnce() +{ + LOG_INFO("Init sensor: %s\n", sensorName); + if (!hasSensor()) { + return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; + } + + MLX90632::status returnError; + if (mlx.begin(nodeTelemetrySensorsMap[sensorType].first, *nodeTelemetrySensorsMap[sensorType].second, returnError) == + true) // MLX90632 init + { + LOG_DEBUG("MLX90632 Init Succeed\n"); + status = true; + } else { + LOG_ERROR("MLX90632 Init Failed\n"); + status = false; + } + return initI2CSensor(); +} + +void MLX90632Sensor::setup() {} + +bool MLX90632Sensor::getMetrics(meshtastic_Telemetry *measurement) +{ + measurement->variant.environment_metrics.temperature = mlx.getObjectTemp(); // Get the object temperature in Fahrenheit + + return true; +} + +#endif \ No newline at end of file diff --git a/src/modules/Telemetry/Sensor/MLX90632Sensor.h b/src/modules/Telemetry/Sensor/MLX90632Sensor.h new file mode 100644 index 0000000000..7b36c44cd8 --- /dev/null +++ b/src/modules/Telemetry/Sensor/MLX90632Sensor.h @@ -0,0 +1,23 @@ +#include "configuration.h" + +#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR + +#include "../mesh/generated/meshtastic/telemetry.pb.h" +#include "TelemetrySensor.h" +#include + +class MLX90632Sensor : public TelemetrySensor +{ + private: + MLX90632 mlx = MLX90632(); + + protected: + virtual void setup() override; + + public: + MLX90632Sensor(); + virtual int32_t runOnce() override; + virtual bool getMetrics(meshtastic_Telemetry *measurement) override; +}; + +#endif \ No newline at end of file