From 8ff30a0215735d16758254f9eb6e928d3563cc73 Mon Sep 17 00:00:00 2001 From: rahulpscraftech360 Date: Sat, 23 Aug 2025 16:12:14 +0530 Subject: [PATCH] device activation working --- main/xiaozhi-server/core/api/ota_handler.py | 1 + main/xiaozhi-server/test_ota_activation.py | 95 +++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 main/xiaozhi-server/test_ota_activation.py diff --git a/main/xiaozhi-server/core/api/ota_handler.py b/main/xiaozhi-server/core/api/ota_handler.py index cbabbdd30..79449658a 100644 --- a/main/xiaozhi-server/core/api/ota_handler.py +++ b/main/xiaozhi-server/core/api/ota_handler.py @@ -5,6 +5,7 @@ import base64 import hmac import hashlib import os +import aiohttp from aiohttp import web from core.utils.util import get_local_ip from core.api.base_handler import BaseHandler diff --git a/main/xiaozhi-server/test_ota_activation.py b/main/xiaozhi-server/test_ota_activation.py new file mode 100644 index 000000000..a6228d494 --- /dev/null +++ b/main/xiaozhi-server/test_ota_activation.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python3 +""" +Test script to verify OTA activation code generation +""" + +import json +import asyncio +import httpx + +async def test_ota_endpoint(): + """Test the OTA endpoint with a sample device""" + + # Sample device data (similar to what your ESP32 sends) + device_data = { + "version": 176, + "flash_size": 4194304, + "minimum_free_heap_size": 186020, + "mac_address": "68:25:dd:bb:4d:44", + "uuid": "848fc4d1-3db0-42e5-a0e6-e60a9b4477d8", + "chip_model_name": "ESP32", + "chip_info": { + "model": 1, + "cores": 2, + "revision": 301, + "features": 62 + }, + "application": { + "name": "Xiaozhi_ESP32", + "version": "1.7.6", + "compile_time": "2025-08-23T10:00:00Z", + "idf_version": "v5.2.1", + "elf_sha256": "d4e77c78a2f8a0b4b2e1c4e77c78a2f8a0b4b2e1" + }, + "partition_table": [], + "ota": { + "label": "ota_0" + }, + "board": { + "type": "doit-ai-01-kit", + "ssid": "TestWiFi", + "rssi": -45, + "channel": 6, + "ip": "192.168.1.74", + "mac": "68:25:dd:bb:4d:44" + } + } + + # OTA endpoint URL + ota_url = "http://192.168.1.105:8003/xiaozhi/ota/" + + # Headers that the device sends + headers = { + "device-id": "68:25:dd:bb:4d:44", + "Content-Type": "application/json" + } + + print(f"Testing OTA endpoint: {ota_url}") + print(f"Device ID: {headers['device-id']}") + print(f"Device firmware: {device_data['application']['version']}") + print("-" * 50) + + try: + async with httpx.AsyncClient() as client: + response = await client.post( + ota_url, + headers=headers, + json=device_data, + timeout=10.0 + ) + + print(f"Response status: {response.status_code}") + + if response.status_code == 200: + result = response.json() + print(f"Response data: {json.dumps(result, indent=2)}") + + # Check if activation code is present + if "activation" in result: + activation = result["activation"] + print("\n" + "=" * 50) + print("ACTIVATION CODE RECEIVED!") + print(f"Code: {activation.get('code')}") + print(f"Message: {activation.get('message')}") + print("=" * 50) + else: + print("\nNo activation code in response") + + else: + print(f"Error response: {response.text}") + + except Exception as e: + print(f"Error testing OTA endpoint: {e}") + +if __name__ == "__main__": + asyncio.run(test_ota_endpoint()) \ No newline at end of file