Skip to content

Commit

Permalink
Merge pull request #676 from ianmcorvidae/set-time
Browse files Browse the repository at this point in the history
Add a --set-time command that set's the node time using a provided timestamp or the host system clock
  • Loading branch information
ianmcorvidae authored Sep 22, 2024
2 parents de657ba + 40019a9 commit d875a57
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
13 changes: 13 additions & 0 deletions meshtastic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ def onConnected(interface):
if not args.export_config:
print("Connected to radio")

if args.set_time is not None:
interface.getNode(args.dest, False, **getNode_kwargs).setTime(args.set_time)

if args.remove_position:
closeNow = True
waitForAckNak = True
Expand Down Expand Up @@ -1597,6 +1600,16 @@ def initParser():
action="store_true",
)

group.add_argument(
"--set-time",
help="Set the time to the provided unix epoch timestamp, or the system's current time if omitted or 0.",
action="store",
type=int,
nargs="?",
default=None,
const=0,
)

group.add_argument(
"--reply", help="Reply to received messages", action="store_true"
)
Expand Down
15 changes: 15 additions & 0 deletions meshtastic/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,21 @@ def removeFixedPosition(self):
onResponse = self.onAckNak
return self._sendAdmin(p, onResponse=onResponse)

def setTime(self, timeSec: int = 0):
"""Tell the node to set its time to the provided timestamp, or the system's current time if not provided or 0."""
self.ensureSessionKey()
if timeSec == 0:
timeSec = int(time.time())
p = admin_pb2.AdminMessage()
p.set_time_only = timeSec
logging.info(f"Setting node time to {timeSec}")

if self == self.iface.localNode:
onResponse = None
else:
onResponse = self.onAckNak
return self._sendAdmin(p, onResponse=onResponse)

def _fixupChannels(self):
"""Fixup indexes and add disabled channels as needed"""

Expand Down

0 comments on commit d875a57

Please sign in to comment.