BLUEPY(1) bluepy BLUEPY(1) (NAME) bluepy - bluepy bluepy (Bluetooth Low Energy) . ( BlueZ ) . API Peripheral <#peripheral> . : PERIPHERAL (THE PERIPHERAL CLASS) Peripheral bluepy (peripheral) LE . Peripheral MAC (characteristics) . (Constructor) Peripheral([deviceAddr=None[, addrType=ADDR_TYPE_PUBLIC[, iface=None]]]) deviceAddr None Peripheral deviceAddr . deviceAddr "11:22:33:ab:cd:ed". deviceAddr None Peripheral . connect() . addrType (btle.ADDR_TYPE_PUBLIC) (btle.ADDR_TYPE_RANDOM) . . Bluetooth 4.0 . iface . 0 /dev/hci0 1 /dev/hci1 . deviceAddr ScanEntry . ScanEntry addrType iface . BTLEException . (Instance Methods) connect(addr[, addrType=ADDR_TYPE_PUBLIC[, iface=None]]) addr addrType iface ( Peripheral ). Peripheral ( addr ) . disconnect() . (destructor) Peripheral . disconnect() . getState() . : "conn" - "disc" - "scan" - () "tryconn" - . getServices() Service . . 3.x dictionary view . getServiceByUUID(uuidVal) Service UUID . uuidVal UUID UUID . ( getServices()) . BTLEEException . getCharacteristics(startHnd=1, endHnd=0xFFFF, uuid=None) Characteristic . . startHnd / endHnd (handles) - Service.getCharacteristics() . uuid UUID . uuid UUID UUID . . getDescriptors(startHnd=1, endHnd=0xFFFF) Descriptor . . startHnd / endHnd . Service.getDescriptors() . . withDelegate(delegate) <<>> ("delegate") . DefaultDelegate . <#notifications> . Peripheral . setDelegate(delegate) ( 0.9.10 ) withDelegate(). waitForNotifications(timeout) (timeout ) . handleNotification() waitForNotifications() True . False . writeCharacteristic(handle, val, withResponse=False) val ( str 2.x byte 3.x) handle 1 65535 . GATT Characteristic . withResponse true . readCharacteristic(handle) handle . Characteristic . . addr MAC ( ). addrType - ADDR_TYPE_PUBLIC ADDR_TYPE_RANDOM . iface Bluetooth ( 0 = /dev/hci0) . (THE SCANNER CLASS) Scanner LE (advertising data) . . ( Bluetooth LE ). (Constructor) Scanner([index=0]) . index Bluetooth ( 0 /dev/hci0 ). start() scan() - . (Instance Methods) withDelegate(delegate) delegate (callbacks) . DefaultDelegate . scan([timeout = 10]) timeout ( ) . delegate . ( view Python 3.x) ScanEntry . scan() clear() start() process() stop() . clear() . start() (peripherals) . process() . process([timeout = 10]) delegate . timeout ( ) . ( start() stop()) . stop() . process() . getDevices() ( view Python 3.x) ScanEntry ( clear()) . LE : # import the necessary parts of the bluepy library from bluepy.btle import Scanner, DefaultDelegate # create a delegate class to receive the BLE broadcast packets class ScanDelegate(DefaultDelegate): def __init__(self): DefaultDelegate.__init__(self) # when this python script discovers a BLE broadcast packet, print a message with the device's MAC address def handleDiscovery(self, dev, isNewDev, isNewData): if isNewDev: print "Discovered device", dev.addr elif isNewData: print "Received new data from", dev.addr # create a scanner object that sends BLE broadcast packets to the ScanDelegate scanner = Scanner().withDelegate(ScanDelegate()) # create a list of unique devices that the scanner discovered during a 10-second scan devices = scanner.scan(10.0) # for each device in the list of devices for dev in devices: # print the device's MAC address, its address type, # and Received Signal Strength Indication that shows how strong the signal was when the script received the broadcast. print "Device %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi) # For each of the device's advertising data items, print a description of the data type and value of the data itself # getScanData returns a list of tupples: adtype, desc, value # where AD Type means "advertising data type," as defined by Bluetooth convention: # https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile # desc is a human-readable description of the data type and value is the data itself for (adtype, desc, value) in dev.getScanData(): print " %s = %s" % (desc, value) : # import the necessary parts of the bluepy library from bluepy.btle import Scanner, DefaultDelegate # create a delegate class to receive the BLE broadcast packets class ScanDelegate(DefaultDelegate): def __init__(self): DefaultDelegate.__init__(self) # when this python script discovers a BLE broadcast packet, print a message with the device's MAC address def handleDiscovery(self, dev, isNewDev, isNewData): if isNewDev: print "Discovered device", dev.addr elif isNewData: print "Received new data from", dev.addr # create a scanner object that sends BLE broadcast packets to the ScanDelegate scanner = Scanner().withDelegate(ScanDelegate()) # start the scanner and keep the process running scanner.start() while True: print "Still running..." scanner.process() () LE (root) () handleDiscovery() delegate . dev delegate ScanEntry ..SH " SCANENTRY (THE SCANENTRY CLASS)" ScanEntry Scanner Bluetooth LE . ( MAC ) ( ) (broadcasts) . (Constructor) ScanEntry Scanner . (Instance Methods) getDescription(adtype) ('type') adtype . adtype "Complete Local Name" . Generic Access Profile . getValueText(adtype) adtype . 'local name' . None . getScanData() (adtype, description, value) AD ( getDescription() getValueText() ) . (Properties) (read-only) . addr MAC ( ). addrType - ADDR_TYPE_PUBLIC ADDR_TYPE_RANDOM. iface (0 = /dev/hci0) . rssi (RSSI) (broadcast) . dB 0 dB () . connectable - True False ( 'beacons' ). updateCount ( clear() Scanner ) . DEFAULTDELEGATE (THE DEFAULTDELEGATE CLASS) bluepy (asynchronous) - (notifications) (indications) - 'delegate' . delegate . DefaultDelegate bluepy - (override) ..SS " (Constructor)" DefaultDelegate() . (Instance Methods) handleNotification(cHandle, data) (notification) (indication) Peripheral . cHandle ( ) - peripheral . data ( str Python 2.x bytes 3.x). handleDiscovery(scanEntry, isNewDev, isNewData) (advertising data) LE Scanner . scanEntry - ScanEntry . ( MAC ) isNewDev True False . isNewData True . UUID (THE UUID CLASS) (Constructor) UUID(value) UUID value . : o int 0 0xFFFFFFFF o str o UUID o str() (Instance Methods) getCommonName() UUID . UUID << >> <#assignednumbers> "Cycling Speed and Cadence". . (Properties) (read-only) . binVal UUID ( str Python 2.x bytes 3.x). SERVICE (THE SERVICE CLASS) Service Bluetooth LE (characteristics) (descriptors) (peripheral) . peripheral . : (Constructor) Service getServices() getServiceByUUID() Peripheral . (Instance Methods) getCharacteristics([forUUID=None]) Characteristic . peripheral . forUUID UUID . ( ) UUID . - . uuid UUID . peripheral Peripheral . (THE CHARACTERISTIC CLASS) <<>> ("characteristic") Bluetooth LE . ( ) ( ). Bluetooth LE . (Constructor) Characteristic . getCharacteristics() Peripheral . (Instance Methods) read() . 2.x str 3.x bytes . struct . write(data[, withResponse=False]) data . data 2.x str 3.x bytes . Bluetooth LE . withResponse True . BTLEException . supportsRead() ( ) True False . propertiesToString() ('READ' 'WRITE' ). getHandle() GATT . ( <#notifications> ). (Properties) - . uuid UUID . peripheral Peripheral . properties (bitmask) . (THE DESCRIPTOR CLASS) Descriptor (placeholder) . bluepy . (WORKING WITH NOTIFICATIONS) bluepy ("delegate") Peripheral . : handleNotification(cHandle, data) Peripheral . waitForNotifications() Bluetooth LE . handleNotification() BluePy . cHandle 'handle' GATT . . 'handle' getHandle() Characteristic . data str ( 2.x) bytes ( 3.x) . struct (unpack) . delegate btle.DefaultDelegate . delegate ..SS " (Example code)" : import btle class MyDelegate(btle.DefaultDelegate): def __init__(self, params): btle.DefaultDelegate.__init__(self) # ... initialise here def handleNotification(self, cHandle, data): # ... perhaps check cHandle # ... process 'data' # Initialisation ------- p = btle.Peripheral( address ) p.setDelegate( MyDelegate(params) ) # Setup to turn notifications on, e.g. # svc = p.getServiceByUUID( service_uuid ) # ch = svc.getCharacteristics( char_uuid )[0] # ch.write( setup_data ) # Main loop -------- while True: if p.waitForNotifications(1.0): # handleNotification() was called continue print "Waiting..." # Perhaps do something else here (ASSIGNED NUMBERS) AssignedNumbers Bluetooth . AssignedNumbers.firmwareRevisionString UUID Firmware Revision String (0x2A26) . Bluetooth . bluepy : alertNotificationService batteryLevel batteryService bloodPressure currentTimeService cyclingPower cyclingSpeedAndCadence deviceInformation deviceName firmwareRevisionString genericAccess genericAttribute glucose hardwareRevisionString healthThermometer heartRate humanInterfaceDevice immediateAlert linkLoss locationAndNavigation manufacturerNameString modelNumberString nextDstChangeService phoneAlertStatusService referenceTimeUpdateService runningSpeedAndCadence scanParameters serialNumberString softwareRevisionString txPower txPowerLevel userData o <> o <> o <> Ian Harvey (COPYRIGHT) 2014, Ian Harvey 0.9 December 14, 2025 BLUEPY(1)