Added serial connection support

pull/1/head
Jeremiah K 2023-04-17 20:24:51 -05:00
rodzic 957a4e3b76
commit 4ce36f8222
3 zmienionych plików z 22 dodań i 10 usunięć

12
main.py
Wyświetl plik

@ -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,11 +29,20 @@ 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...")
# 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}.")

BIN
meshtastic.sqlite 100644

Plik binarny nie jest wyświetlany.

Wyświetl plik

@ -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: