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


(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

bugs

install error

image

??? 不支持 Python 3

??? 缺少 C++ 依赖

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

refs



©xgqfrms 2012-2021

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

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


posted @ 2023-05-17 23:26  xgqfrms  阅读(21)  评论(1编辑  收藏  举报