Commit Graph

65 Commits

Author SHA1 Message Date
Rafał Wojdyła eb53c61f17 Respect predefined I2C addresses in EnvironmentSensorManager 2026-05-24 13:16:50 +02:00
Josiah VanderZee 4b6b8abe7a Add missing Wire.h include for sensors
This slipped through in PR #2327 and I noticed because the TechoBoard.h
for my variant doesn't include the Wire header, so the source file
in question does not coincidentally obtain a copy.
2026-05-07 07:20:48 -05:00
Liam Cottle bf733f00a6 Merge pull request #2488 from weebl2000/fix-rak-pin-gps-en-undefined
Gate PIN_GPS_EN
2026-05-07 18:44:37 +12:00
Wessel Nieboer 3bde089bdb Gate PIN_GPS_EN
Do not reference it unconditionally
2026-05-07 00:31:15 +02:00
Nick Dunklee c7be216f27 fix(sensors): improve sensor initialization and handling to prevent hangs and handle growth
This is a medium-ish refactor to attempt to clean up sensor handling logic both for board stability and future potential growth before the code becomes all spaghetti and meatballs.

I'd be curious to see if anyone running sensors out there that knows how to build and flash MeshCore code could give this a try and see how it behaves. It is working fine on my end on multiple nodes.

PR notes are gigantic because it is a fundamental behavior repair for sensors, so I wanted to over-explain. Also, if it hadn't been mentioned previously, push-back is always welcome. I'm just spending my time trying to clean up / fix / enhance this corner of the firmware, and want to contribute my improvements back to the project.

**Problem:**

Current MeshCore code makes no attempt to see what sensors are actually available on the I2C bus at startup and blindly tries to interact with sensors. This has some very bad side-effects, like if a sensor that is unsupported, or has a weird initialization process, the MeshCore node will just hang at boot and never successfully start up and ostensibly looks bricked, or the INA226 and SHT4X both sharing the same address and the code just silently fighting.

The current implementation also gloms sensor readouts from the MCU and environment sensors onto the same telemetry channel, with some arbitrary exceptions for incrementing channels based on certain behavioral situations. The MCU temperature and external temperature sensors would appear on channel 1, and it wouldn't be possible to tell which sensor the temperature value was coming from.

