From 2a6a2bf425508ee5b1c515ac7f11b995d34f6a6d Mon Sep 17 00:00:00 2001 From: Bob Date: Wed, 10 Dec 2025 16:42:55 -0800 Subject: [PATCH] apply nvs changes at end --- esp32_deploy.py | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/esp32_deploy.py b/esp32_deploy.py index cfe7082..a01b321 100755 --- a/esp32_deploy.py +++ b/esp32_deploy.py @@ -105,6 +105,7 @@ class UnifiedDeployWorker: except Exception as e: return False try: + # Initial reset to catch the boot logs (Existing logic) if self.args.config_only: writer.transport.serial.dtr = False writer.transport.serial.rts = True @@ -117,10 +118,42 @@ class UnifiedDeployWorker: self.log.warning("Boot prompt missed...") await self._send_config(writer) - return await self._verify_configuration(reader) - except Exception as e: return False - finally: writer.close(); await writer.wait_closed() + # Verify the config was saved to NVS + is_configured = await self._verify_configuration(reader) + + if is_configured: + self.log.info(f"{Colors.GREEN}Config verified. Resetting device to apply settings...{Colors.RESET}") + await self._perform_reset(writer) + return True + else: + self.log.error(f"{Colors.RED}Config verification failed.{Colors.RESET}") + return False + + except Exception as e: + self.log.error(f"Config Error: {e}") + return False + finally: + writer.close() + await writer.wait_closed() + + async def _perform_reset(self, writer): + """ + Performs a hard reset using DTR/RTS lines to restart the ESP32. + """ + try: + # Standard ESP32 Reset Sequence: + # RTS=True (EN=Low) -> Reset Active + # DTR=False (IO0=High) -> Normal Boot Mode + writer.transport.serial.dtr = False + writer.transport.serial.rts = True + await asyncio.sleep(0.2) # Hold reset for 200ms + + # Release Reset + writer.transport.serial.rts = False + await asyncio.sleep(0.1) + except Exception as e: + self.log.error(f"Failed to reset device: {e}") async def _wait_for_boot(self, reader): timeout = time.time() + 10