Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vince-lynch/3d883b7e14d23623eae7096a3b6590ab to your computer and use it in GitHub Desktop.
Save vince-lynch/3d883b7e14d23623eae7096a3b6590ab to your computer and use it in GitHub Desktop.
import asyncio
import binascii
from bleak import discover
device = None
CONSMART_BLE_NOTIFICATION_SERVICE_WRGB_UUID = "0000ffd5-0000-1000-8000-00805f9b34fb";
CONSMART_BLE_NOTIFICATION_CHARACTERISTICS_WRGB_UUID = "0000ffd9-0000-1000-8000-00805f9b34fb";
async def scan():
lock_found = False
while not lock_found:
d = await discover()
for i in range(0,len(d)):
if "LOCK" in d[i].name:
print("["+str(i)+"]"+str(d[i]))
device = d[i]
lock_found = True
return device
from bleak import BleakClient
async def connect(address, loop):
print("Connecting to LOCK...")
async with BleakClient(address, loop=loop) as client:
services = await client.get_services()
print("Found services..")
for ser in services:
if ser.uuid == CONSMART_BLE_NOTIFICATION_SERVICE_WRGB_UUID:
uuid = ser.uuid
print("Found Notification Service")
lockChar = ser.get_characteristic(CONSMART_BLE_NOTIFICATION_CHARACTERISTICS_WRGB_UUID)
pwd = '010203040102' # renderNum(self.pwd)
raw = '29' + pwd + '28'
message = binascii.unhexlify(raw)
response = await client.write_gatt_char(CONSMART_BLE_NOTIFICATION_CHARACTERISTICS_WRGB_UUID, message)
packet = binascii.unhexlify("fe4f50454e00000000fd") # OPEN CODE
response2 = await client.write_gatt_char(CONSMART_BLE_NOTIFICATION_CHARACTERISTICS_WRGB_UUID, packet)
print("Got this far")
#notify = await client.start_notify(uuid, );
print("Looking for LOCK")
loop = asyncio.get_event_loop()
device = loop.run_until_complete(scan())
#index = input('Lock found, hit enter to continue')
loop.run_until_complete(connect(device.address, loop))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment