在树莓派上使用蓝牙测量接近度 [英] Measuring proximity with bluetooth on raspberry Pi

查看:28
本文介绍了在树莓派上使用蓝牙测量接近度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用这个脚本 https://github.com/karulis/pybluez/blob/master/examples/advanced/inquiry-with-rssi.py 但似乎 sock = bluez.hci_open_dev(dev_id) 返回一个非工作套接字.每次将 sock 传递给函数时,都会抛出 error(9, 'Bad file descriptor').

I've been trying to use this script https://github.com/karulis/pybluez/blob/master/examples/advanced/inquiry-with-rssi.py but it seems that sock = bluez.hci_open_dev(dev_id) returns a non-working socket. Every time sock is passed into a function error(9, 'Bad file descriptor') is thrown.

这个脚本已经很旧了,所以很有可能它不再起作用了.所以我有两个问题.有谁知道如何使用 pybluez 库(或更现代的等效库)来测量蓝牙设备与树莓派的接近度?

This script is pretty old so there is a decent chance it doesn't work any more. So I have two questions. Does anyone know how to use the pybluez library (or a more modern equivalent) to measure proximity of a bluetooth device with a raspberry pi?

我在这个脚本中做错了什么导致我构建了一个损坏的套接字?

And what am I doing wrong with this script that is causing me to build a broken socket?

谢谢.

推荐答案

试试这个:

运行 hcitool dev 以获取蓝牙设备的地址.

Run hcitool dev to get the address of your bluetooth device.

在您链接到的脚本中,将第 120 行更改为:

In the script you linked to, change line 120 from:

dev_id = 0

到:

dev_id = bluez.hci_get_route(ADDRESS_FOR_YOUR_BLUETOOTH_DEVICE)

为了测量接近度,脚本调用函数

To measure proximity, the script calls the function

device_inquiry_with_with_rssi(sock)

应该打印蓝牙设备 ID 及其相应 RSSI 值的列表(请参阅第 95-102 行).通常,设备必须处于配对模式才能显示在查询结果中.该函数还将 ID/RSSI 列表作为数组返回,因此您可以从自己的代码中调用它并处理返回的结果.RSSI 值表示设备的信号强度,因此是邻近度的间接度量(参见 从启用蓝牙低功耗的设备的 RSSI 值中查找距离).

which should print a list of bluetooth device ids and their corresponding RSSI values (see lines 95-102). Typically, devices must be in pairing mode to show up in the inquiry results. The function also returns the list of IDs/RSSIs as an array, so you can call it from your own code and process the returned results. The RSSI value indicates the signal strength of a device, and so is an indirect measure of proximity (see Finding distance from RSSI value of Bluetooth Low Energy enabled device ).

这篇关于在树莓派上使用蓝牙测量接近度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