From e725292ee090cb40fd8eb5414c7d1be764ac0fd1 Mon Sep 17 00:00:00 2001 From: Wolfgang Nagele Date: Sun, 25 Aug 2024 14:39:37 +0200 Subject: [PATCH 1/9] Code block unreachable --- meshtastic/mesh_interface.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/meshtastic/mesh_interface.py b/meshtastic/mesh_interface.py index c83a399..7401b0c 100644 --- a/meshtastic/mesh_interface.py +++ b/meshtastic/mesh_interface.py @@ -975,13 +975,6 @@ class MeshInterface: # pylint: disable=R0902 self.localNode.nodeNum = self.myInfo.my_node_num logging.debug(f"Received myinfo: {stripnl(fromRadio.my_info)}") - failmsg = None - - if failmsg: - self.failure = MeshInterface.MeshInterfaceError(failmsg) - self.isConnected.set() # let waitConnected return this exception - self.close() - elif fromRadio.HasField("metadata"): self.metadata = fromRadio.metadata logging.debug(f"Received device metadata: {stripnl(fromRadio.metadata)}") From b692ef4cfb6b1bef9b70c665c5c30e051240bde0 Mon Sep 17 00:00:00 2001 From: Wolfgang Nagele Date: Sun, 25 Aug 2024 11:11:10 +0200 Subject: [PATCH 2/9] Add method to be able to send heartbeat --- meshtastic/mesh_interface.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/meshtastic/mesh_interface.py b/meshtastic/mesh_interface.py index c83a399..3948089 100644 --- a/meshtastic/mesh_interface.py +++ b/meshtastic/mesh_interface.py @@ -812,19 +812,21 @@ class MeshInterface: # pylint: disable=R0902 lambda: pub.sendMessage("meshtastic.connection.lost", interface=self) ) + def sendHeartbeat(self): + p = mesh_pb2.ToRadio() + p.heartbeat.CopyFrom(mesh_pb2.Heartbeat()) + self._sendToRadio(p) + def _startHeartbeat(self): """We need to send a heartbeat message to the device every X seconds""" def callback(): self.heartbeatTimer = None - i = 300 - logging.debug(f"Sending heartbeat, interval {i} seconds") - if i != 0: - self.heartbeatTimer = threading.Timer(i, callback) - self.heartbeatTimer.start() - p = mesh_pb2.ToRadio() - p.heartbeat.CopyFrom(mesh_pb2.Heartbeat()) - self._sendToRadio(p) + interval = 300 + logging.debug(f"Sending heartbeat, interval {interval} seconds") + self.heartbeatTimer = threading.Timer(interval, callback) + self.heartbeatTimer.start() + self.sendHeartbeat() callback() # run our periodic callback now, it will make another timer if necessary From d77335caa7fde9f2cd0585ab76a38f90213be250 Mon Sep 17 00:00:00 2001 From: Wolfgang Nagele Date: Sun, 25 Aug 2024 22:13:08 +0200 Subject: [PATCH 3/9] Add sendHeartbeat doc-string --- meshtastic/mesh_interface.py | 1 + 1 file changed, 1 insertion(+) diff --git a/meshtastic/mesh_interface.py b/meshtastic/mesh_interface.py index 3948089..36c7ee8 100644 --- a/meshtastic/mesh_interface.py +++ b/meshtastic/mesh_interface.py @@ -813,6 +813,7 @@ class MeshInterface: # pylint: disable=R0902 ) def sendHeartbeat(self): + """Sends a heartbeat to the radio. Can be used to verify the connection is healthy.""" p = mesh_pb2.ToRadio() p.heartbeat.CopyFrom(mesh_pb2.Heartbeat()) self._sendToRadio(p) From 4500850063e0852519265f0b2262ba092c3bc61f Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Thu, 29 Aug 2024 22:29:20 -0500 Subject: [PATCH 4/9] Don't automatically set the time from Python The Python MO is to do as little as possible beyond what the user has intentionally instructed. So don't try to set the time automatically. --- meshtastic/mesh_interface.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/meshtastic/mesh_interface.py b/meshtastic/mesh_interface.py index c59fcb3..fd09e65 100644 --- a/meshtastic/mesh_interface.py +++ b/meshtastic/mesh_interface.py @@ -472,11 +472,6 @@ class MeshInterface: # pylint: disable=R0902 p.altitude = int(altitude) logging.debug(f"p.altitude:{p.altitude}") - if timeSec == 0: - timeSec = int(time.time()) # returns unix timestamp in seconds - p.time = timeSec - logging.debug(f"p.time:{p.time}") - if wantResponse: onResponse = self.onResponsePosition else: From 428e9a228c1c43e32e55f5e7d4597d4d877ecb4f Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Thu, 29 Aug 2024 23:09:04 -0500 Subject: [PATCH 5/9] Remove unused time variable --- meshtastic/mesh_interface.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/meshtastic/mesh_interface.py b/meshtastic/mesh_interface.py index fd09e65..91a8c1f 100644 --- a/meshtastic/mesh_interface.py +++ b/meshtastic/mesh_interface.py @@ -442,7 +442,6 @@ class MeshInterface: # pylint: disable=R0902 latitude: float = 0.0, longitude: float = 0.0, altitude: int = 0, - timeSec: int = 0, destinationId: Union[int, str] = BROADCAST_ADDR, wantAck: bool = False, wantResponse: bool = False, @@ -454,8 +453,6 @@ class MeshInterface: # pylint: disable=R0902 Also, the device software will notice this packet and use it to automatically set its notion of the local position. - If timeSec is not specified (recommended), we will use the local machine time. - Returns the sent packet. The id field will be populated in this packet and can be used to track future message acks/naks. """ From 5c312bedc190271b5c56d53967bb5097df2e1b2a Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Fri, 30 Aug 2024 01:15:40 -0500 Subject: [PATCH 6/9] Remove assert from test, due to removed position time --- meshtastic/tests/test_mesh_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meshtastic/tests/test_mesh_interface.py b/meshtastic/tests/test_mesh_interface.py index f637c62..21f80c6 100644 --- a/meshtastic/tests/test_mesh_interface.py +++ b/meshtastic/tests/test_mesh_interface.py @@ -185,7 +185,7 @@ def test_sendPosition(caplog): with caplog.at_level(logging.DEBUG): iface.sendPosition() iface.close() - assert re.search(r"p.time:", caplog.text, re.MULTILINE) + # assert re.search(r"p.time:", caplog.text, re.MULTILINE) # TODO From aed4f25cf59da8e6081452615fa754f990ad6844 Mon Sep 17 00:00:00 2001 From: Derek Arnold Date: Tue, 3 Sep 2024 17:41:05 -0500 Subject: [PATCH 7/9] Reuse node to prevent overwriting channel settings to be sent out over the admin channel --- meshtastic/__main__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index e7886e6..f78155d 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -778,7 +778,8 @@ def onConnected(interface): channelIndex = mt_config.channel_index if channelIndex is None: meshtastic.util.our_exit("Warning: Need to specify '--ch-index'.", 1) - ch = interface.getNode(args.dest).channels[channelIndex] + node = interface.getNode(args.dest) + ch = node.channels[channelIndex] if args.ch_enable or args.ch_disable: print( @@ -836,7 +837,7 @@ def onConnected(interface): ch.role = channel_pb2.Channel.Role.DISABLED print(f"Writing modified channels to device") - interface.getNode(args.dest).writeChannel(channelIndex) + node.writeChannel(channelIndex) if args.get_canned_message: closeNow = True From a689fd73a29271e00d93641f853c561b9aa787a1 Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Thu, 5 Sep 2024 13:49:28 -0700 Subject: [PATCH 8/9] Deprecate --no-time and remove behavior, followup to #663 --- meshtastic/__main__.py | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index f78155d..a8e1547 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -314,21 +314,6 @@ def onConnected(interface): print("Setting device position and enabling fixed position setting") # can include lat/long/alt etc: latitude = 37.5, longitude = -122.1 interface.localNode.setFixedPosition(lat, lon, alt) - elif not args.no_time: - # We normally provide a current time to the mesh when we connect - if ( - interface.localNode.nodeNum in interface.nodesByNum - and "position" in interface.nodesByNum[interface.localNode.nodeNum] - ): - # send the same position the node already knows, just to update time - position = interface.nodesByNum[interface.localNode.nodeNum]["position"] - interface.sendPosition( - position.get("latitude", 0.0), - position.get("longitude", 0.0), - position.get("altitude", 0.0), - ) - else: - interface.sendPosition() if args.set_owner: closeNow = True @@ -1588,7 +1573,7 @@ def initParser(): group.add_argument( "--no-time", - help="Suppress sending the current time to the mesh", + help="Deprecated. Retained for backwards compatibility in scripts, but is a no-op.", action="store_true", ) From 17f36057365751d23db46557b4eb203e639d5734 Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Thu, 5 Sep 2024 13:58:02 -0700 Subject: [PATCH 9/9] Ensure set-owner combined with set-owner-short sets both values --- meshtastic/__main__.py | 27 ++++++++++++--------------- meshtastic/node.py | 4 ++-- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index a8e1547..3184d2a 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -315,19 +315,16 @@ def onConnected(interface): # can include lat/long/alt etc: latitude = 37.5, longitude = -122.1 interface.localNode.setFixedPosition(lat, lon, alt) - if args.set_owner: + if args.set_owner or args.set_owner_short: closeNow = True waitForAckNak = True - print(f"Setting device owner to {args.set_owner}") - interface.getNode(args.dest, False).setOwner(args.set_owner) - - if args.set_owner_short: - closeNow = True - waitForAckNak = True - print(f"Setting device owner short to {args.set_owner_short}") - interface.getNode(args.dest, False).setOwner( - long_name=None, short_name=args.set_owner_short - ) + if args.set_owner and args.set_owner_short: + print(f"Setting device owner to {args.set_owner} and short name to {args.set_owner_short}") + elif args.set_owner: + print(f"Setting device owner to {args.set_owner}") + else: # short name only + print(f"Setting device owner short to {args.set_owner_short}") + interface.getNode(args.dest, False).setOwner(long_name=args.set_owner, short_name=args.set_owner_short) # TODO: add to export-config and configure if args.set_canned_message: @@ -1452,6 +1449,10 @@ def initParser(): group.add_argument("--set-owner", help="Set device owner name", action="store") + group.add_argument( + "--set-owner-short", help="Set device owner short name", action="store" + ) + group.add_argument( "--set-canned-message", help="Set the canned messages plugin message (up to 200 characters).", @@ -1464,10 +1465,6 @@ def initParser(): action="store", ) - group.add_argument( - "--set-owner-short", help="Set device owner short name", action="store" - ) - group.add_argument( "--set-ham", help="Set licensed Ham ID and turn off encryption", action="store" ) diff --git a/meshtastic/node.py b/meshtastic/node.py index 48b9508..5f5ed7d 100644 --- a/meshtastic/node.py +++ b/meshtastic/node.py @@ -5,7 +5,7 @@ import base64 import logging import time -from typing import Union +from typing import Optional, Union from meshtastic.protobuf import admin_pb2, apponly_pb2, channel_pb2, localonly_pb2, mesh_pb2, portnums_pb2 from meshtastic.util import ( @@ -279,7 +279,7 @@ class Node: return c.index return 0 - def setOwner(self, long_name=None, short_name=None, is_licensed=False): + def setOwner(self, long_name: Optional[str]=None, short_name: Optional[str]=None, is_licensed: bool=False): """Set device owner name""" logging.debug(f"in setOwner nodeNum:{self.nodeNum}") p = admin_pb2.AdminMessage()