kopia lustrzana https://github.com/mate-dev/meshtastic-matrix-relay
Added serial connection support
rodzic
957a4e3b76
commit
4ce36f8222
18
main.py
18
main.py
|
@ -6,6 +6,7 @@ import logging
|
||||||
import yaml
|
import yaml
|
||||||
import re
|
import re
|
||||||
import meshtastic.tcp_interface
|
import meshtastic.tcp_interface
|
||||||
|
import meshtastic.serial_interface
|
||||||
from nio import AsyncClient, AsyncClientConfig, MatrixRoom, RoomMessageText, RoomMessage
|
from nio import AsyncClient, AsyncClientConfig, MatrixRoom, RoomMessageText, RoomMessage
|
||||||
from pubsub import pub
|
from pubsub import pub
|
||||||
from meshtastic import mesh_pb2
|
from meshtastic import mesh_pb2
|
||||||
|
@ -28,14 +29,23 @@ elif relay_config["logging"]["level"] == "warn":
|
||||||
elif relay_config["logging"]["level"] == "error":
|
elif relay_config["logging"]["level"] == "error":
|
||||||
logger.setLevel(logging.ERROR)
|
logger.setLevel(logging.ERROR)
|
||||||
|
|
||||||
target_host = relay_config["meshtastic"]["host"]
|
|
||||||
|
|
||||||
# Connect to the Meshtastic device
|
# Connect to the Meshtastic device
|
||||||
logger.info(f"Starting Meshtastic <==> Matrix Relay...")
|
logger.info(f"Starting Meshtastic <==> Matrix Relay...")
|
||||||
|
|
||||||
logger.info(f"Connecting to radio at {target_host} ...")
|
# Add a new configuration option to select between serial and network connections
|
||||||
meshtastic_interface = meshtastic.tcp_interface.TCPInterface(hostname=target_host)
|
connection_type = relay_config["meshtastic"]["connection_type"]
|
||||||
logger.info(f"Connected to radio at {target_host}.")
|
|
||||||
|
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
|
matrix_client = None
|
||||||
|
|
||||||
|
|
Plik binarny nie jest wyświetlany.
|
@ -1,12 +1,14 @@
|
||||||
matrix:
|
matrix:
|
||||||
homeserver: "https://scamdemic.wtf"
|
homeserver: "https://example.matrix.org"
|
||||||
access_token: "syt_bWVzaHRhc3RpY2JvdA_TJwsgMiKQmBdpPVIVlaQ_0S5MPm"
|
access_token: "reaalllllyloooooongsecretttttcodeeeeeeforrrrbot"
|
||||||
bot_user_id: "@meshtasticbot:scamdemic.wtf"
|
bot_user_id: "@botuser:example.matrix.org"
|
||||||
room_id: "!phZxXpkkANBjLFBWUB:scamdemic.wtf"
|
room_id: "!someroomid:example.matrix.org"
|
||||||
|
|
||||||
meshtastic:
|
meshtastic:
|
||||||
host: "meshtastic.local"
|
connection_type: serial # Choose either "network" or "serial"
|
||||||
broadcast_enabled: false
|
serial_port: /dev/ttyUSB0 # Only used when connection is "serial"
|
||||||
|
host: "meshtastic.local" # Only used when connection is "network"
|
||||||
|
broadcast_enabled: true
|
||||||
channel: 0
|
channel: 0
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
|
|
Ładowanie…
Reference in New Issue