From 6812f508bcb9c9b8e9c2c2121d8873a3b32cd0b2 Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Thu, 25 Apr 2024 11:17:15 -0700 Subject: [PATCH] Add --enter-dfu for entering DFU mode on NRF52 devices via admin message --- meshtastic/__main__.py | 13 ++++++++++++- meshtastic/node.py | 13 +++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index b61fe962..159435a8 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -375,6 +375,11 @@ def onConnected(interface): waitForAckNak = True interface.getNode(args.dest, False).rebootOTA() + if args.enter_dfu: + closeNow = True + waitForAckNak = True + interface.getNode(args.dest, False).enterDFUMode() + if args.shutdown: closeNow = True waitForAckNak = True @@ -1364,7 +1369,13 @@ def initParser(): group.add_argument( "--reboot-ota", - help="Tell the destination node to reboot into factory firmware", + help="Tell the destination node to reboot into factory firmware (ESP32)", + action="store_true", + ) + + group.add_argument( + "--enter-dfu", + help="Tell the destination node to enter DFU mode (NRF52)", action="store_true", ) diff --git a/meshtastic/node.py b/meshtastic/node.py index 0f6fb995..156fbba9 100644 --- a/meshtastic/node.py +++ b/meshtastic/node.py @@ -571,6 +571,19 @@ def rebootOTA(self, secs: int = 10): onResponse = self.onAckNak return self._sendAdmin(p, onResponse=onResponse) + def enterDFUMode(self): + """Tell the node to enter DFU mode (NRF52).""" + p = admin_pb2.AdminMessage() + p.enter_dfu_mode_request = True + logging.info(f"Telling node to enable DFU mode") + + # If sending to a remote node, wait for ACK/NAK + if self == self.iface.localNode: + onResponse = None + else: + onResponse = self.onAckNak + return self._sendAdmin(p, onResponse=onResponse) + def shutdown(self, secs: int = 10): """Tell the node to shutdown.""" p = admin_pb2.AdminMessage()