Skip to content

Commit 2f5a736

Browse files
committed
Merge remote-tracking branch 'root/master' into pr-powermon
# Conflicts: # meshtastic/ble_interface.py # meshtastic/protobuf/mesh_pb2.py # meshtastic/protobuf/powermon_pb2.py # meshtastic/protobuf/powermon_pb2.pyi
2 parents 6da04f7 + ae904f6 commit 2f5a736

10 files changed

+155
-86
lines changed

meshtastic/__main__.py

+26-17
Original file line numberDiff line numberDiff line change
@@ -1146,20 +1146,24 @@ def addConnectionArgs(parser: argparse.ArgumentParser) -> argparse.ArgumentParse
11461146
outer = parser.add_argument_group('Connection', 'Optional arguments that specify how to connect to a Meshtastic device.')
11471147
group = outer.add_mutually_exclusive_group()
11481148
group.add_argument(
1149-
"--port",
1150-
help="The port of the device to connect to using serial, e.g. /dev/ttyUSB0.",
1149+
"--port", "--serial", "-s",
1150+
help="The port of the device to connect to using serial, e.g. /dev/ttyUSB0. (defaults to trying to detect a port)",
1151+
nargs="?",
1152+
const=None,
11511153
default=None,
11521154
)
11531155

11541156
group.add_argument(
1155-
"--host",
1156-
help="The hostname or IP address of the device to connect to using TCP",
1157+
"--host", "--tcp", "-t",
1158+
help="Connect to a device using TCP, optionally passing hostname or IP address to use. (defaults to '%(const)s')",
1159+
nargs="?",
11571160
default=None,
1161+
const="localhost"
11581162
)
11591163

11601164
group.add_argument(
1161-
"--ble",
1162-
help="Connect to a BLE device, optionally specifying a device name (defaults to 'any')",
1165+
"--ble", "-b",
1166+
help="Connect to a BLE device, optionally specifying a device name (defaults to '%(const)s')",
11631167
nargs="?",
11641168
default=None,
11651169
const="any"
@@ -1483,16 +1487,6 @@ def initParser():
14831487
"--reply", help="Reply to received messages", action="store_true"
14841488
)
14851489

1486-
group.add_argument(
1487-
"--gpio-wrb", nargs=2, help="Set a particular GPIO # to 1 or 0", action="append"
1488-
)
1489-
1490-
group.add_argument("--gpio-rd", help="Read from a GPIO mask (ex: '0x10')")
1491-
1492-
group.add_argument(
1493-
"--gpio-watch", help="Start watching a GPIO mask for changes (ex: '0x10')"
1494-
)
1495-
14961490
group.add_argument(
14971491
"--no-time",
14981492
help="Suppress sending the current time to the mesh",
@@ -1531,7 +1525,7 @@ def initParser():
15311525
"--pos-fields",
15321526
help="Specify fields to send when sending a position. Use no argument for a list of valid values. "
15331527
"Can pass multiple values as a space separated list like "
1534-
"this: '--pos-fields POS_ALTITUDE POS_ALT_MSL'",
1528+
"this: '--pos-fields ALTITUDE HEADING SPEED'",
15351529
nargs="*",
15361530
action="store",
15371531
)
@@ -1621,6 +1615,21 @@ def initParser():
16211615
action="store_true",
16221616
)
16231617

1618+
remoteHardwareArgs = parser.add_argument_group('Remote Hardware', 'Arguments related to the Remote Hardware module')
1619+
1620+
remoteHardwareArgs.add_argument(
1621+
"--gpio-wrb", nargs=2, help="Set a particular GPIO # to 1 or 0", action="append"
1622+
)
1623+
1624+
remoteHardwareArgs.add_argument(
1625+
"--gpio-rd", help="Read from a GPIO mask (ex: '0x10')"
1626+
)
1627+
1628+
remoteHardwareArgs.add_argument(
1629+
"--gpio-watch", help="Start watching a GPIO mask for changes (ex: '0x10')"
1630+
)
1631+
1632+
16241633
have_tunnel = platform.system() == "Linux"
16251634
if have_tunnel:
16261635
tunnelArgs = parser.add_argument_group('Tunnel', 'Arguments related to establishing a tunnel device over the mesh.')

meshtastic/ble_interface.py

+26-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,19 @@
1111
from bleak import BleakClient, BleakScanner, BLEDevice
1212
from bleak.exc import BleakDBusError, BleakError
1313

14+
import google.protobuf
15+
1416
from meshtastic.mesh_interface import MeshInterface
1517

