python蓝牙模块

需要安装蓝牙模块:pybluez

#pip install pybluez
 
import time
from bluetooth import *
alreadyFound = []
def findDevs():
    print("start searching...")
    foundDevs = discover_devices(lookup_names=True)
    for(addr,name) in foundDevs:
        if addr not in alreadyFound:
            print("[*] Found Bluetooth Device :  " +str(name))
            print("[+] MAC address :  " +str(addr))
            alreadyFound.append(addr)
 

findDevs()

import bluetooth
print("performing inquiry...")
nearby_devices = bluetooth.discover_devices(lookup_names = True)
print("found %d devices" % len(nearby_devices))
for addr, name in nearby_devices:
    print("  %s - %s" % (addr, name))

参考:

https://blog.csdn.net/abg49988/article/details/101867060

https://blog.csdn.net/qq_41204464/article/details/89258270

发布了396 篇原创文章 · 获赞 172 · 访问量 17万+

猜你喜欢

转载自blog.csdn.net/hxxjxw/article/details/104727765