diff --git a/src/configuration.h b/src/configuration.h index 701e07a32..37fda2b9d 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -128,6 +128,7 @@ along with this program. If not, see . #define LPS22HB_ADDR_ALT 0x5D #define SHT31_ADDR 0x44 #define PMSA0031_ADDR 0x12 +#define VEML7700_ADDR 0x10 // ----------------------------------------------------------------------------- // ACCELEROMETER diff --git a/src/detect/ScanI2C.h b/src/detect/ScanI2C.h index c8fcfee10..5fad2f30a 100644 --- a/src/detect/ScanI2C.h +++ b/src/detect/ScanI2C.h @@ -41,6 +41,7 @@ class ScanI2C BQ24295, LSM6DS3, TCA9555, + VEML7700, #ifdef HAS_NCP5623 NCP5623, #endif diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index ba2820a77..0b76318ce 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -324,6 +324,7 @@ void ScanI2CTwoWire::scanPort(I2CPort port) SCAN_SIMPLE_CASE(BMA423_ADDR, BMA423, "BMA423 accelerometer found\n"); SCAN_SIMPLE_CASE(LSM6DS3_ADDR, LSM6DS3, "LSM6DS3 accelerometer found at address 0x%x\n", (uint8_t)addr.address); SCAN_SIMPLE_CASE(TCA9555_ADDR, TCA9555, "TCA9555 I2C expander found\n"); + SCAN_SIMPLE_CASE(VEML7700_ADDR, VEML7700, "VEML7700 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 f40fd0789..0a26312eb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -538,6 +538,7 @@ void setup() SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::QMI8658, meshtastic_TelemetrySensorType_QMI8658) SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::QMC5883L, meshtastic_TelemetrySensorType_QMC5883L) SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::PMSA0031, meshtastic_TelemetrySensorType_PMSA003I) + SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::VEML7700, meshtastic_TelemetrySensorType_VEML7700) i2cScanner.reset(); @@ -1006,4 +1007,4 @@ void loop() mainDelay.delay(delayMsec); } // if (didWake) LOG_DEBUG("wake!\n"); -} +} \ No newline at end of file diff --git a/src/mesh/generated/meshtastic/telemetry.pb.h b/src/mesh/generated/meshtastic/telemetry.pb.h index d4efad85d..d85855437 100644 --- a/src/mesh/generated/meshtastic/telemetry.pb.h +++ b/src/mesh/generated/meshtastic/telemetry.pb.h @@ -86,7 +86,12 @@ typedef struct _meshtastic_EnvironmentMetrics { uint16_t iaq; /* RCWL9620 Doppler Radar Distance Sensor, used for water level detection. Float value in mm. */ float distance; + /* VEML7700 high accuracy ambient light(Lux) digital 16-bit resolution sensor. */ float lux; + /* VEML7700 raw white light data digital 16-bit resolution sensor. */ + uint32_t white; + /* VEML7700 raw ALS data digital 16-bit resolution sensor. */ + uint32_t ALS; } meshtastic_EnvironmentMetrics; /* Power Metrics (voltage / current / etc) */ @@ -168,12 +173,12 @@ extern "C" { /* Initializer values for message structs */ #define meshtastic_DeviceMetrics_init_default {0, 0, 0, 0, 0} -#define meshtastic_EnvironmentMetrics_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0} +#define meshtastic_EnvironmentMetrics_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define meshtastic_PowerMetrics_init_default {0, 0, 0, 0, 0, 0} #define meshtastic_AirQualityMetrics_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define meshtastic_Telemetry_init_default {0, 0, {meshtastic_DeviceMetrics_init_default}} #define meshtastic_DeviceMetrics_init_zero {0, 0, 0, 0, 0} -#define meshtastic_EnvironmentMetrics_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0} +#define meshtastic_EnvironmentMetrics_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define meshtastic_PowerMetrics_init_zero {0, 0, 0, 0, 0, 0} #define meshtastic_AirQualityMetrics_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define meshtastic_Telemetry_init_zero {0, 0, {meshtastic_DeviceMetrics_init_zero}} @@ -193,6 +198,8 @@ extern "C" { #define meshtastic_EnvironmentMetrics_iaq_tag 7 #define meshtastic_EnvironmentMetrics_distance_tag 8 #define meshtastic_EnvironmentMetrics_lux_tag 9 +#define meshtastic_EnvironmentMetrics_white_tag 10 +#define meshtastic_EnvironmentMetrics_ALS_tag 11 #define meshtastic_PowerMetrics_ch1_voltage_tag 1 #define meshtastic_PowerMetrics_ch1_current_tag 2 #define meshtastic_PowerMetrics_ch2_voltage_tag 3 @@ -236,7 +243,9 @@ X(a, STATIC, SINGULAR, FLOAT, voltage, 5) \ X(a, STATIC, SINGULAR, FLOAT, current, 6) \ X(a, STATIC, SINGULAR, UINT32, iaq, 7) \ X(a, STATIC, SINGULAR, FLOAT, distance, 8) \ -X(a, STATIC, SINGULAR, FLOAT, lux, 9) +X(a, STATIC, SINGULAR, FLOAT, lux, 9) \ +X(a, STATIC, SINGULAR, UINT32, white, 10) \ +X(a, STATIC, SINGULAR, UINT32, ALS, 11) #define meshtastic_EnvironmentMetrics_CALLBACK NULL #define meshtastic_EnvironmentMetrics_DEFAULT NULL @@ -296,7 +305,7 @@ extern const pb_msgdesc_t meshtastic_Telemetry_msg; #define MESHTASTIC_MESHTASTIC_TELEMETRY_PB_H_MAX_SIZE meshtastic_Telemetry_size #define meshtastic_AirQualityMetrics_size 72 #define meshtastic_DeviceMetrics_size 27 -#define meshtastic_EnvironmentMetrics_size 44 +#define meshtastic_EnvironmentMetrics_size 56 #define meshtastic_PowerMetrics_size 30 #define meshtastic_Telemetry_size 79 diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index 189ab7ed0..657d309ba 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -23,6 +23,7 @@ #include "Sensor/MCP9808Sensor.h" #include "Sensor/SHT31Sensor.h" #include "Sensor/SHTC3Sensor.h" +#include "Sensor/VEML7700Sensor.h" BMP085Sensor bmp085Sensor; BMP280Sensor bmp280Sensor; @@ -32,6 +33,7 @@ MCP9808Sensor mcp9808Sensor; SHTC3Sensor shtc3Sensor; LPS22HBSensor lps22hbSensor; SHT31Sensor sht31Sensor; +VEML7700Sensor veml7700Sensor; #define FAILED_STATE_SENSOR_READ_MULTIPLIER 10 #define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true @@ -90,6 +92,8 @@ int32_t EnvironmentTelemetryModule::runOnce() result = ina219Sensor.runOnce(); if (ina260Sensor.hasSensor()) result = ina260Sensor.runOnce(); + if (veml7700Sensor.hasSensor()) + result = veml7700Sensor.runOnce(); } return result; } else { @@ -192,10 +196,11 @@ bool EnvironmentTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPac const char *sender = getSenderShortName(mp); LOG_INFO("(Received from %s): barometric_pressure=%f, current=%f, gas_resistance=%f, relative_humidity=%f, " - "temperature=%f, voltage=%f\n", + "temperature=%f, voltage=%f, lux=%f, iaq=%i\n", sender, t->variant.environment_metrics.barometric_pressure, t->variant.environment_metrics.current, t->variant.environment_metrics.gas_resistance, t->variant.environment_metrics.relative_humidity, - t->variant.environment_metrics.temperature, t->variant.environment_metrics.voltage); + t->variant.environment_metrics.temperature, t->variant.environment_metrics.voltage, + t->variant.environment_metrics.lux, t->variant.environment_metrics.iaq); #endif // release previous packet before occupying a new spot if (lastMeasurementPacket != nullptr) @@ -210,44 +215,65 @@ bool EnvironmentTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPac bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) { meshtastic_Telemetry m; - bool valid = false; + bool valid = true; + bool hasSensor = false; m.time = getTime(); m.which_variant = meshtastic_Telemetry_environment_metrics_tag; - m.variant.environment_metrics.barometric_pressure = 0; - m.variant.environment_metrics.current = 0; - m.variant.environment_metrics.gas_resistance = 0; - m.variant.environment_metrics.relative_humidity = 0; - m.variant.environment_metrics.temperature = 0; - m.variant.environment_metrics.voltage = 0; - - if (sht31Sensor.hasSensor()) - valid = sht31Sensor.getMetrics(&m); - if (lps22hbSensor.hasSensor()) - valid = lps22hbSensor.getMetrics(&m); - if (shtc3Sensor.hasSensor()) - valid = shtc3Sensor.getMetrics(&m); - if (bmp085Sensor.hasSensor()) - valid = bmp085Sensor.getMetrics(&m); - if (bmp280Sensor.hasSensor()) - valid = bmp280Sensor.getMetrics(&m); - if (bme280Sensor.hasSensor()) - valid = bme280Sensor.getMetrics(&m); - if (bme680Sensor.hasSensor()) - valid = bme680Sensor.getMetrics(&m); - if (mcp9808Sensor.hasSensor()) - valid = mcp9808Sensor.getMetrics(&m); - if (ina219Sensor.hasSensor()) + if (sht31Sensor.hasSensor()) { + valid = valid && sht31Sensor.getMetrics(&m); + hasSensor = true; + } + if (lps22hbSensor.hasSensor()) { + valid = valid && lps22hbSensor.getMetrics(&m); + hasSensor = true; + } + if (shtc3Sensor.hasSensor()) { + valid = valid && shtc3Sensor.getMetrics(&m); + hasSensor = true; + } + if (bmp085Sensor.hasSensor()) { + valid = valid && bmp085Sensor.getMetrics(&m); + hasSensor = true; + } + if (bmp280Sensor.hasSensor()) { + valid = valid && bmp280Sensor.getMetrics(&m); + hasSensor = true; + } + if (bme280Sensor.hasSensor()) { + valid = valid && bme280Sensor.getMetrics(&m); + hasSensor = true; + } + if (bme680Sensor.hasSensor()) { + valid = valid && bme680Sensor.getMetrics(&m); + hasSensor = true; + } + if (mcp9808Sensor.hasSensor()) { + valid = valid && mcp9808Sensor.getMetrics(&m); + hasSensor = true; + } + if (ina219Sensor.hasSensor()) { valid = ina219Sensor.getMetrics(&m); - if (ina260Sensor.hasSensor()) - valid = ina260Sensor.getMetrics(&m); + hasSensor = true; + } + if (ina260Sensor.hasSensor()) { + valid = valid && ina260Sensor.getMetrics(&m); + hasSensor = true; + } + if (veml7700Sensor.hasSensor()) { + valid = valid && veml7700Sensor.getMetrics(&m); + hasSensor = true; + } + + valid = valid && hasSensor; if (valid) { LOG_INFO("(Sending): barometric_pressure=%f, current=%f, gas_resistance=%f, relative_humidity=%f, temperature=%f, " - "voltage=%f\n", + "voltage=%f, lux=%f, iaq=%i\n", m.variant.environment_metrics.barometric_pressure, m.variant.environment_metrics.current, m.variant.environment_metrics.gas_resistance, m.variant.environment_metrics.relative_humidity, - m.variant.environment_metrics.temperature, m.variant.environment_metrics.voltage); + m.variant.environment_metrics.temperature, m.variant.environment_metrics.voltage, + m.variant.environment_metrics.lux, m.variant.environment_metrics.iaq); sensor_read_error_count = 0; diff --git a/src/modules/Telemetry/Sensor/VEML7700Sensor.cpp b/src/modules/Telemetry/Sensor/VEML7700Sensor.cpp index cfce1c7f1..5e1376849 100644 --- a/src/modules/Telemetry/Sensor/VEML7700Sensor.cpp +++ b/src/modules/Telemetry/Sensor/VEML7700Sensor.cpp @@ -26,9 +26,10 @@ void VEML7700Sensor::setup() {} bool VEML7700Sensor::getMetrics(meshtastic_Telemetry *measurement) { - LOG_DEBUG("VEML7700Sensor::getMetrics\n"); - measurement->variant.environment_metrics.lux = veml7700.readLux(VEML_LUX_AUTO); + measurement->variant.environment_metrics.white = veml7700.readWhite(); + measurement->variant.environment_metrics.ALS = veml7700.readALS(); + return true; } \ No newline at end of file diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index da1c204b8..59f1002fc 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -664,6 +664,10 @@ std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp) msgPayload["gas_resistance"] = new JSONValue(decoded->variant.environment_metrics.gas_resistance); msgPayload["voltage"] = new JSONValue(decoded->variant.environment_metrics.voltage); msgPayload["current"] = new JSONValue(decoded->variant.environment_metrics.current); + msgPayload["lux"] = new JSONValue(decoded->variant.environment_metrics.lux); + msgPayload["white"] = new JSONValue((uint)decoded->variant.environment_metrics.white); + msgPayload["ALS"] = new JSONValue((uint)decoded->variant.environment_metrics.ALS); + msgPayload["iaq"] = new JSONValue((uint)decoded->variant.environment_metrics.iaq); } else if (decoded->which_variant == meshtastic_Telemetry_power_metrics_tag) { msgPayload["voltage_ch1"] = new JSONValue(decoded->variant.power_metrics.ch1_voltage); msgPayload["current_ch1"] = new JSONValue(decoded->variant.power_metrics.ch1_current);