mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-30 05:13:59 +08:00
Iot (#129)
* 2025-2-17-iot配置消息处理, 以及控制iot命令发送 (#40) * update:优化 * update:增加视频教程 * update:iot兼容性又问题,撤回 * fixed:iot boolean 参数接收bug --------- Co-authored-by: Jiao Haoyang <108573524+XuSenfeng@users.noreply.github.com> Co-authored-by: hrz <1710360675@qq.com>
This commit is contained in:
+3
-1
@@ -41,7 +41,9 @@ manager:
|
|||||||
enabled: false
|
enabled: false
|
||||||
ip: 0.0.0.0
|
ip: 0.0.0.0
|
||||||
port: 8002
|
port: 8002
|
||||||
|
iot:
|
||||||
|
Speaker:
|
||||||
|
volume: 100
|
||||||
xiaozhi:
|
xiaozhi:
|
||||||
type: hello
|
type: hello
|
||||||
version: 1
|
version: 1
|
||||||
|
|||||||
+3
-1
@@ -4,6 +4,7 @@ import uuid
|
|||||||
import time
|
import time
|
||||||
import queue
|
import queue
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import traceback
|
||||||
from config.logger import setup_logging
|
from config.logger import setup_logging
|
||||||
import threading
|
import threading
|
||||||
import websockets
|
import websockets
|
||||||
@@ -149,7 +150,8 @@ class ConnectionHandler:
|
|||||||
await ws.close()
|
await ws.close()
|
||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.bind(tag=TAG).error(f"Connection error: {str(e)}")
|
stack_trace = traceback.format_exc()
|
||||||
|
self.logger.bind(tag=TAG).error(f"Connection error: {str(e)}-{stack_trace}")
|
||||||
await ws.close()
|
await ws.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -44,12 +44,10 @@ class IotDescriptor:
|
|||||||
property_item["description"] = value["description"]
|
property_item["description"] = value["description"]
|
||||||
if value["type"] == "number":
|
if value["type"] == "number":
|
||||||
property_item["value"] = 0
|
property_item["value"] = 0
|
||||||
elif value["type"] == "bool":
|
elif value["type"] == "boolean":
|
||||||
property_item["value"] = False
|
property_item["value"] = False
|
||||||
elif value["type"] == "string":
|
|
||||||
property_item["value"] = ""
|
|
||||||
else:
|
else:
|
||||||
raise ValueError("Invalid type")
|
property_item["value"] = ""
|
||||||
self.properties.append(property_item)
|
self.properties.append(property_item)
|
||||||
|
|
||||||
# 根据描述创建方法
|
# 根据描述创建方法
|
||||||
@@ -75,12 +73,10 @@ class IotDescriptor:
|
|||||||
method[k]["description"] = v["description"]
|
method[k]["description"] = v["description"]
|
||||||
if v["type"] == "number":
|
if v["type"] == "number":
|
||||||
method[k]["value"] = 0
|
method[k]["value"] = 0
|
||||||
elif v["type"] == "bool":
|
elif v["type"] == "boolean":
|
||||||
method[k]["value"] = False
|
method[k]["value"] = False
|
||||||
elif v["type"] == "string":
|
|
||||||
method[k]["value"] = ""
|
|
||||||
else:
|
else:
|
||||||
raise ValueError("Invalid type")
|
method[k]["value"] = ""
|
||||||
|
|
||||||
self.methods.append(method)
|
self.methods.append(method)
|
||||||
|
|
||||||
@@ -92,7 +88,7 @@ async def handleIotDescriptors(conn, descriptors):
|
|||||||
"name":"Speaker",
|
"name":"Speaker",
|
||||||
"description":"当前 AI 机器人的扬声器",
|
"description":"当前 AI 机器人的扬声器",
|
||||||
"properties":{
|
"properties":{
|
||||||
"volume":{"description":"当前音量 值","type":"number"} 可以有bool, int, string三种类型
|
"volume":{"description":"当前音量 值","type":"number"} 可以有boolean, number, string三种类型
|
||||||
},
|
},
|
||||||
"methods":{
|
"methods":{
|
||||||
"SetVolume":{
|
"SetVolume":{
|
||||||
|
|||||||
Reference in New Issue
Block a user