Skip to content

Instantly share code, notes, and snippets.

Created March 25, 2023 23:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Example of Custom Bluetti Polling Script
import asyncio
from bleak import BleakError
import sys
from bluetti_mqtt.bluetooth import (check_addresses, BluetoothClient, ParseError, BadConnectionError)
async def monitor_device(address):
devices = await check_addresses({address})
if len(devices) == 0:
sys.exit('Could not find the given device to connect to')
device = devices[0]
print(f'Connecting to {device.address}')
client = BluetoothClient(device.address)
while not client.is_connected:
print('Waiting for connection...')
await asyncio.sleep(1)
# Poll device
while True:
for command in device.polling_commands:
response_future = await client.perform(command)
response = await response_future
parsed = device.parse(, command.offset, response.body)
print(parsed) # <-- This is the thing you want to save
except (BadConnectionError, BleakError, ParseError) as err:
print(f'Got an error running command {command}: {err}')
if __name__ == "__main__":[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment