add veml7700 readings to protobuf and to the mqtt json + fix the readigns validator code in env telemetry

This commit is contained in:
Jorge Castillo 2024-05-08 22:14:55 -04:00
parent 23466b5a5f
commit 39336847ad
8 changed files with 82 additions and 38 deletions

View File

@ -128,6 +128,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define LPS22HB_ADDR_ALT 0x5D #define LPS22HB_ADDR_ALT 0x5D
#define SHT31_ADDR 0x44 #define SHT31_ADDR 0x44
#define PMSA0031_ADDR 0x12 #define PMSA0031_ADDR 0x12
#define VEML7700_ADDR 0x10
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// ACCELEROMETER // ACCELEROMETER

View File

@ -41,6 +41,7 @@ class ScanI2C
BQ24295, BQ24295,
LSM6DS3, LSM6DS3,
TCA9555, TCA9555,
VEML7700,
#ifdef HAS_NCP5623 #ifdef HAS_NCP5623
NCP5623, NCP5623,
#endif #endif

View File

@ -324,6 +324,7 @@ void ScanI2CTwoWire::scanPort(I2CPort port)
SCAN_SIMPLE_CASE(BMA423_ADDR, BMA423, "BMA423 accelerometer found\n"); 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(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(TCA9555_ADDR, TCA9555, "TCA9555 I2C expander found\n");
SCAN_SIMPLE_CASE(VEML7700_ADDR, VEML7700, "VEML7700 light sensor found\n");
default: default:
LOG_INFO("Device found at address 0x%x was not able to be enumerated\n", addr.address); LOG_INFO("Device found at address 0x%x was not able to be enumerated\n", addr.address);

View File

@ -538,6 +538,7 @@ void setup()
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::QMI8658, meshtastic_TelemetrySensorType_QMI8658) 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::QMC5883L, meshtastic_TelemetrySensorType_QMC5883L)
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::PMSA0031, meshtastic_TelemetrySensorType_PMSA003I) SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::PMSA0031, meshtastic_TelemetrySensorType_PMSA003I)
SCANNER_TO_SENSORS_MAP(ScanI2C::DeviceType::VEML7700, meshtastic_TelemetrySensorType_VEML7700)
i2cScanner.reset(); i2cScanner.reset();

View File

