python蓝牙通信_python实现蓝牙通信

安装和示例

linux下安装

sudo apt-get install python-pip libglib2.0-dev

sudo pip install bluepy

官方示例

importbtleclassMyDelegate(btle.DefaultDelegate):def __init__(self, params):

btle.DefaultDelegate.__init__(self)#... initialise here

defhandleNotification(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 --------

whileTrue:if p.waitForNotifications(1.0):#handleNotification() was called

continue

print "Waiting..."

#Perhaps do something else here

蓝牙通信模块pybluez的使用

选择蓝牙通信对象

importbluetooth

target_name

你可能感兴趣的:(python蓝牙通信)