feat: Enhance device registration to include name and active slot, supporting remote configuration updates and shutdown.
This commit is contained in:
@@ -33,26 +33,45 @@ class HeadUnit:
|
||||
"serial_number": self.serial_number,
|
||||
"mode": self.mode,
|
||||
"active_slot": self.active_slot,
|
||||
"status": self.status
|
||||
"status": self.status,
|
||||
"name": self.config.get("name", "Unnamed Device")
|
||||
}
|
||||
with open(self.config_path, 'w') as f:
|
||||
json.dump(self.config, f, indent=4)
|
||||
|
||||
def register(self):
|
||||
print(f"[*] Registering device {self.serial_number} ({self.mac_address})...")
|
||||
print(f"[*] Synchronising with mesh orchestration... ({self.serial_number})")
|
||||
try:
|
||||
resp = requests.post(f"{self.server_url}/api/devices/register", json={
|
||||
"serialNumber": self.serial_number,
|
||||
"macAddress": self.mac_address
|
||||
"macAddress": self.mac_address,
|
||||
"activeSlot": self.active_slot,
|
||||
"name": self.config.get("name", "Unnamed Device")
|
||||
})
|
||||
if resp.status_code == 200:
|
||||
data = resp.json()
|
||||
self.status = data.get("status")
|
||||
|
||||
# Adopt remote configuration
|
||||
remote_slot = data.get("activeSlot")
|
||||
if remote_slot and remote_slot != self.active_slot:
|
||||
print(f"[!] Remote slot override: Switching {self.active_slot} -> {remote_slot}")
|
||||
self.active_slot = remote_slot
|
||||
|
||||
remote_name = data.get("name")
|
||||
if remote_name:
|
||||
self.config["name"] = remote_name
|
||||
|
||||
self.save_config()
|
||||
print(f"[+] Registration successful. Status: {self.status}")
|
||||
print(f"[+] Sync successful. Slot: {self.active_slot} | Status: {self.status}")
|
||||
|
||||
if self.status == "OFFLINE":
|
||||
print("[!] Remote instruction: System decommissioned. Shutting down...")
|
||||
return "SHUTDOWN"
|
||||
|
||||
return True
|
||||
else:
|
||||
print(f"[-] Registration failed: {resp.text}")
|
||||
print(f"[-] Synchronisation failed: {resp.text}")
|
||||
except Exception as e:
|
||||
print(f"[-] Connection error: {e}")
|
||||
return False
|
||||
@@ -145,10 +164,17 @@ if __name__ == "__main__":
|
||||
print("\n[*] Entering automated telemetry loop. Press Ctrl+C to return to menu.")
|
||||
try:
|
||||
while True:
|
||||
hu.register()
|
||||
result = hu.register()
|
||||
if result == "SHUTDOWN":
|
||||
print("[!] System shutdown confirmed. Exiting loop.")
|
||||
break
|
||||
|
||||
if hu.status == "ENROLLED":
|
||||
hu.report_test(generate_mock_hdmi_test())
|
||||
time.sleep(5)
|
||||
|
||||
if hu.status == "OFFLINE":
|
||||
break
|
||||
except KeyboardInterrupt:
|
||||
print("\n[!] Loop interrupted by user.")
|
||||
elif choice == "0":
|
||||
|
||||
Reference in New Issue
Block a user