first commit

This commit is contained in:
2026-03-12 17:03:56 +08:00
commit aa4d4c7d7c
48 changed files with 10958 additions and 0 deletions

29
test/device.py Normal file
View File

@@ -0,0 +1,29 @@
import socket
import time
from protocol import build_frame
SERVER_IP = '127.0.0.1'
SERVER_PORT = 9000
DEVICE_ID = 10000052 # 每个设备改这个
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((SERVER_IP, SERVER_PORT))
print(f"[DEVICE {DEVICE_ID}] connected")
while True:
# 发送心跳
hb = build_frame(0x00, DEVICE_ID)
s.sendall(hb)
# 接收控制指令
s.settimeout(1)
try:
data = s.recv(1024)
if data and data[8] == 0xA0:
print(f"[DEVICE {DEVICE_ID}] recv A0:", data.hex(' '))
# 这里执行你的 IO / GPIO
except socket.timeout:
pass
time.sleep(3)