Per [CayenneLPP](https://github.com/myDevicesIoT/CayenneLPP): *Data Channel: Uniquely identifies each sensor in the device across frames, eg. “indoor sensor”* So this channel division implementation falls inline with what CayenneLPP intended. There are up to 256 channels available. So I tried to model this change in that behavioral style.

**Proposed Improvement:**

This implementation scans the I2C bus for what devices are present, sets each sensor to its own CayenneLPP channel, and keeps MCU telemetry on channel 1 only. So Channel 1 is always "self" and no confusion can result.

Details:
  - Channel 1 is always the MCU and things about it, so you always know that telemetry is from the board itself. Exception is GPS, GPS stays on channel 1 as well since it is "about the board" even though it's a bit gray-area as GPS can often be a secondary chip.
  - Each sensor board is allocated to a dedicated CayenneLPP channel, so if you are reading from that channel, you know the data is from that sensor only. (Sensors emitting more than one of the same type of measurement are exceptions.)
  - `scanI2CBus()` probes addresses 0x08–0x77 with raw `beginTransmission`/`endTransmission`. No sensor library is touched until after this completes. This will prevent sensor-based boot hangs, unknown or unresponsive devices never reach a library init call.
  - Created `SENSOR_TABLE` a compile-time array that is gated by the existing `ENV_INCLUDE_*` macros. A sentinel `{ 0, nullptr, nullptr, nullptr }` at the end keeps the array non-empty regardless of which sensors are enabled, avoiding zero-length array warnings.
  - When `begin()` is called, scan first, then loop: skip if address not detected, skip if `init()` returns 0, otherwise register one ActiveSensor entry per sub-channel.
  - `querySensors()` I replaced the entire #ifdef chain with a 3-line loop.
  - T1000-E has its own T1000SensorManager, so it should be completely unaffected by this change.
  - SHT4X quirky initialization behavior is retained.
  - MLX90614  - git commits around this didn't have any notes as to why it is reporting ambient temperature on a separate channel as well as the object temperature, as the ambient temperature is used internally to compute the object temperature and not really needed for the sensor's purpose - just the same, kept the existing behavior of reporting the ambient temperature one channel above the channel assigned to the sensor
  - All `bool *_initialized` fields are gone, replaced with `ActiveSensor _active_sensors[16]` (query function pointer and sub-channel index) and `_active_sensor_count. SensorDef` lives entirely in the `.cpp` so the header has no dependency on it.
  - Details on the INA226 and SHT4X: both default to address 0x44, the old code had a bug and would have both begin() calls fire and they would just fight each other silently. In the new code, the respective sensor code is only called if the device is actually present, however, if both were present simultaneously, SHT4X comes first in the table and would win, and INA226 would return false and be skipped. The INA226 has 16 possible addresses that are configurable in the hardware itself, so in a potential scenario where both sensors would be present, the person implementing that design could take that into account.
  - BME680 gas resistance will now transmit on the same channel as the rest of BME680 telemetry which is inline with CayenneLPP standards. Coupling this PR with https://github.com/meshcore-dev/MeshCore/pull/2146 streamline the whole sensor telemetry, and with https://github.com/meshcore-dev/MeshCore/pull/2149 will overall improve BME680 handling. The gas resistance sensor actually has a binary library to make it more useful, calibration, accounting for age of sensor, and other improvements, but since that adds more flash consumption, I have omitted that in PRs thus far.
 - RAK12035 and other current upstream dev branch changes integrated.
2026-04-17 22:23:21 -06:00
Liam Cottle 612aa66fc8 Merge pull request #2075 from pcmoore/working-ina3221
RFE: allow for INA3221 macro overrides in platform.io files
2026-04-12 22:49:17 +12:00
KPrivitt 27f732653b Added RAK12035 Soil Moisture and Temperature Sensor (#2223) 2026-04-03 22:54:24 +13:00
Quency-D 2cbe0c0398 Fixed the initialization error of the BME680 sensor. 2026-04-02 10:24:17 +08:00
Paul Moore 913a27da20 EnvironmentSensorManager: allow for INA3221 macro overrides
Allow for platformio.ini files to override the default values for the
following INA3221 related macros:

  TELEM_INA3221_ADDRESS
  TELEM_INA3221_SHUNT_VALUE
  TELEM_INA3221_NUM_CHANNELS

Signed-off-by: Paul Moore <paul@paul-moore.com>
2026-03-19 21:55:13 -04:00
Liam Cottle 044c66e261 Merge pull request #1001 from kallanreed/fix_gps_debug_logging
Use correct macro for GPS logging test
2026-03-05 13:14:37 +13:00
Wessel Nieboer 8a9a0dca5f Fix GPS +8mA power leak when disabled (nRF52)
On the T114, GPS_RESET (pin 38) is the same pin as PIN_3V3_EN.
MicroNMEALocationProvider::begin() sets pin 38 HIGH (powering the 3V3
rail) but stop() never set it back LOW, leaving the GPS module powered
even when disabled.

Assert reset pin in stop() to mirror begin(), and guard
_location->loop() behind gps_active check.

Fixes meshcore-dev/MeshCore#1628
2026-02-28 19:13:42 +01:00
Piotr Małek 3845a1c021 Fix incorrect INA260 address in debug message 2026-01-27 16:29:31 +01:00
Quency-D fc61018d4d Fix the issue of inconsistent I2C usage in the environmental sensor. 2026-01-23 10:45:13 +08:00
Frieder Schrempf ab7935142c EnvironmentSensorManager.cpp: Cleanup after failed RAK4631 GPS detection
If no GPS was detected, revert the hardware to the initial state,
otherwise we may see conflicts or increased power consumption on some
boards.

Signed-off-by: Frieder Schrempf <frieder@fris.de>
2025-12-31 14:42:42 +01:00
Frieder Schrempf e79ee11872 EnvironmentSensorManager.cpp: Fix RAK4631 serial GPS detection
Serial1 is always true. If we want to check for the presence of a GPS
receiver, we need to check if any data was received.

Signed-off-by: Frieder Schrempf <frieder@fris.de>
2025-12-31 14:42:41 +01:00
entr0p1 cc28b1a34d EnvironmentSensorManager.cpp: Mitigate BME280 self-heating causing inaccurate readings. 2025-12-20 21:51:51 +11:00
agessaman b91b854a1d fix output from LPS22HB: convert barometric pressure from kPa to hPa in EnvironmentSensorManager 2025-12-08 19:53:33 -08:00
Christophe Vanlancker 01eb8716af fix(core): optimize GPS loop and add display GPIO safeguards 2025-12-05 20:45:10 +01:00
csrutil df3cb3d192 _location->loop() should be in the next tick 2025-11-29 20:29:52 +08:00
csrutil 62e180dc0f changed ms to sec 2025-11-29 19:02:00 +08:00
csrutil 88fb173297 add configurable GPS update interval
Make GPS update interval configurable via settings instead of using hardcoded 1 second value. The interval is persisted from preferences and can be adjusted at runtime through the sensor manager settings interface
2025-11-29 17:20:21 +08:00
Florent 1c0017b634 thinknode_m5: gps support 2025-11-28 13:15:11 +01:00
recrof 88a6141943 fix: move bme680 detection before bme280 2025-11-18 15:36:25 +01:00
kallanreed 9e61b56e70 Use correct macro for logging test 2025-10-22 16:44:20 -07:00
Wesley Ellis 4cfbd3bad5 Switch BMP085 mode to 0 for ULTRALOWPOWER 2025-10-22 16:53:11 -04:00
Wesley Ellis ac15131296 Add support for bmp085/bmp180 temperature/pressure sensor 2025-10-22 16:17:06 -04:00
liquidraver 3c48f01601 BME680 library doesn't have altitude calculation, we can add it here to match other sensors' 2025-10-16 11:29:22 +02:00
liquidraver 0e7486552d Add simple BME680 support to RAK with adafruit library 2025-10-16 10:17:23 +02:00
Scott Powell d3be6afccb * fix for non-RAK targets 2025-10-15 22:51:05 +11:00
Scott Powell fa8c31be88 * fix for RAK12500 GPS (I2C) 2025-10-15 22:47:55 +11:00
Florent de Lamotte 341b69e3c9 sensor list command 2025-10-06 14:08:16 +02:00
fdlamotte c83abbeff6 ESM: add gps reset after begin 2025-09-28 09:20:59 +02:00
Florent c1915a1133 ESM: delegate gps management to LocationProvider 2025-09-23 11:12:07 +02:00
ripplebiz 4aa58ade8a Merge pull request #811 from fdlamotte/tracker_l1_environment_sensors
Tracker l1: environment sensors
2025-09-23 15:34:22 +10:00
Florent 611d61b6c6 tracker_l1: fix bme226 init in ESM to include all sensors 2025-09-22 19:10:01 +02:00
Quency-D 669bea04a0 add heltec_v4 board. 2025-09-22 19:58:27 +08:00
Florent f9543bb7bb tracker_l1: support for EnvironmentSensorManager 2025-09-21 22:14:22 +02:00
csrutil cf93109cd5 feat: add altitude support to environment sensor node telemetry
- Include actual node altitude in GPS telemetry instead of hardcoded 0.0f
- Extract altitude data from both ublox_GNSS and serial GPS sources
- Update debug logging to display altitude alongside lat/lon coordinates
2025-09-09 19:20:39 +08:00
recrof d59724acd0 new variant: RAK WisMesh Tag 2025-09-05 16:21:19 +02:00
Alex Wolden 0c37eafd01 Fixed shunt value for ina226 2025-08-21 13:23:05 -07:00
Alex Wolden c636536599 Add INA226 to rak 2025-08-20 22:23:54 -07:00
Martin Kudlacek 822850b4d5 Support for Sensirion SHT4x 2025-07-28 10:02:31 +02:00
Martin Kudlacek a96d1022a0 Added support for TI INA260 2025-07-28 09:41:06 +02:00
taco ef58ef460b fix: BMP280 altitude was using incorrect library 2025-07-28 11:29:55 +10:00
Mike Cochrane 93802fe250 Add VL53L0X time-of-flight distance sensor to Heltec V3 Sensor 2025-07-18 22:01:47 +12:00
Mike Cochrane 9f2a77c92e Add Melexis Contact-less Infrared Sensor - MLX90614 to Heltec V3 Sensor 2025-07-18 18:51:00 +12:00
Mike Cochrane e4f7b9e37f Allow the SDA and SCL pins for Environment sensors to be configured independantly. Add Heltec V3 Sensor. 2025-07-18 18:16:59 +12:00
cod3doomy 6b4592bfe2 Cleanup and fixes
-Added RAK_4631 define back
-Added includes for common RAK sensors that are currently supported in ESM
-Set global variables to static
-Reduced delay time within the RAK gps init sequence
2025-07-17 10:42:18 -07:00
cod3doomy 660ab0692f RAK4631 ESM Migration
Changes to migrate sensor code to the ESM.

Added a separate GPS init sequence for the RAK that scans I2C and Serial1 on the various sockets of the various base boards to find the RAK12500. (and soon the RAK12501)

Removed the GPS specific envs from platformio.ini and enabled GPS for all envs.

Verified working with RAK12500 on RAK19007 sockets A and D, as well as RAK19003.
2025-07-16 19:04:50 -07:00
marcelverdult 58cffa8f76 Fixed Barometric Pressure Reading for BMP280
Measurement has to be divided by 100 same as BME280
2025-07-16 13:50:23 +02:00