Skip to content

Instantly share code, notes, and snippets.

@GuillaumeDerval
Created July 30, 2020 16:17
Show Gist options
  • Save GuillaumeDerval/65a4d89feacb8a0451c0207614ae4434 to your computer and use it in GitHub Desktop.
Save GuillaumeDerval/65a4d89feacb8a0451c0207614ae4434 to your computer and use it in GitHub Desktop.
Starting 4moms mamaRoo using Python
import asyncio
import random
from bleak import discover, BleakClient
ADDRESS = None
UUID = "622d0101-2416-0fa7-e132-2f1495cc2ce0" # can be found by connecting to the mamaRoo and inspecting the thing it advertises.
async def find_mamaroo():
if ADDRESS is not None:
return ADDRESS
devices = await discover()
for d in devices:
if d.name == "mamaRoo":
return d.address
async def run():
address = await find_mamaroo()
print(address)
async with BleakClient(address, loop=loop) as client:
print("connected")
try:
while True:
mode = random.randint(1, 5)
speed = random.randint(1, 5)
# Speed
await client.write_gatt_char(UUID, bytearray([0x43, 0x06, speed]))
# Mode
await client.write_gatt_char(UUID, bytearray([0x43, 0x04, mode]))
# Say that it should move
await client.write_gatt_char(UUID, bytearray([0x43, 0x02, 0x01]))
await asyncio.sleep(3)
except KeyboardInterrupt:
await client.write_gatt_char(UUID, bytearray([0x43, 0x02, 0x00])) # shutdown
await asyncio.sleep(1)
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment