diff --git a/main.py b/main.py index 7c0cb94..49b1b9b 100644 --- a/main.py +++ b/main.py @@ -6,6 +6,7 @@ import logging import yaml import re import meshtastic.tcp_interface +import meshtastic.serial_interface from nio import AsyncClient, AsyncClientConfig, MatrixRoom, RoomMessageText, RoomMessage from pubsub import pub from meshtastic import mesh_pb2 @@ -28,14 +29,23 @@ elif relay_config["logging"]["level"] == "warn": elif relay_config["logging"]["level"] == "error": logger.setLevel(logging.ERROR) -target_host = relay_config["meshtastic"]["host"] # Connect to the Meshtastic device logger.info(f"Starting Meshtastic <==> Matrix Relay...") -logger.info(f"Connecting to radio at {target_host} ...") -meshtastic_interface = meshtastic.tcp_interface.TCPInterface(hostname=target_host) -logger.info(f"Connected to radio at {target_host}.") +# Add a new configuration option to select between serial and network connections +connection_type = relay_config["meshtastic"]["connection_type"] + +if connection_type == "serial": + serial_port = relay_config["meshtastic"]["serial_port"] + logger.info(f"Connecting to radio using serial port {serial_port} ...") + meshtastic_interface = meshtastic.serial_interface.SerialInterface(serial_port) + logger.info(f"Connected to radio using serial port {serial_port}.") +else: + target_host = relay_config["meshtastic"]["host"] + logger.info(f"Connecting to radio at {target_host} ...") + meshtastic_interface = meshtastic.tcp_interface.TCPInterface(hostname=target_host) + logger.info(f"Connected to radio at {target_host}.") matrix_client = None diff --git a/meshtastic.sqlite b/meshtastic.sqlite new file mode 100644 index 0000000..9ac2eb1 Binary files /dev/null and b/meshtastic.sqlite differ diff --git a/sample_config.yaml b/sample_config.yaml index 18a124b..dfae6db 100644 --- a/sample_config.yaml +++ b/sample_config.yaml @@ -1,12 +1,14 @@ matrix: - homeserver: "https://scamdemic.wtf" - access_token: "syt_bWVzaHRhc3RpY2JvdA_TJwsgMiKQmBdpPVIVlaQ_0S5MPm" - bot_user_id: "@meshtasticbot:scamdemic.wtf" - room_id: "!phZxXpkkANBjLFBWUB:scamdemic.wtf" + homeserver: "https://example.matrix.org" + access_token: "reaalllllyloooooongsecretttttcodeeeeeeforrrrbot" + bot_user_id: "@botuser:example.matrix.org" + room_id: "!someroomid:example.matrix.org" meshtastic: - host: "meshtastic.local" - broadcast_enabled: false + connection_type: serial # Choose either "network" or "serial" + serial_port: /dev/ttyUSB0 # Only used when connection is "serial" + host: "meshtastic.local" # Only used when connection is "network" + broadcast_enabled: true channel: 0 logging: