Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More robust method of finding Meshtastic device port. #17

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/aprstastic/__about__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2024-present Adam Fourney <[email protected]>
#
# SPDX-License-Identifier: MIT
__version__ = "0.0.1a17"
__version__ = "0.0.1a18"
32 changes: 22 additions & 10 deletions src/aprstastic/_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
import threading
import re
import os
import serial.tools.list_ports
import meshtastic.stream_interface
import meshtastic.serial_interface
from datetime import datetime
from meshtastic.util import message_to_json
from meshtastic.util import findPorts

from queue import Queue, Empty
from .__about__ import __version__
Expand Down Expand Up @@ -162,9 +161,15 @@ def _get_interface(
self, device=None
) -> meshtastic.stream_interface.StreamInterface:
if device is None:
ports = list(serial.tools.list_ports.comports())
ports = meshtastic.util.findPorts(True)
if len(ports) == 1:
device = ports[0].device
device = ports[0]
else:
logger.error(
"Please specify the correct serial port in 'aprstastic.yaml'. "
f"Possible values include: {ports}"
)
return None
if device is not None:
dev = meshtastic.serial_interface.SerialInterface(device)
logger.info(f"Connected to: {device}")
Expand Down Expand Up @@ -213,12 +218,19 @@ def _process_meshtastic_packet(self, packet):
return

if message_string.strip() == "?":
# It seems to send in the opposite order? LIFO?
self._send_mesh_message(
fromId,
"Send and receive APRS messages by registering your call sign. HAM license required.\n\nReply with:\n!register [CALLSIGN]-[SSID]\nE.g.,\n!register N0CALL-1\n\nSee https://github.com/afourney/aprstastic for more.",
)
return
# Different call signs for registered and non-registered devices
if fromId not in self._id_to_call_signs:
self._send_mesh_message(
fromId,
"Send and receive APRS messages by registering your call sign. HAM license required.\n\nReply with:\n!register [CALLSIGN]-[SSID]\nE.g.,\n!register N0CALL-1\n\nSee https://github.com/afourney/aprstastic for more.",
)
return
else:
self._send_mesh_message(
fromId,
"Send APRS messages by replying here, and prefixing your message with the dest callsign. E.g., 'WLNK-1: hello'\n\nSee https://github.com/afourney/aprstastic for more.",
)
return

if message_string.strip() == "!id" or message_string.strip() == "!version":
# Let clients query the gateway call sign and version number
Expand Down
Loading