在尝试了APP之后,发现SensorTile.box有实时优势,那就是可以通过蓝牙连接,而不是每次取完数据之后从TF卡里面把数据拿出来分析;同时,如果没有实时的蓝牙连接,TF卡里面的数据也足以保证数据记录的完整性,两者相辅相成,互为比较。在这里我尝试用python获取蓝牙数据。首先在笔记本上编写python代码实现tile.box的查找,如下:
import time
from bluetooth import *
alreadyFound = []
def findDevs():
foundDevs = discover_devices(lookup_names=True)
for (addr, name) in foundDevs:
if (addr not in alreadyFound) and (name=='TILEBOX'):
alreadyFound.append(addr)
if __name__=='__main__':
while alreadyFound == []:
findDevs()
time.sleep(5)
print(alreadyFound)
执行后,
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
================ RESTART: D:\bluetooth\tilebox.py ================
['C0:50:27:32:09:33']
>>>
接下来尝试把代码移植到树莓派上,首先需要在树莓派上安装蓝牙组件,sudo apt-get install libbluetooth-dev,安装完成以后,可以通过命令行查看蓝牙设备
pi@raspberrypi:~$ hciconfig
hci0: Type: Primary Bus: UART
BD Address: DC:A6:32:13:8A:2B ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING
RX bytes:806 acl:0 sco:0 events:52 errors:0
TX bytes:2515 acl:0 sco:0 commands:52 errors:0
pi@raspberrypi:~$ hcitool dev
Devices:
hci0 DC:A6:32:13:8A:2B
本机的蓝牙地址是DC:A6:32:13:8A:2B,激活蓝牙设备
pi@raspberrypi:~$ service bluetooth start
pi@raspberrypi:~$ sudo hciconfig hci0 up
pi@raspberrypi:~$ hcitool scan
很可惜,找不到tile.box,所以代码移植肯定是暂不成功的。后续准备从两方面开展:
1、使用电脑调试信息获取;
2、调通树莓派的蓝牙。 |