@ -86,7 +86,12 @@ typedef struct _meshtastic_EnvironmentMetrics {
uint16_t iaq; uint16_t iaq;
/* RCWL9620 Doppler Radar Distance Sensor, used for water level detection. Float value in mm. */ /* RCWL9620 Doppler Radar Distance Sensor, used for water level detection. Float value in mm. */
float distance; float distance;
/* VEML7700 high accuracy ambient light(Lux) digital 16-bit resolution sensor. */
float lux; 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; } meshtastic_EnvironmentMetrics;
/* Power Metrics (voltage / current / etc) */ /* Power Metrics (voltage / current / etc) */
@ -168,12 +173,12 @@ extern "C" {
/* Initializer values for message structs */ /* Initializer values for message structs */
#define meshtastic_DeviceMetrics_init_default {0, 0, 0, 0, 0} #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_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_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_Telemetry_init_default {0, 0, {meshtastic_DeviceMetrics_init_default}}
#define meshtastic_DeviceMetrics_init_zero {0, 0, 0, 0, 0} #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_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_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}} #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_iaq_tag 7
#define meshtastic_EnvironmentMetrics_distance_tag 8 #define meshtastic_EnvironmentMetrics_distance_tag 8
#define meshtastic_EnvironmentMetrics_lux_tag 9 #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_voltage_tag 1
#define meshtastic_PowerMetrics_ch1_current_tag 2 #define meshtastic_PowerMetrics_ch1_current_tag 2
#define meshtastic_PowerMetrics_ch2_voltage_tag 3 #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, FLOAT, current, 6) \
X(a, STATIC, SINGULAR, UINT32, iaq, 7) \ X(a, STATIC, SINGULAR, UINT32, iaq, 7) \
X(a, STATIC, SINGULAR, FLOAT, distance, 8) \ 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_CALLBACK NULL
#define meshtastic_EnvironmentMetrics_DEFAULT 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_MESHTASTIC_TELEMETRY_PB_H_MAX_SIZE meshtastic_Telemetry_size
#define meshtastic_AirQualityMetrics_size 72 #define meshtastic_AirQualityMetrics_size 72
#define meshtastic_DeviceMetrics_size 27 #define meshtastic_DeviceMetrics_size 27
#define meshtastic_EnvironmentMetrics_size 44 #define meshtastic_EnvironmentMetrics_size 56
#define meshtastic_PowerMetrics_size 30 #define meshtastic_PowerMetrics_size 30
#define meshtastic_Telemetry_size 79 #define meshtastic_Telemetry_size 79

View File

@ -23,6 +23,7 @@
#include "Sensor/MCP9808Sensor.h" #include "Sensor/MCP9808Sensor.h"
#include "Sensor/SHT31Sensor.h" #include "Sensor/SHT31Sensor.h"
#include "Sensor/SHTC3Sensor.h" #include "Sensor/SHTC3Sensor.h"
#include "Sensor/VEML7700Sensor.h"
BMP085Sensor bmp085Sensor; BMP085Sensor bmp085Sensor;
BMP280Sensor bmp280Sensor; BMP280Sensor bmp280Sensor;
@ -32,6 +33,7 @@ MCP9808Sensor mcp9808Sensor;
SHTC3Sensor shtc3Sensor; SHTC3Sensor shtc3Sensor;
LPS22HBSensor lps22hbSensor; LPS22HBSensor lps22hbSensor;
SHT31Sensor sht31Sensor; SHT31Sensor sht31Sensor;
VEML7700Sensor veml7700Sensor;
#define FAILED_STATE_SENSOR_READ_MULTIPLIER 10 #define FAILED_STATE_SENSOR_READ_MULTIPLIER 10
#define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true #define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true
@ -90,6 +92,8 @@ int32_t EnvironmentTelemetryModule::runOnce()
result = ina219Sensor.runOnce(); result = ina219Sensor.runOnce();
if (ina260Sensor.hasSensor()) if (ina260Sensor.hasSensor())
result = ina260Sensor.runOnce(); result = ina260Sensor.runOnce();
if (veml7700Sensor.hasSensor())
result = veml7700Sensor.runOnce();
} }
return result; return result;
} else { } else {
@ -192,10 +196,11 @@ bool EnvironmentTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPac
const char *sender = getSenderShortName(mp); const char *sender = getSenderShortName(mp);
LOG_INFO("(Received from %s): barometric_pressure=%f, current=%f, gas_resistance=%f, relative_humidity=%f, " 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, 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.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 #endif
// release previous packet before occupying a new spot // release previous packet before occupying a new spot
if (lastMeasurementPacket != nullptr) if (lastMeasurementPacket != nullptr)
@ -210,44 +215,65 @@ bool EnvironmentTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPac
bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
{ {
meshtastic_Telemetry m; meshtastic_Telemetry m;
bool valid = false; bool valid = true;
bool hasSensor = false;
m.time = getTime(); m.time = getTime();
m.which_variant = meshtastic_Telemetry_environment_metrics_tag; m.which_variant = meshtastic_Telemetry_environment_metrics_tag;
m.variant.environment_metrics.barometric_pressure = 0; if (sht31Sensor.hasSensor()) {
m.variant.environment_metrics.current = 0; valid = valid && sht31Sensor.getMetrics(&m);
m.variant.environment_metrics.gas_resistance = 0; hasSensor = true;
m.variant.environment_metrics.relative_humidity = 0; }
m.variant.environment_metrics.temperature = 0; if (lps22hbSensor.hasSensor()) {
m.variant.environment_metrics.voltage = 0; valid = valid && lps22hbSensor.getMetrics(&m);
hasSensor = true;
if (sht31Sensor.hasSensor()) }
valid = sht31Sensor.getMetrics(&m); if (shtc3Sensor.hasSensor()) {
if (lps22hbSensor.hasSensor()) valid = valid && shtc3Sensor.getMetrics(&m);
valid = lps22hbSensor.getMetrics(&m); hasSensor = true;
if (shtc3Sensor.hasSensor()) }
valid = shtc3Sensor.getMetrics(&m); if (bmp085Sensor.hasSensor()) {
if (bmp085Sensor.hasSensor()) valid = valid && bmp085Sensor.getMetrics(&m);
valid = bmp085Sensor.getMetrics(&m); hasSensor = true;
if (bmp280Sensor.hasSensor()) }
valid = bmp280Sensor.getMetrics(&m); if (bmp280Sensor.hasSensor()) {
if (bme280Sensor.hasSensor()) valid = valid && bmp280Sensor.getMetrics(&m);
valid = bme280Sensor.getMetrics(&m); hasSensor = true;
if (bme680Sensor.hasSensor()) }
valid = bme680Sensor.getMetrics(&m); if (bme280Sensor.hasSensor()) {
if (mcp9808Sensor.hasSensor()) valid = valid && bme280Sensor.getMetrics(&m);
valid = mcp9808Sensor.getMetrics(&m); hasSensor = true;
if (ina219Sensor.hasSensor()) }
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); valid = ina219Sensor.getMetrics(&m);
if (ina260Sensor.hasSensor()) hasSensor = true;
valid = ina260Sensor.getMetrics(&m); }
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) { if (valid) {
LOG_INFO("(Sending): barometric_pressure=%f, current=%f, gas_resistance=%f, relative_humidity=%f, temperature=%f, " 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.barometric_pressure, m.variant.environment_metrics.current,
m.variant.environment_metrics.gas_resistance, m.variant.environment_metrics.relative_humidity, 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; sensor_read_error_count = 0;

View File

@ -26,9 +26,10 @@ void VEML7700Sensor::setup() {}
bool VEML7700Sensor::getMetrics(meshtastic_Telemetry *measurement) 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.lux = veml7700.readLux(VEML_LUX_AUTO);
measurement->variant.environment_metrics.white = veml7700.readWhite();
measurement->variant.environment_metrics.ALS = veml7700.readALS();
return true; return true;
} }

View File

@ -664,6 +664,10 @@ std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp)
msgPayload["gas_resistance"] = new JSONValue(decoded->variant.environment_metrics.gas_resistance); msgPayload["gas_resistance"] = new JSONValue(decoded->variant.environment_metrics.gas_resistance);
msgPayload["voltage"] = new JSONValue(decoded->variant.environment_metrics.voltage); msgPayload["voltage"] = new JSONValue(decoded->variant.environment_metrics.voltage);
msgPayload["current"] = new JSONValue(decoded->variant.environment_metrics.current); 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) { } else if (decoded->which_variant == meshtastic_Telemetry_power_metrics_tag) {
msgPayload["voltage_ch1"] = new JSONValue(decoded->variant.power_metrics.ch1_voltage); msgPayload["voltage_ch1"] = new JSONValue(decoded->variant.power_metrics.ch1_voltage);
msgPayload["current_ch1"] = new JSONValue(decoded->variant.power_metrics.ch1_current); msgPayload["current_ch1"] = new JSONValue(decoded->variant.power_metrics.ch1_current);