From 005773ec4b2b14ca470b208296648aefbfaa009e Mon Sep 17 00:00:00 2001 From: TeTeHacko Date: Thu, 6 Aug 2026 10:05:40 +0200 Subject: [PATCH] feat(cli): `i2c` -- scan the bus on a live node begin() already scans I2C before touching any sensor library, but only into a MESH_DEBUG log nobody has on a deployed node. So "is that sensor actually there?" was answerable only by inference from telemetry, and inference is what produced `TELEM_INA226_ADDRESS=0x40` in our SenseCap envs: a guard against false-detecting SHT41 at the library default 0x44, written as if an INA226 existed. It does not. `i2c` on bench-rpt answers "no I2C device" -- the variant has a single bus (WIRE_INTERFACES_COUNT 1) and nothing on it. That closed a whole line of "measure the solar node with its own current sensor" work. Output leads with what answered, then lists the table addresses that stayed quiet, deduplicated and as bare hex: names for three entries sharing 0x76 alone overran the 150 B mesh reply and truncated the interesting part. Co-Authored-By: Claude Opus 5 --- src/helpers/CommonCLI.cpp | 9 +++++++++ src/helpers/SensorManager.h | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/helpers/CommonCLI.cpp b/src/helpers/CommonCLI.cpp index 0c151218..d7e904af 100644 --- a/src/helpers/CommonCLI.cpp +++ b/src/helpers/CommonCLI.cpp @@ -378,6 +378,15 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, char* command, char* re *(dp-1) = 0; // remove last CR } } + } else if (memcmp(command, "i2c", 3) == 0) { + // Live bus scan. `sensor read` only shows what got initialised, so a + // sensor that is absent and one whose address is wrong look identical + // there; this separates the two. + // 150 = what one LoRa packet carries, i.e. the smallest reply buffer any + // caller of CommonCLI passes (the local console's is far bigger, but + // CommonCLI is not told which one it got). + int n = _sensors->scanI2C(reply, 150); + if (n < 0) strcpy(reply, "no I2C bus on this build"); } else if (memcmp(command, "sensor read", 11) == 0) { // Decode the live telemetry (the same CayenneLPP payload sent over the // mesh) into a human-readable line. `sensor list` only exposes settings diff --git a/src/helpers/SensorManager.h b/src/helpers/SensorManager.h index 89a174c2..9558f123 100644 --- a/src/helpers/SensorManager.h +++ b/src/helpers/SensorManager.h @@ -24,6 +24,15 @@ public: virtual bool setSettingValue(const char* name, const char* value) { return false; } virtual LocationProvider* getLocationProvider() { return NULL; } + // Live I2C scan, written into dest as text. Returns the number of devices + // that answered, or -1 when the platform has no bus to scan. + // + // begin() already scans the bus, but only into a MESH_DEBUG log nobody has on + // a deployed node -- so "is that sensor actually there?" was answerable only + // by inference from telemetry, and inference is what produced a build flag + // pointing INA226 at 0x40 to dodge a false detect at 0x44 (SHT41's address). + virtual int scanI2C(char* dest, size_t max_len) { (void)dest; (void)max_len; return -1; } + // Helper functions to manage setting by keys (useful in many places ...) const char* getSettingByKey(const char* key) { int num = getNumSettings();