Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@peplin
Created September 10, 2016 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peplin/f765ae283cc695999560d350659a322b to your computer and use it in GitHub Desktop.
Save peplin/f765ae283cc695999560d350659a322b to your computer and use it in GitHub Desktop.
A quick test for running the 2 pygatt backends in a coffee shop, connecting to any device we can and reading one characteristic
#!/usr/bin/env python
from __future__ import print_function
import logging
logging.basicConfig()
logging.getLogger('pygatt').setLevel(logging.INFO)
import binascii
import pygatt
import os
import sys
ADDRESS = "E7:14:B3:A3:A9:F2"
# Many devices, e.g. Fitbit, use random addressing - this is required to
# connect.
ADDRESS_TYPE = pygatt.BLEAddressType.random
address = ADDRESS
if os.environ['BACKEND'] == "gatttool":
adapter = pygatt.GATTToolBackend(hci_device="hci1")
else:
adapter = pygatt.BGAPIBackend()
adapter.start()
devices = adapter.scan(run_as_root=True, timeout=3)
for device in devices:
address = device['address']
try:
print("Connecting...")
device = adapter.connect(address, address_type=ADDRESS_TYPE)
print("Connected")
for uuid in device.discover_characteristics().keys():
if str(uuid) == "adabfb04-6e7d-4601-bda2-bffaa68956ba":
print("Skipping evil UUID %s" % uuid)
continue
try:
print("Read UUID %s: %s" % (uuid, binascii.hexlify(device.char_read(uuid))))
except:
continue
else:
break
device.disconnect()
except pygatt.exceptions.NotConnectedError:
print("failed to connect to %s" % address)
continue
else:
break
else:
print("failed to connect and read from any device")
sys.exit(1)
#!/usr/bin/env bash
set -ex
export BACKEND="gatttool"
env/bin/python ./fitbit.py
env3.5/bin/python ./fitbit.py
export BACKEND="bgapi"
env/bin/python ./fitbit.py
env3.5/bin/python ./fitbit.py
@sujaycharala
Copy link

hi,
i have connected to the fitbit using the code.i receiving the hexa data 48583033 from fitbit but i am unable to decode it can u please he me in decoding the value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment