smart-home/quick_radar_test.py
2026-02-26 09:16:34 +08:00

49 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
快速雷达传感器UART测试脚本
测试ESP32雷达传感器的UART距离检测功能
"""
import requests
import json
import time
def test_radar_api():
"""测试雷达API"""
url = "http://192.168.1.3:80/thermal_grid"
print("🔧 雷达UART距离检测测试")
print("=" * 50)
print(f"📡 ESP32地址: 192.168.1.3")
print(f"🌐 API地址: {url}")
print("=" * 50)
try:
response = requests.get(url, timeout=5)
if response.status_code == 200:
data = response.json()
# 提取雷达数据
radar = data.get('radar', {})
print(f"📊 雷达传感器状态:")
print(f"🚶 GPIO检测: {'有人' if radar.get('detected', False) else '无人'}")
print(f"📡 UART通信: {'可用' if radar.get('uart_available', False) else '不可用'}")
print(f"📏 距离分段: {radar.get('distance_range', 'unknown')}")
if radar.get('uart_available', False):
print(f"🎯 运动距离: {radar.get('moving_distance', 0)}cm")
print(f"🎯 静止距离: {radar.get('static_distance', 0)}cm")
print("✅ UART通信正常工作")
else:
print("⚠️ UART通信不可用使用GPIO检测")
else:
print(f"❌ HTTP错误: {response.status_code}")
except Exception as e:
print(f"❌ 连接错误: {e}")
if __name__ == "__main__":
test_radar_api()