From 355e4609eb9c03165eef25ab6f0b5f0031d5ab00 Mon Sep 17 00:00:00 2001 From: TeTeHacko Date: Tue, 4 Aug 2026 19:26:03 +0200 Subject: [PATCH] feat(repeater/bot): sender ignore list + command whitelist so two bots share one channel #tth-test already had a bot: tracker (Solo firmware), which also puts "Ping" on the channel by itself. Measured consequence of running a second bot there with no coordination, over a few minutes: the counter went 2 -> 9, i.e. seven of the replies went to tracker rather than to a person, and because the cooldown is one per channel, a human question then landed in a closed window. One of four probes got no answer for exactly that reason. Worth stating because it corrects an earlier guess of mine: that miss was NOT an RF problem. Replies arrive DIRECT (0 hops) at SNR +13.5..14.25 dB, and SF7 demodulates down to about -7.5 dB, so at 2 dBm there is ~20 dB of margin. More TX power would have bought nothing; the fix was arbitration, not watts. Two build-time knobs, both defaulting to today's behaviour: BOT_IGNORE_SENDERS comma-separated node names, dropped before trigger and command matching. Verified live: `ignored` incremented on a real tracker message. BOT_COMMANDS whitelist of !commands this node answers, "" = all. Matching for both is EXACT and case-insensitive, deliberately unlike botTriggerMatches()' substring search -- a substring ignore list would let a node called "TTH" silence "tracker", and a substring whitelist would let "path" enable "!pathx". Adds !noise (noise floor), which is in the same spirit as !snr and !heard: things a companion bot cannot answer at all because it has no analyzer. `bot` now also reports the whitelist, the ignore list and an ignored counter, so the arbitration is inspectable from the console instead of inferred. Deployed split: x3 answers only !snr/!heard/!noise and has NO bare-word trigger, so it never speaks into ordinary traffic; !path/!ping stay with tracker. Verified live -- !path drew exactly one answer, from tracker. Co-Authored-By: Claude Opus 5 (1M context) --- examples/simple_repeater/ChannelBot.h | 65 +++++++++++++++++++++++++-- examples/simple_repeater/MyMesh.h | 1 + 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/examples/simple_repeater/ChannelBot.h b/examples/simple_repeater/ChannelBot.h index b57a5885..0d42ccbb 100644 --- a/examples/simple_repeater/ChannelBot.h +++ b/examples/simple_repeater/ChannelBot.h @@ -30,10 +30,24 @@ #ifdef BOT_CHANNEL_PSK -// Comma-separated, case-insensitive substrings; "*" answers anything. +// Comma-separated, case-insensitive substrings; "*" answers anything, "" never. #ifndef BOT_TRIGGER #define BOT_TRIGGER "ping,test" #endif +// Senders whose messages are skipped outright, comma-separated node names. +// This is what keeps two bots on one channel from feeding each other: with +// tracker (Solo firmware) periodically putting "Ping" on #tth-test, an +// unfiltered trigger list made this node answer every one of them and burn the +// cooldown, so a human asking a question got silence. +#ifndef BOT_IGNORE_SENDERS + #define BOT_IGNORE_SENDERS "" +#endif +// Whitelist of `!commands` this node answers, comma-separated, "" = all. +// The point is complementarity: two bots answering !path means two packets and +// one duplicate. Give each node the commands only it can answer well. +#ifndef BOT_COMMANDS + #define BOT_COMMANDS "" +#endif // The ONLY throttle on a node that is otherwise pure RX. Keep it generous: // every reply is a flood packet on a shared community mesh. #ifndef BOT_REPLY_COOLDOWN_MS @@ -60,6 +74,7 @@ void MyMesh::botInit() { bot_channel_valid = false; bot_next_reply_at = 0; bot_replies_sent = 0; + bot_ignored = 0; bot_last_reply_secs = 0; memset(&bot_channel, 0, sizeof(bot_channel)); @@ -121,10 +136,41 @@ void MyMesh::botFormatPath(char* out, const mesh::Packet* pkt) const { *p = 0; } +// Exact, case-insensitive membership in a comma-separated list. Distinct from +// botTriggerMatches(), which is a SUBSTRING search: an ignore list or a command +// whitelist matching on substrings would be a trap ("path" enabling "!pathx", +// a node called "TTH" silencing "tracker"). +static bool bot_list_has(const char* list, const char* word) { + const char* seg = list; + while (*seg) { + const char* comma = strchr(seg, ','); + int len = comma ? (int)(comma - seg) : (int)strlen(seg); + while (len > 0 && *seg == ' ') { seg++; len--; } + while (len > 0 && seg[len - 1] == ' ') len--; + if (len > 0 && (int)strlen(word) == len) { + int i = 0; + while (i < len && tolower((unsigned char)word[i]) == tolower((unsigned char)seg[i])) i++; + if (i == len) return true; + } + if (!comma) break; + seg = comma + 1; + } + return false; +} + // One `!command` -> one text fragment. Returns chars written, 0 for unknown. // The interesting ones are the analyzer's: a companion bot cannot answer these // at all, because it has no rxlog and no heard registry. int MyMesh::botCommandReply(char* out, int max_len, const char* cmd, const mesh::Packet* pkt) { + // An empty BOT_COMMANDS means "all"; otherwise only what is listed. + if (BOT_COMMANDS[0] != 0 && !bot_list_has(BOT_COMMANDS, cmd)) return 0; + + if (strcmp(cmd, "noise") == 0) { + // Noise floor is the analyzer's own measurement -- a companion bot has no + // way to answer this, which makes it worth owning on a shared channel. + return snprintf(out, max_len, "noise floor %d dBm", + (int)(int16_t)_radio->getNoiseFloor()); + } if (strcmp(cmd, "ping") == 0) { return snprintf(out, max_len, "pong"); } @@ -265,6 +311,14 @@ void MyMesh::onGroupDataRecv(mesh::Packet* packet, uint8_t type, const mesh::Gro if (sep) { *sep = 0; if (strcmp(text, _prefs.node_name) == 0) return; + // Peer bots: skip before any trigger or command matching. Measured need -- + // tracker puts "Ping" on this channel by itself, and answering those ate the + // cooldown, so a human question landed in a closed window. + if (BOT_IGNORE_SENDERS[0] != 0 && bot_list_has(BOT_IGNORE_SENDERS, text)) { + bot_ignored++; + MESH_DEBUG_PRINTLN("bot: ignoruji odesilatele z BOT_IGNORE_SENDERS"); + return; + } msg = sep + 2; } @@ -296,9 +350,12 @@ bool MyMesh::botHandleCommand(const char* command, char* reply) { strcpy(reply, "bot: DISABLED (bad BOT_CHANNEL_PSK)"); return true; } - sprintf(reply, "bot: chan hash %02X, trigger '%s', cooldown %d ms, replies %u, last %u", - (uint32_t)bot_channel.hash[0], BOT_TRIGGER, (int)BOT_REPLY_COOLDOWN_MS, - (uint32_t)bot_replies_sent, (uint32_t)bot_last_reply_secs); + sprintf(reply, "bot: chan %02X, trigger '%s', cmds '%s', ignore '%s', cooldown %d ms, replies %u, ignored %u, last %u", + (uint32_t)bot_channel.hash[0], BOT_TRIGGER, + BOT_COMMANDS[0] ? BOT_COMMANDS : "(vse)", + BOT_IGNORE_SENDERS[0] ? BOT_IGNORE_SENDERS : "(nikdo)", + (int)BOT_REPLY_COOLDOWN_MS, (uint32_t)bot_replies_sent, + (uint32_t)bot_ignored, (uint32_t)bot_last_reply_secs); return true; } diff --git a/examples/simple_repeater/MyMesh.h b/examples/simple_repeater/MyMesh.h index 2a139fb7..0462e519 100644 --- a/examples/simple_repeater/MyMesh.h +++ b/examples/simple_repeater/MyMesh.h @@ -215,6 +215,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks { bool bot_channel_valid; // false = PSK malformed, bot silently off unsigned long bot_next_reply_at; // cooldown gate, 0 = not armed uint32_t bot_replies_sent; + uint32_t bot_ignored; // zprav zahozenych podle BOT_IGNORE_SENDERS uint32_t bot_last_reply_secs; // RTC time of the last reply, 0 = never #endif CayenneLPP telemetry;