diff --git a/apps/socket/README.md b/apps/socket/README.md
index e69de29..e2533f6 100644
--- a/apps/socket/README.md
+++ b/apps/socket/README.md
@@ -0,0 +1,9 @@
+
+```sh
+# 安装 python 环境 ,安装项目
+uv sync
+
+uv run python main.py
+
+pm2 start "uv run app.py" --name "dnake-socket-app"
+```
diff --git a/docs/package.json b/docs/package.json
index d199771..c4dd01b 100644
--- a/docs/package.json
+++ b/docs/package.json
@@ -1,6 +1,6 @@
{
"name": "@kevisual/me-dnake-docs",
- "version": "0.0.1",
+ "version": "0.0.2",
"description": "",
"main": "index.js",
"basename": "/root/me-dnake-docs",
@@ -8,7 +8,7 @@
"dev": "astro dev",
"build": "astro build",
"preview": "astro preview",
- "pub": "envision deploy ./dist -k me-dnake-docs -v 0.0.1 -u",
+ "pub": "envision deploy ./dist -k me-dnake-docs -v 0.0.2 -u",
"sn": "pnpm dlx shadcn@latest add "
},
"keywords": [],
diff --git a/docs/src/pages/home.mdx b/docs/src/pages/home.mdx
new file mode 100644
index 0000000..1d44e5e
--- /dev/null
+++ b/docs/src/pages/home.mdx
@@ -0,0 +1,48 @@
+# home配置文档
+
+## configuration.yaml
+
+配置调用rest_command服务,文件地址在 docker 内部根目录下,`config/configuration.yaml` 位置
+
+添加以下内容
+```yaml
+rest_command:
+ set_floor_notify:
+ url: http://host.docker.internal:3001/api/router?path=floor
+ method: POST
+ content_type: application/json
+```
+然后配置脚本位置 `config/scripts.yaml` 文件,添加以下内容
+(scripts 被 configuration.yaml 引用)
+
+```yaml
+notify_floor:
+ alias: "发送楼层消息"
+ description: "通过本地服务发送楼层通知"
+ sequence:
+ - service: rest_command.set_floor_notify
+```
+## 触发使用
+home 可视化页面可以编辑自动化,编辑后台也可以,在 automations.yaml 文件中添加以下类似内容
+
+```yaml
+- id: '1760892271622'
+ alias: 打开电梯
+ description: 打开电梯,上13楼来
+ triggers:
+ - trigger: state
+ entity_id:
+ - event.xiaomi_cn_1076466578_hub1_virtual_event_e_4_1
+ from:
+ to:
+ conditions:
+ - condition: state
+ entity_id: event.xiaomi_cn_1076466578_hub1_virtual_event_e_4_1
+ attribute: 事件名称
+ state: 打开电梯
+ actions:
+ - action: script.notify_floor
+ metadata: {}
+ data: {}
+ mode: single
+```
\ No newline at end of file
diff --git a/docs/src/pages/index.astro b/docs/src/pages/index.astro
index 9c160e4..5d254c5 100644
--- a/docs/src/pages/index.astro
+++ b/docs/src/pages/index.astro
@@ -2,6 +2,7 @@
import '../styles/global.css';
const links = [
+
{
link: './adb/',
title: 'ADB 文档',
@@ -13,41 +14,52 @@ const links = [
{
link: './ip/',
title: 'IP 相关文档, IPTABLES 配置,如何从A 局域网 ping 同B 局域网',
+ },
+ {
+ link: './python/',
+ title: 'Python 脚本运行文档',
+ },
+ {
+ link: './home/',
+ title: 'homeassistant 触发脚本文档方法',
}
];
---
-
+
My Homepage
-
+
-
-
-
文档导航
-
-
-
- {links.map((item) => (
- -
-
-
- {item.title}
-
- 点击查看详细文档
-
-
-
- ))}
+
+
diff --git a/docs/src/pages/python.mdx b/docs/src/pages/python.mdx
new file mode 100644
index 0000000..e9de7d6
--- /dev/null
+++ b/docs/src/pages/python.mdx
@@ -0,0 +1,144 @@
+# python 代码示例
+
+```sh
+# 安装 python 环境 ,安装项目
+uv sync
+```
+
+## 运行 python 脚本
+
+main.py 主模块
+
+```python
+import socket
+import time
+
+def send_sip_message():
+ # 配置参数
+ target_ip = "192.168.3.3" # 设备eth1的IP(转发入口)
+ target_port = 5060 # 转发端口
+ mac_local_ip = "192.168.3.33"# Mac的本地IP(与Via头部一致)
+ sender_sip = "3011302" # 发送方SIP用户
+ sender_ip = "192.168.9.57" # 设备eth0的IP(转发后源IP)
+ receiver_sip = "3019901" # 接收方SIP用户
+ receiver_ip = "192.168.9.4" # 目标IP
+
+ # 生成唯一标识
+ call_id = f"{int(time.time())}" # 基于时间戳的Call-ID
+ tag = f"{int(time.time() % 1000000)}" # 随机tag
+ branch = f"z9hG4bK{int(time.time())}" # Via分支标识
+
+ # XML消息体(业务数据)
+ xml_body = '''
+
+ sip:{receiver_sip}@{receiver_ip}:5060
+ 1
+ 2
+ 13
+ 2
+ elev
+ appoint
+ /elev/appoint
+'''.format(receiver_sip=receiver_sip, receiver_ip=receiver_ip)
+
+ # 计算消息体长度(字节数)
+ content_length = len(xml_body.encode('utf-8'))
+
+ # 构造SIP MESSAGE请求(严格使用\r\n换行)
+ sip_message = f'''MESSAGE sip:{receiver_sip}@{receiver_ip}:5060 SIP/2.0
+Via: SIP/2.0/UDP {mac_local_ip}:5060;rport;branch={branch}
+From: ;tag={tag}
+To:
+Call-ID: {call_id}@{mac_local_ip}
+CSeq: 20 MESSAGE
+Content-Type: text/plain
+Max-Forwards: 70
+User-Agent: DnakeVoip v1.0
+Content-Length: {content_length}
+
+{xml_body}'''
+
+ # 替换换行符为\r\n(确保符合SIP协议)
+ sip_message = sip_message.replace('\n', '\r\n')
+
+ try:
+ # 创建UDP socket并发送消息
+ with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
+ # 设置超时时间(5秒)
+ sock.settimeout(5)
+ # 发送消息
+ sock.sendto(sip_message.encode('utf-8'), (target_ip, target_port))
+ print(f"已发送SIP消息到 {target_ip}:{target_port}")
+ print("\n发送的消息内容:")
+ print(sip_message)
+
+ # 尝试接收响应(可选)
+ try:
+ response, addr = sock.recvfrom(4096)
+ print(f"\n收到来自 {addr} 的响应:")
+ print(response.decode('utf-8', errors='ignore'))
+ except socket.timeout:
+ print("\n未收到响应(可能对方未回复或网络延迟)")
+
+ except Exception as e:
+ print(f"发送失败:{str(e)}")
+
+if __name__ == "__main__":
+ send_sip_message()
+```
+
+app.py
+
+```python
+from fastapi import FastAPI, Query
+import httpx
+import asyncio
+import uvicorn
+from main import send_sip_message
+
+app = FastAPI()
+
+async def main():
+ """主函数内容"""
+ print("执行main函数...")
+ # 执行发送SIP消息
+ send_sip_message()
+ return {"message": "main function executed - SIP message sent"}
+
+async def test():
+ """测试函数内容"""
+ print("执行test函数...")
+ # 在这里添加你的test函数逻辑
+ return {"message": "test function executed"}
+
+@app.api_route("/api/router", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"])
+async def router(path: str = Query(...)):
+ """路由处理器"""
+ try:
+ # 根据path参数执行不同的函数
+ if path == "floor":
+ result = await main()
+ elif path == "test":
+ result = await test()
+ else:
+ return {"error": f"Unknown path: {path}"}
+
+ return {"success": True, "data": result}
+
+ except Exception as e:
+ return {"success": False, "error": str(e)}
+
+@app.api_route("/", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"])
+async def root():
+ """健康检查端点"""
+ return {"message": "FastAPI server is running"}
+
+if __name__ == "__main__":
+ # 监听所有IPv6地址的3001端口
+ uvicorn.run(
+ "app:app",
+ host="::", # 监听所有IPv6地址
+ port=3001,
+ reload=True
+ )
+```
\ No newline at end of file