From 90957e6994a606d413820676029571bcecd76611 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 11 Jun 2022 16:44:56 -0500 Subject: [PATCH 1/4] INA260 + INA219 sensor support (#1501) * INA219 + INA260 support in telemetry * Protobuf update * Fixes + debug statement * Fix size * Fix conversion from mv * Added getRegisterValue for i2cscan --- platformio.ini | 3 +- protobufs | 2 +- src/configuration.h | 2 + src/debug/i2cScan.h | 55 ++++++++++++------- src/main.cpp | 3 +- src/main.h | 2 +- src/mesh/generated/config.pb.h | 12 +--- src/mesh/generated/localonly.pb.h | 2 +- src/mesh/generated/telemetry.pb.h | 38 +++++++------ .../Telemetry/EnvironmentTelemetry.cpp | 14 +++++ src/modules/Telemetry/Sensor/BME280Sensor.cpp | 4 +- src/modules/Telemetry/Sensor/BME680Sensor.cpp | 5 +- src/modules/Telemetry/Sensor/INA219Sensor.cpp | 30 ++++++++++ src/modules/Telemetry/Sensor/INA219Sensor.h | 17 ++++++ src/modules/Telemetry/Sensor/INA260Sensor.cpp | 30 ++++++++++ src/modules/Telemetry/Sensor/INA260Sensor.h | 17 ++++++ .../Telemetry/Sensor/MCP9808Sensor.cpp | 4 +- 17 files changed, 182 insertions(+), 58 deletions(-) create mode 100644 src/modules/Telemetry/Sensor/INA219Sensor.cpp create mode 100644 src/modules/Telemetry/Sensor/INA219Sensor.h create mode 100644 src/modules/Telemetry/Sensor/INA260Sensor.cpp create mode 100644 src/modules/Telemetry/Sensor/INA260Sensor.h diff --git a/platformio.ini b/platformio.ini index 5d991fe38..6628cdb99 100644 --- a/platformio.ini +++ b/platformio.ini @@ -84,7 +84,8 @@ lib_deps = adafruit/Adafruit BME280 Library@^2.2.2 adafruit/Adafruit BME680 Library@^2.0.1 adafruit/Adafruit MCP9808 Library@^2.0.0 - + adafruit/Adafruit INA260 Library@^1.5.0 + adafruit/Adafruit INA219@^1.2.0 ; Common settings for ESP targes, mixin with extends = esp32_base [esp32_base] extends = arduino_base diff --git a/protobufs b/protobufs index 33b3ab5fd..dbd4219a8 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 33b3ab5fde6b6ef158e3b111bf240d1d59c152ef +Subproject commit dbd4219a862b26b5c6fa6569bd8faa42ab8852a5 diff --git a/src/configuration.h b/src/configuration.h index 35d226e29..f0d44a3e9 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -177,6 +177,8 @@ along with this program. If not, see . #define BME_ADDR 0x76 #define BME_ADDR_ALTERNATE 0x77 #define MCP9808_ADDR 0x18 +#define INA_ADDR 0x40 +#define INA_ADDR_ALTERNATE 0x41 // ----------------------------------------------------------------------------- // GPS diff --git a/src/debug/i2cScan.h b/src/debug/i2cScan.h index 206cdbfe9..c4ab6a41e 100644 --- a/src/debug/i2cScan.h +++ b/src/debug/i2cScan.h @@ -4,6 +4,24 @@ #include "mesh/generated/telemetry.pb.h" #ifndef NO_WIRE +uint16_t getRegisterValue(uint8_t address, uint8_t reg, uint8_t length) { + uint16_t value = 0x00; + Wire.beginTransmission(address); + Wire.write(reg); + Wire.endTransmission(); + delay(20); + Wire.requestFrom((int)address, length); + DEBUG_MSG("Wire.available() = %d\n", Wire.available()); + if (Wire.available() == 2) { + // Read MSB, then LSB + value = (uint16_t)Wire.read() << 8; + value |= Wire.read(); + } else if (Wire.available()) { + value = Wire.read(); + } + return value; +} + uint8_t oled_probe(byte addr) { uint8_t r = 0; @@ -35,7 +53,7 @@ uint8_t oled_probe(byte addr) void scanI2Cdevice(void) { byte err, addr; - uint8_t r = 0x00; + uint16_t registerValue = 0x00; int nDevices = 0; for (addr = 1; addr < 127; addr++) { Wire.beginTransmission(addr); @@ -75,15 +93,8 @@ void scanI2Cdevice(void) if (addr == CARDKB_ADDR) { cardkb_found = addr; // Do we have the RAK14006 instead? - Wire.beginTransmission(addr); - Wire.write(0x04); // SENSOR_GET_VERSION - Wire.endTransmission(); - delay(20); - Wire.requestFrom((int)addr, 1); - if (Wire.available()) { - r = Wire.read(); - } - if (r == 0x02) { // KEYPAD_VERSION + registerValue = getRegisterValue(addr, 0x04, 1); + if (registerValue == 0x02) { // KEYPAD_VERSION DEBUG_MSG("RAK14004 found\n"); kb_model = 0x02; } else { @@ -106,22 +117,26 @@ void scanI2Cdevice(void) } #endif if (addr == BME_ADDR || addr == BME_ADDR_ALTERNATE) { - Wire.beginTransmission(addr); - Wire.write(0xD0); // GET_ID - Wire.endTransmission(); - delay(20); - Wire.requestFrom((int)addr, 1); - if (Wire.available()) { - r = Wire.read(); - } - if (r == 0x61) { + registerValue = getRegisterValue(addr, 0xD0, 1); // GET_ID + if (registerValue == 0x61) { DEBUG_MSG("BME-680 sensor found at address 0x%x\n", (uint8_t)addr); nodeTelemetrySensorsMap[TelemetrySensorType_BME680] = addr; - } else if (r == 0x60) { + } else if (registerValue == 0x60) { DEBUG_MSG("BME-280 sensor found at address 0x%x\n", (uint8_t)addr); nodeTelemetrySensorsMap[TelemetrySensorType_BME280] = addr; } } + if (addr == INA_ADDR || addr == INA_ADDR_ALTERNATE) { + registerValue = getRegisterValue(addr, 0xFE, 2); + DEBUG_MSG("Register MFG_UID: 0x%x\n", registerValue); + if (registerValue == 0x5449) { + DEBUG_MSG("INA260 sensor found at address 0x%x\n", (uint8_t)addr); + nodeTelemetrySensorsMap[TelemetrySensorType_INA260] = addr; + } else { // Assume INA219 if INA260 ID is not found + DEBUG_MSG("INA219 sensor found at address 0x%x\n", (uint8_t)addr); + nodeTelemetrySensorsMap[TelemetrySensorType_INA219] = addr; + } + } if (addr == MCP9808_ADDR) { nodeTelemetrySensorsMap[TelemetrySensorType_MCP9808] = addr; DEBUG_MSG("MCP9808 sensor found at address 0x%x\n", (uint8_t)addr); diff --git a/src/main.cpp b/src/main.cpp index 4dd16c896..f7938c71f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -89,8 +89,9 @@ bool eink_found = true; uint32_t serialSinceMsec; bool axp192_found; + // Array map of sensor types (as array index) and i2c address as value we'll find in the i2c scan -uint8_t nodeTelemetrySensorsMap[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +uint8_t nodeTelemetrySensorsMap[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; Router *router = NULL; // Users of router don't care what sort of subclass implements that API diff --git a/src/main.h b/src/main.h index 0f7a7779e..cc17adb09 100644 --- a/src/main.h +++ b/src/main.h @@ -19,7 +19,7 @@ extern bool axp192_found; extern bool isCharging; extern bool isUSBPowered; -extern uint8_t nodeTelemetrySensorsMap[10]; +extern uint8_t nodeTelemetrySensorsMap[12]; // Global Screen singleton. extern graphics::Screen *screen; diff --git a/src/mesh/generated/config.pb.h b/src/mesh/generated/config.pb.h index c48d38e6c..3c137cb02 100644 --- a/src/mesh/generated/config.pb.h +++ b/src/mesh/generated/config.pb.h @@ -120,8 +120,6 @@ typedef struct _Config_PositionConfig { bool gps_disabled; uint32_t gps_update_interval; uint32_t gps_attempt_time; - bool gps_accept_2d; - uint32_t gps_max_dop; uint32_t position_flags; } Config_PositionConfig; @@ -194,14 +192,14 @@ extern "C" { /* Initializer values for message structs */ #define Config_init_default {0, {Config_DeviceConfig_init_default}} #define Config_DeviceConfig_init_default {_Config_DeviceConfig_Role_MIN, 0, 0, 0, ""} -#define Config_PositionConfig_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0} +#define Config_PositionConfig_init_default {0, 0, 0, 0, 0, 0, 0} #define Config_PowerConfig_init_default {_Config_PowerConfig_ChargeCurrent_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define Config_WiFiConfig_init_default {"", "", 0, 0} #define Config_DisplayConfig_init_default {0, _Config_DisplayConfig_GpsCoordinateFormat_MIN, 0} #define Config_LoRaConfig_init_default {0, _Config_LoRaConfig_ModemPreset_MIN, 0, 0, 0, 0, _Config_LoRaConfig_RegionCode_MIN, 0, 0, 0, {0, 0, 0}} #define Config_init_zero {0, {Config_DeviceConfig_init_zero}} #define Config_DeviceConfig_init_zero {_Config_DeviceConfig_Role_MIN, 0, 0, 0, ""} -#define Config_PositionConfig_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0} +#define Config_PositionConfig_init_zero {0, 0, 0, 0, 0, 0, 0} #define Config_PowerConfig_init_zero {_Config_PowerConfig_ChargeCurrent_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define Config_WiFiConfig_init_zero {"", "", 0, 0} #define Config_DisplayConfig_init_zero {0, _Config_DisplayConfig_GpsCoordinateFormat_MIN, 0} @@ -232,8 +230,6 @@ extern "C" { #define Config_PositionConfig_gps_disabled_tag 5 #define Config_PositionConfig_gps_update_interval_tag 6 #define Config_PositionConfig_gps_attempt_time_tag 7 -#define Config_PositionConfig_gps_accept_2d_tag 8 -#define Config_PositionConfig_gps_max_dop_tag 9 #define Config_PositionConfig_position_flags_tag 10 #define Config_PowerConfig_charge_current_tag 1 #define Config_PowerConfig_is_low_power_tag 2 @@ -291,8 +287,6 @@ X(a, STATIC, SINGULAR, BOOL, fixed_position, 3) \ X(a, STATIC, SINGULAR, BOOL, gps_disabled, 5) \ X(a, STATIC, SINGULAR, UINT32, gps_update_interval, 6) \ X(a, STATIC, SINGULAR, UINT32, gps_attempt_time, 7) \ -X(a, STATIC, SINGULAR, BOOL, gps_accept_2d, 8) \ -X(a, STATIC, SINGULAR, UINT32, gps_max_dop, 9) \ X(a, STATIC, SINGULAR, UINT32, position_flags, 10) #define Config_PositionConfig_CALLBACK NULL #define Config_PositionConfig_DEFAULT NULL @@ -363,7 +357,7 @@ extern const pb_msgdesc_t Config_LoRaConfig_msg; #define Config_DeviceConfig_size 42 #define Config_DisplayConfig_size 14 #define Config_LoRaConfig_size 67 -#define Config_PositionConfig_size 38 +#define Config_PositionConfig_size 30 #define Config_PowerConfig_size 55 #define Config_WiFiConfig_size 103 #define Config_size 105 diff --git a/src/mesh/generated/localonly.pb.h b/src/mesh/generated/localonly.pb.h index c03d97611..fccc904e4 100644 --- a/src/mesh/generated/localonly.pb.h +++ b/src/mesh/generated/localonly.pb.h @@ -126,7 +126,7 @@ extern const pb_msgdesc_t LocalModuleConfig_msg; #define LocalModuleConfig_fields &LocalModuleConfig_msg /* Maximum encoded size of messages (where known) */ -#define LocalConfig_size 331 +#define LocalConfig_size 323 #define LocalModuleConfig_size 282 #ifdef __cplusplus diff --git a/src/mesh/generated/telemetry.pb.h b/src/mesh/generated/telemetry.pb.h index 6c9db655c..b7857e2ae 100644 --- a/src/mesh/generated/telemetry.pb.h +++ b/src/mesh/generated/telemetry.pb.h @@ -12,26 +12,30 @@ /* Enum definitions */ /* TODO: REPLACE */ typedef enum _TelemetrySensorType { - /* No external telemetry sensor */ + /* No external telemetry sensor explicitly set */ TelemetrySensorType_NotSet = 0, - /* TODO: REPLACE */ + /* Moderate accuracy temperature */ TelemetrySensorType_DHT11 = 1, - /* TODO: REPLACE */ + /* High accuracy temperature */ TelemetrySensorType_DS18B20 = 2, - /* TODO: REPLACE */ + /* Moderate accuracy temperature and humidity */ TelemetrySensorType_DHT12 = 3, - /* TODO: REPLACE */ + /* Moderate accuracy temperature and humidity */ TelemetrySensorType_DHT21 = 4, - /* TODO: REPLACE */ + /* Moderate accuracy temperature and humidity */ TelemetrySensorType_DHT22 = 5, - /* TODO: REPLACE */ + /* High accuracy temperature, pressure, humidity */ TelemetrySensorType_BME280 = 6, - /* TODO: REPLACE */ + /* High accuracy temperature, pressure, humidity, and air resistance */ TelemetrySensorType_BME680 = 7, - /* TODO: REPLACE */ + /* Very high accuracy temperature */ TelemetrySensorType_MCP9808 = 8, - /* TODO: REPLACE */ - TelemetrySensorType_SHTC3 = 9 + /* Moderate accuracy temperature and humidity */ + TelemetrySensorType_SHTC3 = 9, + /* Moderate accuracy current and voltage */ + TelemetrySensorType_INA260 = 10, + /* Moderate accuracy current and voltage */ + TelemetrySensorType_INA219 = 11 } TelemetrySensorType; /* Struct definitions */ @@ -65,10 +69,10 @@ typedef struct _EnvironmentMetrics { /* Types of Measurements the telemetry module is equipped to handle */ typedef struct _Telemetry { - /* This is usually not sent over the mesh (to save space), but it is sent - from the phone so that the local device can set its RTC If it is sent over - the mesh (because there are devices on the mesh without GPS), it will only - be sent by devices which has a hardware GPS clock (IE Mobile Phone). + /* This is usually not sent over the mesh (to save space), but it is sent + from the phone so that the local device can set its RTC If it is sent over + the mesh (because there are devices on the mesh without GPS), it will only + be sent by devices which has a hardware GPS clock (IE Mobile Phone). seconds since 1970 */ uint32_t time; /* Key native device metrics such as battery level */ @@ -82,8 +86,8 @@ typedef struct _Telemetry { /* Helper constants for enums */ #define _TelemetrySensorType_MIN TelemetrySensorType_NotSet -#define _TelemetrySensorType_MAX TelemetrySensorType_SHTC3 -#define _TelemetrySensorType_ARRAYSIZE ((TelemetrySensorType)(TelemetrySensorType_SHTC3+1)) +#define _TelemetrySensorType_MAX TelemetrySensorType_INA219 +#define _TelemetrySensorType_ARRAYSIZE ((TelemetrySensorType)(TelemetrySensorType_INA219+1)) #ifdef __cplusplus diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index c9ae2e3f7..ffa4fce0a 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -16,12 +16,17 @@ #include "Sensor/DHTSensor.h" #include "Sensor/DallasSensor.h" #include "Sensor/MCP9808Sensor.h" +#include "Sensor/INA260Sensor.h" +#include "Sensor/INA219Sensor.h" + BME280Sensor bme280Sensor; BME680Sensor bme680Sensor; DHTSensor dhtSensor; DallasSensor dallasSensor; MCP9808Sensor mcp9808Sensor; +INA260Sensor ina260Sensor; +INA219Sensor ina219Sensor; #define FAILED_STATE_SENSOR_READ_MULTIPLIER 10 #define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true @@ -50,6 +55,7 @@ int32_t EnvironmentTelemetryModule::runOnce() Uncomment the preferences below if you want to use the module without having to configure it from the PythonAPI or WebUI. */ + moduleConfig.telemetry.environment_measurement_enabled = 1; /* moduleConfig.telemetry.environment_measurement_enabled = 1; @@ -96,6 +102,10 @@ int32_t EnvironmentTelemetryModule::runOnce() result = bme280Sensor.runOnce(); if (mcp9808Sensor.hasSensor()) result = mcp9808Sensor.runOnce(); + if (ina260Sensor.hasSensor()) + result = ina260Sensor.runOnce(); + if (ina219Sensor.hasSensor()) + result = ina219Sensor.runOnce(); } return result; } else { @@ -252,6 +262,10 @@ bool EnvironmentTelemetryModule::sendOurTelemetry(NodeNum dest, bool wantReplies bme680Sensor.getMetrics(&m); if (mcp9808Sensor.hasSensor()) mcp9808Sensor.getMetrics(&m); + if (ina219Sensor.hasSensor()) + ina219Sensor.getMetrics(&m); + if (ina260Sensor.hasSensor()) + ina260Sensor.getMetrics(&m); DEBUG_MSG("Telemetry->time: %i\n", m.time); DEBUG_MSG("Telemetry->barometric_pressure: %f\n", m.variant.environment_metrics.barometric_pressure); diff --git a/src/modules/Telemetry/Sensor/BME280Sensor.cpp b/src/modules/Telemetry/Sensor/BME280Sensor.cpp index 65689b4f0..15ec18007 100644 --- a/src/modules/Telemetry/Sensor/BME280Sensor.cpp +++ b/src/modules/Telemetry/Sensor/BME280Sensor.cpp @@ -11,11 +11,11 @@ BME280Sensor::BME280Sensor() : } int32_t BME280Sensor::runOnce() { - DEBUG_MSG("Init sensor: TelemetrySensorType_BME280\n"); + DEBUG_MSG("Init sensor: %s\n", sensorName); if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } - status = bme280.begin(nodeTelemetrySensorsMap[TelemetrySensorType_BME280]); + status = bme280.begin(nodeTelemetrySensorsMap[sensorType]); return initI2CSensor(); } diff --git a/src/modules/Telemetry/Sensor/BME680Sensor.cpp b/src/modules/Telemetry/Sensor/BME680Sensor.cpp index c12a1fbc0..474c376dd 100644 --- a/src/modules/Telemetry/Sensor/BME680Sensor.cpp +++ b/src/modules/Telemetry/Sensor/BME680Sensor.cpp @@ -10,11 +10,11 @@ BME680Sensor::BME680Sensor() : } int32_t BME680Sensor::runOnce() { - DEBUG_MSG("runOnce: TelemetrySensorType_BME680\n"); + DEBUG_MSG("Init sensor: %s\n", sensorName); if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } - status = bme680.begin(nodeTelemetrySensorsMap[TelemetrySensorType_BME680]); + status = bme680.begin(nodeTelemetrySensorsMap[sensorType]); return initI2CSensor(); } @@ -29,7 +29,6 @@ void BME680Sensor::setup() } bool BME680Sensor::getMetrics(Telemetry *measurement) { - measurement->variant.environment_metrics.temperature = bme680.readTemperature(); measurement->variant.environment_metrics.relative_humidity = bme680.readHumidity(); measurement->variant.environment_metrics.barometric_pressure = bme680.readPressure() / 100.0F; diff --git a/src/modules/Telemetry/Sensor/INA219Sensor.cpp b/src/modules/Telemetry/Sensor/INA219Sensor.cpp new file mode 100644 index 000000000..3e280c526 --- /dev/null +++ b/src/modules/Telemetry/Sensor/INA219Sensor.cpp @@ -0,0 +1,30 @@ +#include "../mesh/generated/telemetry.pb.h" +#include "configuration.h" +#include "TelemetrySensor.h" +#include "INA219Sensor.h" +#include + +INA219Sensor::INA219Sensor() : + TelemetrySensor(TelemetrySensorType_INA219, "INA219") +{ +} + +int32_t INA219Sensor::runOnce() { + DEBUG_MSG("Init sensor: %s\n", sensorName); + if (!hasSensor()) { + return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; + } + ina219 = Adafruit_INA219(nodeTelemetrySensorsMap[sensorType]); + status = ina219.begin(); + return initI2CSensor(); +} + +void INA219Sensor::setup() +{ +} + +bool INA219Sensor::getMetrics(Telemetry *measurement) { + measurement->variant.environment_metrics.voltage = ina219.getBusVoltage_V(); + measurement->variant.environment_metrics.current = ina219.getCurrent_mA(); + return true; +} \ No newline at end of file diff --git a/src/modules/Telemetry/Sensor/INA219Sensor.h b/src/modules/Telemetry/Sensor/INA219Sensor.h new file mode 100644 index 000000000..7e0a3c17e --- /dev/null +++ b/src/modules/Telemetry/Sensor/INA219Sensor.h @@ -0,0 +1,17 @@ +#include "../mesh/generated/telemetry.pb.h" +#include "TelemetrySensor.h" +#include + + +class INA219Sensor : virtual public TelemetrySensor { +private: + Adafruit_INA219 ina219; + +protected: + virtual void setup() override; + +public: + INA219Sensor(); + virtual int32_t runOnce() override; + virtual bool getMetrics(Telemetry *measurement) override; +}; \ No newline at end of file diff --git a/src/modules/Telemetry/Sensor/INA260Sensor.cpp b/src/modules/Telemetry/Sensor/INA260Sensor.cpp new file mode 100644 index 000000000..1c924ad71 --- /dev/null +++ b/src/modules/Telemetry/Sensor/INA260Sensor.cpp @@ -0,0 +1,30 @@ +#include "../mesh/generated/telemetry.pb.h" +#include "configuration.h" +#include "TelemetrySensor.h" +#include "INA260Sensor.h" +#include + +INA260Sensor::INA260Sensor() : + TelemetrySensor(TelemetrySensorType_INA260, "INA260") +{ +} + +int32_t INA260Sensor::runOnce() { + DEBUG_MSG("Init sensor: %s\n", sensorName); + if (!hasSensor()) { + return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; + } + status = ina260.begin(nodeTelemetrySensorsMap[sensorType]); + return initI2CSensor(); +} + +void INA260Sensor::setup() +{ +} + +bool INA260Sensor::getMetrics(Telemetry *measurement) { + // mV conversion to V + measurement->variant.environment_metrics.voltage = ina260.readBusVoltage() / 1000; + measurement->variant.environment_metrics.current = ina260.readCurrent(); + return true; +} \ No newline at end of file diff --git a/src/modules/Telemetry/Sensor/INA260Sensor.h b/src/modules/Telemetry/Sensor/INA260Sensor.h new file mode 100644 index 000000000..789b66c2d --- /dev/null +++ b/src/modules/Telemetry/Sensor/INA260Sensor.h @@ -0,0 +1,17 @@ +#include "../mesh/generated/telemetry.pb.h" +#include "TelemetrySensor.h" +#include + + +class INA260Sensor : virtual public TelemetrySensor { +private: + Adafruit_INA260 ina260 = Adafruit_INA260(); + +protected: + virtual void setup() override; + +public: + INA260Sensor(); + virtual int32_t runOnce() override; + virtual bool getMetrics(Telemetry *measurement) override; +}; \ No newline at end of file diff --git a/src/modules/Telemetry/Sensor/MCP9808Sensor.cpp b/src/modules/Telemetry/Sensor/MCP9808Sensor.cpp index 664416d60..57092d285 100644 --- a/src/modules/Telemetry/Sensor/MCP9808Sensor.cpp +++ b/src/modules/Telemetry/Sensor/MCP9808Sensor.cpp @@ -10,11 +10,11 @@ MCP9808Sensor::MCP9808Sensor() : } int32_t MCP9808Sensor::runOnce() { - DEBUG_MSG("Init sensor: TelemetrySensorType_MCP9808\n"); + DEBUG_MSG("Init sensor: %s\n", sensorName); if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } - status = mcp9808.begin(nodeTelemetrySensorsMap[TelemetrySensorType_MCP9808]); + status = mcp9808.begin(nodeTelemetrySensorsMap[sensorType]); return initI2CSensor(); } From 4458b470aa720da04f96264ad69c52101991f486 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sun, 12 Jun 2022 07:14:33 -0500 Subject: [PATCH 2/4] Don't enable environmental telemetry by default (#1502) * INA219 + INA260 support in telemetry * Protobuf update * Fixes + debug statement * Fix size * Fix conversion from mv * Added getRegisterValue for i2cscan * Accidentally left this in * Removed line --- src/modules/Telemetry/EnvironmentTelemetry.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index ffa4fce0a..b996052f7 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -55,7 +55,6 @@ int32_t EnvironmentTelemetryModule::runOnce() Uncomment the preferences below if you want to use the module without having to configure it from the PythonAPI or WebUI. */ - moduleConfig.telemetry.environment_measurement_enabled = 1; /* moduleConfig.telemetry.environment_measurement_enabled = 1; From 51064335729b03fab2251e8a790749e1122819f1 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sun, 12 Jun 2022 09:44:23 -0500 Subject: [PATCH 3/4] Removed phone_timeout_secs pref references (#1503) --- protobufs | 2 +- src/PowerFSM.cpp | 3 --- src/SerialConsole.cpp | 6 ++++-- src/mesh/NodeDB.h | 1 - src/mesh/generated/config.pb.h | 9 +++------ src/mesh/generated/localonly.pb.h | 2 +- src/mesh/generated/telemetry.pb.h | 8 ++++---- src/modules/AdminModule.cpp | 6 ++---- 8 files changed, 15 insertions(+), 22 deletions(-) diff --git a/protobufs b/protobufs index dbd4219a8..e5b5adc19 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit dbd4219a862b26b5c6fa6569bd8faa42ab8852a5 +Subproject commit e5b5adc196d3593ab15c04101093443ab8b36c9c diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index 0804d62dc..82f73147c 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -348,9 +348,6 @@ void PowerFSM_setup() // See: https://github.com/meshtastic/Meshtastic-device/issues/1071 if (isRouter || config.power.is_power_saving) { - - // I don't think this transition is correct, turning off for now - @geeksville - // powerFSM.add_timed_transition(&stateDARK, &stateNB, getPref_phone_timeout_secs() * 1000, NULL, "Phone timeout"); powerFSM.add_timed_transition(&stateNB, &stateLS, config.power.min_wake_secs ? config.power.min_wake_secs : default_min_wake_secs * 1000, diff --git a/src/SerialConsole.cpp b/src/SerialConsole.cpp index 2d001192b..49e7e017a 100644 --- a/src/SerialConsole.cpp +++ b/src/SerialConsole.cpp @@ -4,6 +4,8 @@ #include "configuration.h" #define Port Serial +// Defaulting to the formerly removed phone_timeout_secs value of 15 minutes +#define SERIAL_CONNECTION_TIMEOUT (15 * 60) * 1000UL SerialConsole *console; @@ -41,12 +43,12 @@ SerialConsole::SerialConsole() : StreamAPI(&Port), RedirectablePrint(&Port) emitRebooted(); } + // For the serial port we can't really detect if any client is on the other side, so instead just look for recent messages bool SerialConsole::checkIsConnected() { uint32_t now = millis(); - uint32_t timeout = (config.power.phone_timeout_secs > 0 ? config.power.phone_timeout_secs : default_phone_timeout_secs )* 1000UL; - return (now - lastContactMsec) < timeout; + return (now - lastContactMsec) < SERIAL_CONNECTION_TIMEOUT; } /** diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index e2ec49a9f..0d6d50ee1 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -168,7 +168,6 @@ extern NodeDB nodeDB; #define default_mesh_sds_timeout_secs IF_ROUTER(NODE_DELAY_FOREVER, 2 * 60 * 60) #define default_sds_secs 365 * 24 * 60 * 60 #define default_ls_secs IF_ROUTER(24 * 60 * 60, 5 * 60) -#define default_phone_timeout_secs 15 * 60 #define default_min_wake_secs 10 diff --git a/src/mesh/generated/config.pb.h b/src/mesh/generated/config.pb.h index 3c137cb02..e59fda04b 100644 --- a/src/mesh/generated/config.pb.h +++ b/src/mesh/generated/config.pb.h @@ -131,7 +131,6 @@ typedef struct _Config_PowerConfig { bool is_power_saving; float adc_multiplier_override; uint32_t wait_bluetooth_secs; - uint32_t phone_timeout_secs; uint32_t mesh_sds_timeout_secs; uint32_t sds_secs; uint32_t ls_secs; @@ -193,14 +192,14 @@ extern "C" { #define Config_init_default {0, {Config_DeviceConfig_init_default}} #define Config_DeviceConfig_init_default {_Config_DeviceConfig_Role_MIN, 0, 0, 0, ""} #define Config_PositionConfig_init_default {0, 0, 0, 0, 0, 0, 0} -#define Config_PowerConfig_init_default {_Config_PowerConfig_ChargeCurrent_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define Config_PowerConfig_init_default {_Config_PowerConfig_ChargeCurrent_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define Config_WiFiConfig_init_default {"", "", 0, 0} #define Config_DisplayConfig_init_default {0, _Config_DisplayConfig_GpsCoordinateFormat_MIN, 0} #define Config_LoRaConfig_init_default {0, _Config_LoRaConfig_ModemPreset_MIN, 0, 0, 0, 0, _Config_LoRaConfig_RegionCode_MIN, 0, 0, 0, {0, 0, 0}} #define Config_init_zero {0, {Config_DeviceConfig_init_zero}} #define Config_DeviceConfig_init_zero {_Config_DeviceConfig_Role_MIN, 0, 0, 0, ""} #define Config_PositionConfig_init_zero {0, 0, 0, 0, 0, 0, 0} -#define Config_PowerConfig_init_zero {_Config_PowerConfig_ChargeCurrent_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define Config_PowerConfig_init_zero {_Config_PowerConfig_ChargeCurrent_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define Config_WiFiConfig_init_zero {"", "", 0, 0} #define Config_DisplayConfig_init_zero {0, _Config_DisplayConfig_GpsCoordinateFormat_MIN, 0} #define Config_LoRaConfig_init_zero {0, _Config_LoRaConfig_ModemPreset_MIN, 0, 0, 0, 0, _Config_LoRaConfig_RegionCode_MIN, 0, 0, 0, {0, 0, 0}} @@ -238,7 +237,6 @@ extern "C" { #define Config_PowerConfig_is_power_saving_tag 5 #define Config_PowerConfig_adc_multiplier_override_tag 6 #define Config_PowerConfig_wait_bluetooth_secs_tag 7 -#define Config_PowerConfig_phone_timeout_secs_tag 8 #define Config_PowerConfig_mesh_sds_timeout_secs_tag 9 #define Config_PowerConfig_sds_secs_tag 10 #define Config_PowerConfig_ls_secs_tag 11 @@ -299,7 +297,6 @@ X(a, STATIC, SINGULAR, UINT32, on_battery_shutdown_after_secs, 4) \ X(a, STATIC, SINGULAR, BOOL, is_power_saving, 5) \ X(a, STATIC, SINGULAR, FLOAT, adc_multiplier_override, 6) \ X(a, STATIC, SINGULAR, UINT32, wait_bluetooth_secs, 7) \ -X(a, STATIC, SINGULAR, UINT32, phone_timeout_secs, 8) \ X(a, STATIC, SINGULAR, UINT32, mesh_sds_timeout_secs, 9) \ X(a, STATIC, SINGULAR, UINT32, sds_secs, 10) \ X(a, STATIC, SINGULAR, UINT32, ls_secs, 11) \ @@ -358,7 +355,7 @@ extern const pb_msgdesc_t Config_LoRaConfig_msg; #define Config_DisplayConfig_size 14 #define Config_LoRaConfig_size 67 #define Config_PositionConfig_size 30 -#define Config_PowerConfig_size 55 +#define Config_PowerConfig_size 49 #define Config_WiFiConfig_size 103 #define Config_size 105 diff --git a/src/mesh/generated/localonly.pb.h b/src/mesh/generated/localonly.pb.h index fccc904e4..df0966414 100644 --- a/src/mesh/generated/localonly.pb.h +++ b/src/mesh/generated/localonly.pb.h @@ -126,7 +126,7 @@ extern const pb_msgdesc_t LocalModuleConfig_msg; #define LocalModuleConfig_fields &LocalModuleConfig_msg /* Maximum encoded size of messages (where known) */ -#define LocalConfig_size 323 +#define LocalConfig_size 317 #define LocalModuleConfig_size 282 #ifdef __cplusplus diff --git a/src/mesh/generated/telemetry.pb.h b/src/mesh/generated/telemetry.pb.h index b7857e2ae..b6d3dc7e6 100644 --- a/src/mesh/generated/telemetry.pb.h +++ b/src/mesh/generated/telemetry.pb.h @@ -69,10 +69,10 @@ typedef struct _EnvironmentMetrics { /* Types of Measurements the telemetry module is equipped to handle */ typedef struct _Telemetry { - /* This is usually not sent over the mesh (to save space), but it is sent - from the phone so that the local device can set its RTC If it is sent over - the mesh (because there are devices on the mesh without GPS), it will only - be sent by devices which has a hardware GPS clock (IE Mobile Phone). + /* This is usually not sent over the mesh (to save space), but it is sent + from the phone so that the local device can set its RTC If it is sent over + the mesh (because there are devices on the mesh without GPS), it will only + be sent by devices which has a hardware GPS clock (IE Mobile Phone). seconds since 1970 */ uint32_t time; /* Key native device metrics such as battery level */ diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index c9b533af6..6d25fd367 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -306,11 +306,10 @@ void AdminModule::handleGetConfig(const MeshPacket &req, const uint32_t configTy break; } - // NOTE: The phone app needs to know the ls_secs & phone_timeout value so it can properly expect sleep behavior. + // NOTE: The phone app needs to know the ls_secs value so it can properly expect sleep behavior. // So even if we internally use 0 to represent 'use default' we still need to send the value we are // using to the app (so that even old phone apps work with new device loads). // r.get_radio_response.preferences.ls_secs = getPref_ls_secs(); - // r.get_radio_response.preferences.phone_timeout_secs = getPref_phone_timeout_secs(); // hideSecret(r.get_radio_response.preferences.wifi_ssid); // hmm - leave public for now, because only minimally private // and useful for users to know current provisioning) hideSecret(r.get_radio_response.preferences.wifi_password); // r.get_config_response.which_payloadVariant = Config_ModuleConfig_telemetry_tag; @@ -363,11 +362,10 @@ void AdminModule::handleGetModuleConfig(const MeshPacket &req, const uint32_t co break; } - // NOTE: The phone app needs to know the ls_secs & phone_timeout value so it can properly expect sleep behavior. + // NOTE: The phone app needs to know the ls_secsvalue so it can properly expect sleep behavior. // So even if we internally use 0 to represent 'use default' we still need to send the value we are // using to the app (so that even old phone apps work with new device loads). // r.get_radio_response.preferences.ls_secs = getPref_ls_secs(); - // r.get_radio_response.preferences.phone_timeout_secs = getPref_phone_timeout_secs(); // hideSecret(r.get_radio_response.preferences.wifi_ssid); // hmm - leave public for now, because only minimally private // and useful for users to know current provisioning) hideSecret(r.get_radio_response.preferences.wifi_password); // r.get_config_response.which_payloadVariant = Config_ModuleConfig_telemetry_tag; From 47ad27f9f68304781c562ed724cd86d2aa19c333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sun, 12 Jun 2022 17:59:16 +0200 Subject: [PATCH 4/4] fix C++ warnings The cast throws errors about ambiguous conversions. There's a prototype of requestFrom(uint8_t address, uint8_t length) so just use that one. --- src/debug/i2cScan.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/debug/i2cScan.h b/src/debug/i2cScan.h index c4ab6a41e..29d7cdc95 100644 --- a/src/debug/i2cScan.h +++ b/src/debug/i2cScan.h @@ -10,7 +10,7 @@ uint16_t getRegisterValue(uint8_t address, uint8_t reg, uint8_t length) { Wire.write(reg); Wire.endTransmission(); delay(20); - Wire.requestFrom((int)address, length); + Wire.requestFrom(address, length); DEBUG_MSG("Wire.available() = %d\n", Wire.available()); if (Wire.available() == 2) { // Read MSB, then LSB