From c8b1b8ea6fe823b0c897f0e5f94868b81d00e2c8 Mon Sep 17 00:00:00 2001 From: Rob <95710162+thatSFguy@users.noreply.github.com> Date: Fri, 26 Dec 2025 15:17:46 -0500 Subject: [PATCH] Filter --reply based on specified channel index Ensures that automatic replies are sent back on the same channel index the message was received on. Previously, all replies defaulted to the primary channel (0), even if the incoming message arrived on a secondary channel. Additionally it ensures incoming messages match the specified channel index. E.g: meshtastic --ch-index 1 --reply . Modified the `onReceive` handler to extract the `channel` index from received packets. This ensures `interface.sendText` targets the originating channel rather than always defaulting to the primary channel. Added a filter to ensure that only the specified channel index is being replied to. --- meshtastic/__main__.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 16854002..99625069 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -85,12 +85,18 @@ def onReceive(packet, interface) -> None: if d is not None and args and args.reply: msg = d.get("text") if msg: - rxSnr = packet["rxSnr"] - hopLimit = packet["hopLimit"] - print(f"message: {msg}") - reply = f"got msg '{msg}' with rxSnr: {rxSnr} and hopLimit: {hopLimit}" - print("Sending reply: ", reply) - interface.sendText(reply) + rxChannel = packet.get("channel", 0) + targetChannel = int(args.ch_index or 0) + if rxChannel == targetChannel: + rxSnr = packet["rxSnr"] + hopLimit = packet["hopLimit"] + print(f"message: {msg}") + reply = f"got msg '{msg}' with rxSnr: {rxSnr} and hopLimit: {hopLimit}" + print(f"Received channel {rxChannel}. Sending reply: {reply}") + interface.sendText(reply,channelIndex=rxChannel) + else: + print(f"Ignored message on channel {rxChannel} (waiting for channel {targetChannel})") + except Exception as ex: print(f"Warning: Error processing received packet: {ex}.")