update:兼容全模块部署,不启动自带的OTA 服务

This commit is contained in:
hrz
2025-04-27 13:07:14 +08:00
parent 5ddc2451c1
commit b46bd4d0dd
4 changed files with 111 additions and 46 deletions
+41 -5
View File
@@ -5,8 +5,11 @@ from config.settings import load_config, check_config_file
from core.websocket_server import WebSocketServer
from core.ota_server import SimpleOtaServer
from core.utils.util import check_ffmpeg_installed
from config.logger import setup_logging
from core.utils.util import get_local_ip
TAG = __name__
logger = setup_logging()
async def wait_for_exit():
@@ -35,10 +38,41 @@ async def main():
# 启动 WebSocket 服务器
ws_server = WebSocketServer(config)
ws_task = asyncio.create_task(ws_server.start())
ota_task = None
# 启动 Simple OAT 服务器
ota_server = SimpleOtaServer(config)
ota_task = asyncio.create_task(ota_server.start())
read_config_from_api = config.get("read_config_from_api", False)
if not read_config_from_api:
# 启动 Simple OAT 服务器
ota_server = SimpleOtaServer(config)
ota_task = asyncio.create_task(ota_server.start())
logger.bind(tag=TAG).info(
"OTA接口是\t\thttp://{}:{}/xiaozhi/ota/",
get_local_ip(),
config["server"]["ota_port"],
)
# 获取WebSocket配置,使用安全的默认值
websocket_port = 8000
server_config = config.get("server", {})
if isinstance(server_config, dict):
websocket_port = int(server_config.get("port", 8000))
logger.bind(tag=TAG).info(
"Websocket地址是\tws://{}:{}/xiaozhi/v1/",
get_local_ip(),
websocket_port,
)
logger.bind(tag=TAG).info(
"=======上面的地址是websocket协议地址,请勿用浏览器访问======="
)
logger.bind(tag=TAG).info(
"如想测试websocket请用谷歌浏览器打开test目录下的test_page.html"
)
logger.bind(tag=TAG).info(
"=============================================================\n"
)
try:
await wait_for_exit() # 监听退出信号
@@ -46,10 +80,12 @@ async def main():
print("任务被取消,清理资源中...")
finally:
ws_task.cancel()
ota_task.cancel()
if ota_task:
ota_task.cancel()
try:
await ws_task
await ota_task
if ota_task:
await ota_task
except asyncio.CancelledError:
pass
print("服务器已关闭,程序退出。")