18+
from .protobuf import (
19+
mesh_pb2,
20+
)
1621
SERVICE_UUID = "6ba1b218-15a8-461f-9fa8-5dcae273eafd"
1722
TORADIO_UUID = "f75c76d2-129e-4dad-a1dd-7866124401e7"
1823
FROMRADIO_UUID = "2c55e69e-4993-11ed-b878-0242ac120002"
1924
FROMNUM_UUID = "ed9da18c-a800-4f66-a670-aa7547e34453"
20-
LOGRADIO_UUID = "6c6fd238-78fa-436b-aacf-15c5be1ef2e2"
25+
LEGACY_LOGRADIO_UUID = "6c6fd238-78fa-436b-aacf-15c5be1ef2e2"
26+
LOGRADIO_UUID = "5a3d6e49-06e6-4423-9944-e9de8cdf9547"
2127

2228

2329
class BLEInterface(MeshInterface):
@@ -55,7 +61,11 @@ def __init__(
5561
self.close()
5662
raise e
5763

58-
self.client.start_notify(LOGRADIO_UUID, self.log_radio_handler)
64+
if self.client.has_characteristic(LEGACY_LOGRADIO_UUID):
65+
self.client.start_notify(LEGACY_LOGRADIO_UUID, self.legacy_log_radio_handler)
66+
67+
if self.client.has_characteristic(LOGRADIO_UUID):
68+
self.client.start_notify(LOGRADIO_UUID, self.log_radio_handler)
5969

6070
logging.debug("Mesh configure starting")
6171
self._startConfig()
@@ -80,6 +90,16 @@ def from_num_handler(self, _, b): # pylint: disable=C0116
8090
self.should_read = True
8191

8292
async def log_radio_handler(self, _, b): # pylint: disable=C0116
93+
log_record = mesh_pb2.LogRecord()
94+
try:
95+
log_record.ParseFromString(bytes(b))
96+
except google.protobuf.message.DecodeError:
97+
return
98+
99+
message = f'[{log_record.source}] {log_record.message}' if log_record.source else log_record.message
100+
self._handleLogLine(message)
101+
102+
async def legacy_log_radio_handler(self, _, b): # pylint: disable=C0116
83103
log_radio = b.decode("utf-8").replace("\n", "")
84104
self._handleLogLine(log_radio)
85105

@@ -238,6 +258,10 @@ def read_gatt_char(self, *args, **kwargs): # pylint: disable=C0116
238258
def write_gatt_char(self, *args, **kwargs): # pylint: disable=C0116
239259
self.async_await(self.bleak_client.write_gatt_char(*args, **kwargs))
240260

261+
def has_characteristic(self, specifier):
262+
"""Check if the connected node supports a specified characteristic."""
263+
return bool(self.bleak_client.services.get_characteristic(specifier))
264+
241265
def start_notify(self, *args, **kwargs): # pylint: disable=C0116
242266
self.async_await(self.bleak_client.start_notify(*args, **kwargs))
243267

meshtastic/mesh_interface.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -748,9 +748,8 @@ def _startHeartbeat(self):
748748

749749
def callback():
750750
self.heartbeatTimer = None
751-
prefs = self.localNode.localConfig
752-
i = prefs.power.ls_secs / 2
753-
logging.debug(f"Sending heartbeat, interval {i}")
751+
i = 300
752+
logging.debug(f"Sending heartbeat, interval {i} seconds")
754753
if i != 0:
755754
self.heartbeatTimer = threading.Timer(i, callback)
756755
self.heartbeatTimer.start()

meshtastic/protobuf/config_pb2.py

+44-42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

meshtastic/protobuf/config_pb2.pyi

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class Config(google.protobuf.message.Message):
5656
ROUTER_CLIENT: Config.DeviceConfig._Role.ValueType # 3
5757
"""
5858
Description: Combination of both ROUTER and CLIENT. Not for mobile devices.
59+
Deprecated in v2.3.15 because improper usage is impacting public meshes: Use ROUTER or CLIENT instead.
5960
"""
6061
REPEATER: Config.DeviceConfig._Role.ValueType # 4
6162
"""
@@ -131,6 +132,7 @@ class Config(google.protobuf.message.Message):
131132
ROUTER_CLIENT: Config.DeviceConfig.Role.ValueType # 3
132133
"""
133134
Description: Combination of both ROUTER and CLIENT. Not for mobile devices.
135+
Deprecated in v2.3.15 because improper usage is impacting public meshes: Use ROUTER or CLIENT instead.
134136
"""
135137
REPEATER: Config.DeviceConfig.Role.ValueType # 4
136138
"""

meshtastic/protobuf/deviceonly_pb2.py

+13-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)