From 809b61a0997efc9c411dc2986c856732e2aa2a37 Mon Sep 17 00:00:00 2001 From: David Hall Date: Sat, 7 Mar 2026 14:16:58 +0000 Subject: [PATCH] Upload files to "/" --- exec.sh | 4 +++ sequence-echo.py | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 exec.sh create mode 100644 sequence-echo.py diff --git a/exec.sh b/exec.sh new file mode 100644 index 0000000..1c8b321 --- /dev/null +++ b/exec.sh @@ -0,0 +1,4 @@ +python3 -m venv sequence-echo-env +source sequence-echo-env/bin/activate +pip install meshcore-cli +python3 sequence-echo.py diff --git a/sequence-echo.py b/sequence-echo.py new file mode 100644 index 0000000..22f4399 --- /dev/null +++ b/sequence-echo.py @@ -0,0 +1,70 @@ +import asyncio +import time +from meshcore import MeshCore, EventType + +# --- CONFIGURATION --- +SERIAL_PORT = "/dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0" # Change to your port (e.g., "COM3" on Windows) +CHANNEL_NAME = "#dotmesh" # Target channel +INTERVAL = 60 # Seconds between messages +# --------------------- + +async def send_periodic_sequence(): + # Connect via USB serial + meshcore = await MeshCore.create_serial(SERIAL_PORT) + print(f"Connected to MeshCore on {SERIAL_PORT}") + + # 1. Programmatically look up the channel index + CHANNEL_INDEX = await get_channel_index_by_name(meshcore, CHANNEL_NAME) + + # 2. Safety check: Did we actually find it? + if CHANNEL_INDEX is None: + print(f"Critical Error: Channel '{CHANNEL_NAME}' is not configured on this radio.") + return # Exit the script if we can't find the channel + + print(f"Success: Found '{CHANNEL_NAME}' at index {CHANNEL_INDEX}") + + sequence_number = 0 + + while True: + try: + message = f"Seq: {sequence_number}" + + # 3. Use the dynamically found index to send the message! + await meshcore.commands.send_chan_msg(CHANNEL_INDEX, message) + print(f"Sent: '{message}' to {CHANNEL_NAME} (Index {CHANNEL_INDEX})") + + sequence_number += 1 + await asyncio.sleep(INTERVAL) + + except Exception as e: + print(f"Error: {e}") + await asyncio.sleep(10) + + +async def get_channel_index_by_name(meshcore, target_name): + """ + Queries the device to find the index of a specific channel by name. + """ + print(f"Looking up index for channel '{target_name}'...") + + # Loop through the standard channel slots (0 through 7) + for idx in range(8): + # Fetch the configuration for this channel index + result = await meshcore.commands.get_channel(idx) + + # Check if the command succeeded and has payload data + if result.type != EventType.ERROR and result.payload: + # Print the raw dictionary to see the real keys! + #print(f"Slot {idx} raw data: {result.payload}") + + # We will update this logic once you see the correct key in your terminal + channel_name = result.payload.get('channel_name') + + if channel_name == target_name: + return idx + + return None # Return None if the channel wasn't found on the device + + +if __name__ == "__main__": + asyncio.run(send_periodic_sequence())