LoginSignup
0
0

More than 1 year has passed since last update.

Pythonでbluetooth端末を検出する方法

Last updated at Posted at 2022-12-29

めっちゃ前に作ったやつ非公開のやつ

$ pip install bleak
blue.py
"""
https://qiita.com/kenichih/items/8baa27b3aecc94dd8193

https://atatat.hatenablog.com/entry/2020/07/09/003000

pip install bleak
"""

import asyncio
from bleak import discover

async def run():
    print("検出中")
    devices = await discover()
    for d in devices:
        if d.name != "Unknown" and d.rssi > -90:    #約1〜1.5mにあるとき
            print("強さ:", d.rssi, "     端末:",  d.name)

def main():
  tim = 1
  while True:
    loop = asyncio.get_event_loop()
    loop.run_until_complete(run())
    print()
    print("{}秒後再開します。".format(tim))
    time.sleep(tim)

if __name__ == "__main__":
  main()
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0