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 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5 committed 2026-08-06 10:05:40 +02:00
1 parent c7c9b812ab
commit 005773ec4b
2 files changed
+18

No files matched your search

+9
View File
@@ -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
+9
View File
@@ -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();