美文网首页
树梅派蓝牙

树梅派蓝牙

作者: 古三井 | 来源:发表于2017-11-13 18:19 被阅读0次

一、升级安装蓝牙相关软件包

sudo apt-get update

sudo apt-get upgrade -y

sudo apt-get dist-upgrade -y

sudo apt-get install pi-bluetooth bluez bluez-firmware blueman

二、添加pi用户到蓝牙组

sudo usermod-G bluetooth -a pi

三、重启sudo reboot

查看自己的蓝牙设备

hciconfig

设备打开

sudo hciconfig hci0 up

设备关闭

sudo hciconfig hci0 down

列出蓝牙设备

sudo hcitool lescan

57:4D:70:F9:11:92 (unknown)

C6:05:04:03:F1:BF (unknown)

C6:05:04:03:F1:BF ClinkBlood

5B:B4:3D:DD:C1:CE (unknown)

5B:B4:3D:DD:C1:CE (unknown)

61:1A:D6:26:12:ED (unknown)

61:1A:D6:26:12:ED (unknown)

44:0E:5A:35:6A:A0 (unknown)

44:0E:5A:35:6A:A0 (unknown)

64:09:80:6F:18:84 (unknown)

查看蓝牙设备信息

sudo hcitool info C6:05:04:03:F1:BF

连接蓝牙设备

gatttool -b C6:05:04:03:F1:BF -I

[C6:05:04:03:F1:BF][LE]> connect

Attempting to connect to C6:05:04:03:F1:BF

Connection successful

[C6:05:04:03:F1:BF][LE]> primary

attr handle: 0x0001, end grp handle: 0x0009 uuid: 00001800-0000-1000-8000-00805f9b34fb

attr handle: 0x000c, end grp handle: 0x000f uuid: 00001801-0000-1000-8000-00805f9b34fb

attr handle: 0x0010, end grp handle: 0x0016 uuid: 0000180a-0000-1000-8000-00805f9b34fb

attr handle: 0x0017, end grp handle: 0x001e uuid: 00005970-6d75-4749-5053-676e6f6c7553

attr handle: 0x0020, end grp handle: 0x0029 uuid: 0000fc00-0000-1000-8000-00805f9b34fb

[C6:05:04:03:F1:BF][LE]> characteristics

handle: 0x0002, char properties: 0x02, char value handle: 0x0003, uuid: 00002a00-0000-1000-8000-00805f9b34fb

handle: 0x0004, char properties: 0x02, char value handle: 0x0005, uuid: 00002a01-0000-1000-8000-00805f9b34fb

handle: 0x0006, char properties: 0x0a, char value handle: 0x0007, uuid: 00002a02-0000-1000-8000-00805f9b34fb

handle: 0x0008, char properties: 0x02, char value handle: 0x0009, uuid: 00002a04-0000-1000-8000-00805f9b34fb

handle: 0x000d, char properties: 0x22, char value handle: 0x000e, uuid: 00002a05-0000-1000-8000-00805f9b34fb

handle: 0x0011, char properties: 0x02, char value handle: 0x0012, uuid: 00002a29-0000-1000-8000-00805f9b34fb

handle: 0x0013, char properties: 0x02, char value handle: 0x0014, uuid: 00002a24-0000-1000-8000-00805f9b34fb

handle: 0x0015, char properties: 0x02, char value handle: 0x0016, uuid: 00002a23-0000-1000-8000-00805f9b34fb

handle: 0x0018, char properties: 0x0a, char value handle: 0x0019, uuid: 01005970-6d75-4749-5053-676e6f6c7553

handle: 0x001a, char properties: 0x12, char value handle: 0x001b, uuid: 02005970-6d75-4749-5053-676e6f6c7553

handle: 0x001d, char properties: 0x0a, char value handle: 0x001e, uuid: 03005970-6d75-4749-5053-676e6f6c7553

handle: 0x0021, char properties: 0x08, char value handle: 0x0022, uuid: 0000fca0-0000-1000-8000-00805f9b34fb

handle: 0x0024, char properties: 0x10, char value handle: 0x0025, uuid: 0000fca1-0000-1000-8000-00805f9b34fb

handle: 0x0028, char properties: 0x08, char value handle: 0x0029, uuid: 0000fca2-0000-1000-8000-00805f9b34fb

[C6:05:04:03:F1:BF][LE]> char-read-hnd 0x001b

Characteristic value/descriptor: fe fd 40 01 6c 0a

最后写个脚本:

import os

import time

import sys

while True:

time.sleep(1)

out=sys.stdout

process = os.popen("sudo gatttool -b C6:05:04:03:F1:BF --char-read -a 0x001b")

output = process.read()

out.write("\n%s" % (output))

out.flush()

process.close

相关文章

  • 树梅派蓝牙

    一、升级安装蓝牙相关软件包 sudo apt-get update sudo apt-get upgrade -y...

  • Raspberry Pi使用记录

    树梅派是很适合个人玩耍的开源电路板。这里记录使用树梅派过程中,收集到的使用技巧。文中描述的技巧只在Raspberr...

  • 从零在树梅派上搭建docker swarm集群

    概述 当初是向想使用k8s来做,但是这个东西在树梅派上貌似不是特别的成熟,还有因为i就只有两台树梅派,所以没必要这...

  • 树梅派国内源

    编辑/etc/apt/sources.list文件(需要使用sudo), 在文件最前面添加以下条目(操作前请做好相...

  • 树梅派安装系统

    这样插上去哈,然后: screen /dev/tty.USB0 115200 sudo picocom /dev/...

  • 树莓派基本配置

    1 、 OS 版本控制 树梅派os 2019 2、 wifi 配置https://www.cnblogs.com...

  • docker swarm 修改集群ip

    概述 事情是这样的,我在树梅派上运行着docker swarm的集群原来的ip是192.168.0.113,之后因...

  • 树梅派安装docker-compose

    概述 因为树梅派是arm架构,docker-compose是没有提供官方的二进制文件的,所以我们要使用python...

  • 树梅派中的GUI编程

    1.tkinter 2.pyqt4 sudo apt-get install python-qt4 monkey-...

  • 树梅派开机启动脚本

    cd /etc/init.dtouch xxx_script //新建脚本文件sudo chmod a+x xxx...

网友评论

      本文标题:树梅派蓝牙

      本文链接:https://www.haomeiwen.com/subject/ruzzmxtx.html