apply nvs changes at end

This commit is contained in:
Bob 2025-12-10 16:42:55 -08:00
parent 1ea05536ab
commit 2a6a2bf425
1 changed files with 36 additions and 3 deletions

View File

@ -105,6 +105,7 @@ class UnifiedDeployWorker:
except Exception as e: return False except Exception as e: return False
try: try:
# Initial reset to catch the boot logs (Existing logic)
if self.args.config_only: if self.args.config_only:
writer.transport.serial.dtr = False writer.transport.serial.dtr = False
writer.transport.serial.rts = True writer.transport.serial.rts = True
@ -117,10 +118,42 @@ class UnifiedDeployWorker:
self.log.warning("Boot prompt missed...") self.log.warning("Boot prompt missed...")
await self._send_config(writer) await self._send_config(writer)
return await self._verify_configuration(reader)
except Exception as e: return False # Verify the config was saved to NVS
finally: writer.close(); await writer.wait_closed() 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): async def _wait_for_boot(self, reader):
timeout = time.time() + 10 timeout = time.time() + 10