+
+
+
+ Connected Devices Overview
+
+ Refresh
+
+
+
+
+
+
+
{{ connectedDevices.total || 0 }}
+
Total Devices
+
+
+
+
+
{{ connectedDevices.activeToday || 0 }}
+
Active Today
+
+
+
+
+
Firmware Versions in Use:
+
+
+ {{ version }} ({{ count }} devices)
+
+
+
+
+
+
+
+
item.key === type)
return firmwareType ? firmwareType.name : type
},
+ fetchConnectedDevices() {
+ // Fetch connected devices statistics
+ // This would call an API endpoint to get device statistics
+ // For now, we'll use the device management API to get device info
+ const currentAgentId = localStorage.getItem('agentId') || this.$route.query.agentId;
+ if (currentAgentId) {
+ Api.device.getAgentBindDevices(currentAgentId, ({data}) => {
+ if (data.code === 0 && data.data) {
+ const devices = data.data;
+ this.connectedDevices.total = devices.length;
+
+ // Count devices active today
+ const today = new Date();
+ today.setHours(0, 0, 0, 0);
+ this.connectedDevices.activeToday = devices.filter(device => {
+ const lastConnected = new Date(device.lastConnectedAt);
+ return lastConnected >= today;
+ }).length;
+
+ // Calculate version distribution
+ const versionMap = {};
+ devices.forEach(device => {
+ const version = device.appVersion || 'Unknown';
+ versionMap[version] = (versionMap[version] || 0) + 1;
+ });
+ this.connectedDevices.versionDistribution = versionMap;
+ }
+ });
+ }
+ },
},
};
@@ -481,6 +556,45 @@ export default {
flex-direction: column;
}
+.device-summary-card {
+ background: white;
+ border: none;
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
+
+ ::v-deep .el-card__header {
+ background: linear-gradient(135deg, #f5f7fa 0%, #f0f3f8 100%);
+ padding: 12px 20px;
+ border-bottom: 1px solid #e4e7ed;
+ }
+
+ .device-stats {
+ padding: 10px 0;
+
+ .stat-item {
+ text-align: center;
+ padding: 10px;
+
+ .stat-value {
+ font-size: 28px;
+ font-weight: bold;
+ color: #409eff;
+ margin-bottom: 5px;
+ }
+
+ .stat-label {
+ font-size: 14px;
+ color: #606266;
+ margin-bottom: 8px;
+ }
+
+ .version-list {
+ margin-top: 8px;
+ text-align: left;
+ }
+ }
+ }
+}
+
.params-card {
background: white;
flex: 1;
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/core/providers/tools/device_mcp/mcp_handler.py b/main/xiaozhi-server/core/providers/tools/device_mcp/mcp_handler.py
index da4b311ed..b0d4c2261 100644
--- a/main/xiaozhi-server/core/providers/tools/device_mcp/mcp_handler.py
+++ b/main/xiaozhi-server/core/providers/tools/device_mcp/mcp_handler.py
@@ -30,6 +30,14 @@ async def send_mcp_message(conn, payload: dict):
async def handle_mcp_message(conn, mcp_client, payload: dict):
"""Handle MCP messages, including initialization, tool list and tool call responses"""
logger.bind(tag=TAG).info(f"Handling MCP message: {str(payload)[:100]}")
+
+ # Log device initialization request details
+ if "method" in payload and payload["method"] == "initialize":
+ params = payload.get("params", {})
+ client_info = params.get("clientInfo", {})
+ logger.bind(tag=TAG).info(
+ f"Device initialization request received - Client: {client_info.get('name', 'unknown')} v{client_info.get('version', 'unknown')}"
+ )
if not isinstance(payload, dict):
logger.bind(tag=TAG).error(
@@ -51,12 +59,56 @@ async def handle_mcp_message(conn, mcp_client, payload: dict):
if msg_id == 1: # mcpInitializeID
logger.bind(tag=TAG).debug("Received MCP initialization response")
- server_info = result.get("serverInfo")
+
+ # Extract all relevant information
+ protocol_version = result.get("protocolVersion", "unknown")
+ capabilities = result.get("capabilities", {})
+ server_info = result.get("serverInfo", {})
+
if isinstance(server_info, dict):
- name = server_info.get("name")
- version = server_info.get("version")
+ name = server_info.get("name", "unknown")
+ version = server_info.get("version", "unknown")
+
+ # Store firmware info in connection object for later use
+ conn.device_firmware_info = {
+ 'name': name,
+ 'version': version,
+ 'protocol_version': protocol_version,
+ 'capabilities': capabilities,
+ 'timestamp': asyncio.get_event_loop().time()
+ }
+
+ # Enhanced logging with more prominent firmware version display
logger.bind(tag=TAG).info(
- f"Client MCP server info: name={name}, version={version}"
+ f"="*60
+ )
+ logger.bind(tag=TAG).info(
+ f"DEVICE CONNECTED - Firmware Details:"
+ )
+ logger.bind(tag=TAG).info(
+ f" Device Name: {name}"
+ )
+ logger.bind(tag=TAG).info(
+ f" Firmware Version: {version}"
+ )
+ logger.bind(tag=TAG).info(
+ f" Protocol Version: {protocol_version}"
+ )
+ logger.bind(tag=TAG).info(
+ f" Device ID: {conn.headers.get('device-id', 'unknown')}"
+ )
+ logger.bind(tag=TAG).info(
+ f" MAC Address: {conn.headers.get('device-id', 'unknown').replace('_', ':').upper()}"
+ )
+ logger.bind(tag=TAG).info(
+ f" Capabilities: {list(capabilities.keys()) if capabilities else 'none'}"
+ )
+ logger.bind(tag=TAG).info(
+ f"="*60
+ )
+ else:
+ logger.bind(tag=TAG).warning(
+ f"Device initialization response missing serverInfo: {result}"
)
return
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