xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

How to use Raspberry Pi scan bluetooth devices All In One

How to use Raspberry Pi scan bluetooth devices All In One

蓝牙

$ sudo pip3 install pybluez

https://pypi.org/project/PyBluez/

#!/usr/bin/env python3
# coding: utf8

from time import sleep
import bluetooth

try:
  nearby_devices = bluetooth.discover_devices(lookup_names=True)
  print("Found {} devices.".format(len(nearby_devices)))
  for addr, name in nearby_devices:
    print("address = {}, name = {}".format(addr, name))
except KeyboardInterrupt:
  print("Ctrl + C ✅")
finally:
  sleep(1)
  print("clear ✅")
# bluetooth low energy scan
from bluetooth.ble import DiscoveryService

service = DiscoveryService()
devices = service.discover(2)

for address, name in devices.items():
    print("name: {}, address: {}".format(name, address))

https://github.com/pybluez/pybluez

https://pypi.org/project/pybluez2/
https://github.com/airgproducts/pybluez2

docs

https://pybluez.readthedocs.io/en/latest/install.html

#!/usr/bin/env python3

import bluetooth

def scan():
    print("Scanning for bluetooth devices:")
    devices = bluetooth.discover_devices(lookup_names = True, lookup_class = True)
    number_of_devices = len(devices)
    print(number_of_devices,"devices found")
    for addr, name, device_class in devices:
        print("\n")
        print("Device:")
        print("Device Name: %s" % (name))
        print("Device MAC Address: %s" % (addr))
        print("Device Class: %s" % (device_class))
        print("\n")
    return

https://geektechstuff.com/2020/06/01/python-and-bluetooth-part-1-scanning-for-devices-and-services-python/

https://forums.raspberrypi.com/viewtopic.php?t=329762

from bluetooth import *

print "performing inquiry..."

nearby_devices = discover_devices(lookup_names = True)

print "found %d devices" % len(nearby_devices)

for name, addr in nearby_devices:
     print " %s - %s" % (addr, name)

https://stackoverflow.com/questions/21000680/how-to-find-visible-bluetooth-devices-in-python

http://www.robertprice.co.uk/robblog/2007/01/programming_bluetooth_using_python-shtml/

https://github.com/karulis/pybluez

http://karulis.github.io/pybluez/

https://github.com/EnableTech/raspberry-bluetooth-demo

demos


bugs

install error

image

??? 不支持 Python 3

??? 缺少 C++ 依赖

https://github.com/pybluez/pybluez/issues/476

refs



©xgqfrms 2012-2025

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @   xgqfrms  阅读(32)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
历史上的今天:
2022-05-17 Xcode sets default tab indent equal to 2 spaces All In One
2022-05-17 MacBook Pro 外接显示器的音箱没声音解决方案 All In One
2021-05-17 $forceUpdate All In One
2021-05-17 vue button disabled tooltip All In One
2020-05-17 Deno 1.0 & Node.js All In One
2020-05-17 App Store Previewer
2020-05-17 how to create one single-file Web Component just using the HTML, CSS, JavaScript All In One
点击右上角即可分享
微信分享提示