-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-simple-system.py
More file actions
71 lines (57 loc) · 2.34 KB
/
test-simple-system.py
File metadata and controls
71 lines (57 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
"""
Test the Simple Arduino Fire Detection System
"""
import asyncio
import websockets
import json
async def test_simple_fire_system():
"""Test the simple Arduino fire system"""
print("🔥 Testing Simple Arduino Fire Detection System")
print("=" * 50)
try:
async with websockets.connect("ws://localhost:8766") as websocket:
print("✅ Connected to Arduino Fire System")
# Wait for initial sensor data
message = await websocket.recv()
data = json.loads(message)
print(f"📡 Received: {data['type']}")
print(f"🔥 Sensors: {len(data.get('sensors', []))}")
# Test starting a fire
fire_command = {
"type": "start_fire",
"lat": 38.7900,
"lon": -120.4240,
"intensity": 1.0
}
await websocket.send(json.dumps(fire_command))
print("🔥 Started fire at coordinates")
# Wait for updated sensor data
await asyncio.sleep(3)
message = await websocket.recv()
data = json.loads(message)
hot_sensors = [s for s in data.get('sensors', []) if s.get('temperature', 20) > 30]
print(f"🌡️ Hot sensors detected: {len(hot_sensors)}")
# Test clearing fires
await websocket.send(json.dumps({"type": "clear_fires"}))
print("🧯 Cleared all fires")
print("✅ Simple Arduino Fire System test completed!")
return True
except Exception as e:
print(f"❌ Test failed: {e}")
return False
async def main():
"""Run the test"""
success = await test_simple_fire_system()
if success:
print("\n🎉 Simple Arduino Fire Detection System is working!")
print("🚀 To use the system:")
print(" 1. python simple-arduino-fire.py")
print(" 2. cd frontend && npm run dev")
print(" 3. Open http://localhost:3000/simple")
print(" 4. Click on map to start fires!")
else:
print("\n❌ System test failed")
print("💡 Make sure to start: python simple-arduino-fire.py")
if __name__ == "__main__":
asyncio.run(main())