Merge pull request 'fix: remove outdated ble_client.py, add test_ota_notify.py to tools' (#22) from fix/cleanup-outdated-scripts into main
All checks were successful
CI / build (push) Successful in 1m16s

This commit is contained in:
eddy 2026-08-04 18:48:54 +02:00
commit 09b6ff6823
2 changed files with 123 additions and 87 deletions

View file

@ -1,87 +0,0 @@
#!/usr/bin/env python3
"""BLE client for SylDa_Server — send color commands from laptop."""
import asyncio
import sys
from bleak import BleakScanner, BleakClient
SERVICE_UUID = "0000abcd-0000-1000-8000-00805f9b34fb"
CHAR_UUID = "0000abce-0000-1000-8000-00805f9b34fb"
SERVER_NAME = "SylDa_Server"
COLORS = {
"r": ("red", b"\x00"),
"g": ("green", b"\x01"),
"y": ("yellow", b"\x02"),
"o": ("orange", b"\x03"),
"b": ("blue", b"\x04"),
}
async def find_server():
print(f"Scanning for {SERVER_NAME}...")
device = await BleakScanner.find_device_by_name(SERVER_NAME, timeout=10)
if not device:
print("Not found.")
return None
print(f"Found: {device.name} ({device.address})")
return device
async def send_color(client, data):
await client.write_gatt_char(CHAR_UUID, data, response=True)
print(f"Sent: {COLORS[[k for k, v in COLORS.items() if v[1] == data][0]][0]}")
def show_menu():
print("\n┌─────────────────────┐")
print("│ r = red │")
print("│ g = green │")
print("│ y = yellow │")
print("│ o = orange │")
print("│ b = blue │")
print("│ q = quit │")
print("└─────────────────────┘")
async def connect_handler(client):
print(f"Connected: {client.is_connected}")
async def disconnect_handler(client):
print("Disconnected from server.")
async def main():
device = await find_server()
if not device:
return
async with BleakClient(
device,
disconnected_callback=disconnect_handler,
timeout=10,
) as client:
await connect_handler(client)
while True:
try:
show_menu()
cmd = await asyncio.get_event_loop().run_in_executor(
None, lambda: input("> ").strip().lower()
)
except (EOFError, KeyboardInterrupt):
break
if cmd == "q":
break
elif cmd in COLORS:
await send_color(client, COLORS[cmd][1])
else:
print(f"Unknown: {cmd}")
print("Bye.")
if __name__ == "__main__":
asyncio.run(main())