Cleanup helper scripts. Closes #7
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import asyncio
|
||||
import sys
|
||||
try:
|
||||
from bleak import BleakScanner, BleakClient
|
||||
except ImportError:
|
||||
print("Please install bleak first: pip install bleak")
|
||||
sys.exit(1)
|
||||
|
||||
DEVICE_NAME = "WijiBoard"
|
||||
SERVICE_UUID = "18f3b235-9831-4c75-8ec0-210469b820a0"
|
||||
CMD_UUID = "cd083b06-4447-4cf3-a7c3-322ecf802ce4"
|
||||
STATUS_UUID = "82e38c5b-d3ab-41d1-861c-b84dc6bb1e03"
|
||||
|
||||
async def main():
|
||||
print(f"Scanning for {DEVICE_NAME}...")
|
||||
devices = await BleakScanner.discover(timeout=5.0)
|
||||
|
||||
target_device = None
|
||||
for d in devices:
|
||||
if d.name == DEVICE_NAME:
|
||||
target_device = d
|
||||
break
|
||||
|
||||
if not target_device:
|
||||
print(f"Could not find {DEVICE_NAME}. Make sure it is powered on and advertising.")
|
||||
return
|
||||
|
||||
print(f"Found {DEVICE_NAME} at {target_device.address}. Connecting...")
|
||||
|
||||
async with BleakClient(target_device.address) as client:
|
||||
print(f"Connected: {client.is_connected}")
|
||||
|
||||
# Setup notifications
|
||||
def notification_handler(sender, data):
|
||||
print(f"[STATUS UPDATE] {data.decode('utf-8')}")
|
||||
|
||||
print("Subscribing to status characteristic...")
|
||||
try:
|
||||
await client.start_notify(STATUS_UUID, notification_handler)
|
||||
print("Successfully subscribed!")
|
||||
except Exception as e:
|
||||
print(f"Failed to subscribe: {e}")
|
||||
|
||||
# Send a test command
|
||||
test_cmd = "S1+100"
|
||||
print(f"Sending test command: '{test_cmd}'...")
|
||||
await client.write_gatt_char(CMD_UUID, test_cmd.encode('utf-8'), response=False)
|
||||
|
||||
print("Waiting 5 seconds to receive any status updates...")
|
||||
await asyncio.sleep(5.0)
|
||||
|
||||
print("Disconnecting...")
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user