没有合适的资源?快使用搜索试试~ 我知道了~
首页基于python实现蓝牙通信代码实例
这篇文章主要介绍了基于python实现蓝牙通信代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 安装和示例 linux下安装 sudo apt-get install python-pip libglib2.0-dev sudo pip install bluepy 官方示例 import btle class MyDelegate(btle.DefaultDelegate): def __init__(self, params): btle.DefaultDelegate.__init__(self)#.. .initia
资源详情
资源评论
资源推荐

基于基于python实现蓝牙通信代码实例实现蓝牙通信代码实例
这篇文章主要介绍了基于python实现蓝牙通信代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定
的参考学习价值,需要的朋友可以参考下
安装和示例安装和示例
linux下安装
sudo apt-get install python-pip libglib2.0-dev
sudo pip install bluepy
官方示例官方示例
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
蓝牙通信模块蓝牙通信模块pybluez的使用的使用
选择蓝牙通信对象
import bluetooth
target_name = "My Device"
target_address = None
nearby_devices = bluetooth.discover_devices()
for bdaddr in nearby_devices:
if target_name == bluetooth.lookup_name(
bdaddr):
target_address = bdaddr
break
if target_address is not None:
print(
"found target bluetooth device with address ",
target_address)
else :
print(
"could not find target bluetooth device nearby"
)
查询设备服务
import bluetooth
nearby_devices = bluetooth.discover_devices(
lookup_names = True)
for addr, name in nearby_devices:
print(" %s - %s" % (addr, name))
services = bluetooth.find_service(
address = addr)
for svc in services:
print("Service Name: %s" % svc["name"])
print(" Host: %s" % svc["host"])
print(" Description: %s" % svc[
"description"])














安全验证
文档复制为VIP权益,开通VIP直接复制

评论0