[BlueZ] 1、Download install and use the BlueZ and hcitool on PI 3B+
星期日, 02. 九月 2018 11:58下午 - beautifulzzzz

1. Introduction
Bluez is the default Bluetooth protocol stack on Linux. It should be present and installed on your Linux distribution. If not, building and installing from source is not too difficult:
- Download the latest stable source release of Bluez from here. Unzip the compressed file you downloaded.
- Install the headers and libraries required for Bluez compilation:

2. Download And Install
I follow the blog (Installing Bluez 5.44 onto Raspbian?) to install bluez-5.50.
Download the most recent version from the official page:http://www.bluez.org/download/.
For example, at the time of writing it was 5.50, so I used(on my pi):
wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.50.tar.xz
Then I extracted it and built it:
tar -xf bluez-5.50.tar.xz
cd bluez-5.50
**Read the README! **It lists the dependencies and the configure switches:
Install the dependencies first: (glib, dbus, libdbus, udev, etc.)
sudo apt install libdbus-1-dev libudev-dev libical-dev libreadline-dev
note: If you do not install the libdbus-1-dev, you will later get this strange error:
configure: error: D-Bus >= 1.6 is required
once you've installed dependencies, you can configure switches:
./configure --prefix=/usr --mandir=/usr/share/man --sysconfdir=/etc --localstatedir=/var --enable-experimental
then do:
make
sudo make install
It takes maybe 10 minutes to compile. After installing, you should find bluetoothd in /usr/libexec/bluetooth. You should also see bluetoothd in /usr/lib/bluetooth.
Go to each of these directories and type
./bluetoothd --version
You'll note that the one in libexec is new and the one in lib is old.
In order to make sure that d-bus is talking to you new BlueZ 5.50 and not your old BlueZ 5.43, you need to tell systemd to use the new bluetooth daemon:
sudo vim /lib/systemd/system/bluetooth.service
Make sure the exec.start line points to your new daemon in /usr/libexec/bluetooth.
For me, that wasn't enough. No matter what, upon restart I always got bluetoothd 5.43... So I just created a symlink from the old one to the new.
First rename the old file:
sudo mv /usr/lib/bluetooth/bluetoothd /usr/lib/bluetooth/bluetoothd-543.orig
Create the symlink:
sudo ln -s /usr/libexec/bluetooth/bluetoothd /usr/lib/bluetooth/bluetoothd
sudo systemctl daemon-reload
That should do it.

3. How to use the bluez and hcitool
3.1 setup bluetooth service
Start the bluetooth service and enable automatic startup, assuming you're using systemd as the init daemon:
sudo systemctl start bluetooth.service
sudo systemctl enable bluetooth.service
3.2 hcitool scan for bluetooth devices
Before start scanning make sure that your bluetooth device is turned on and not blocked, you can check that with the rfkill command:
sudo rfkill list
If the bluetooth device is blocked (soft or hard blocked), unblock it with the rfkill command again:
sudo rfkill unblock bluetooth
Bring up the bluetooth device with hciconfig command and start scanning, make sure the target device's bluetooth is on and It's discoverable:
sudo hciconfig hci0 up
hcitool scan
Wait few moment to complete the hcitool scan or hcitool lescan, the results will be something like bellow:


Here 00:1A:7D:DA:71:0A is the bluetooth MAC address and SHEN-PC is the name of the bluetooth device, i.e. an PC.
note: use hcitool lescan will forever scan ble devices, if use ctrl+c stop it, it will show error(ref to LINKS 4 to solve):
hcitool lescan
Set scan parameters failed: Input/output error
3.3 bluetooth service discovery
Now we have the bluetooth MAC address of the target device, use the sdptool command to know which services (like DUN, Handsfree audio) are available on that target device.
sdptool browse 28:ED:6A:A0:26:B7
You can also use the interactive bluetoothctl tool for this purpose.
If the target device is present, you can ping it with l2ping command, requires root privilege:
➜ bluez-5.50 sudo l2ping 94:87:E0:B3:AC:6F
Ping: 94:87:E0:B3:AC:6F from B8:27:EB:8E:CC:51 (data size 44) ...
44 bytes from 94:87:E0:B3:AC:6F id 0 time 53.94ms
44 bytes from 94:87:E0:B3:AC:6F id 1 time 77.12ms
44 bytes from 94:87:E0:B3:AC:6F id 2 time 38.63ms
44 bytes from 94:87:E0:B3:AC:6F id 3 time 46.13ms
44 bytes from 94:87:E0:B3:AC:6F id 4 time 59.96ms
5 sent, 5 received, 0% loss
So, bluetooth service discovery is useful to determine the type of the device, like if it's a bluetooth mp3 player or it's a keyboard.

LINKS
- 1.Bluetooth on Modern Linux by Szymon Janc
- 2.dbus-python tutorial
- 3.Linux bluetooth setup with bluez and hcitool
- 4.hcitool lescan shows I/O error

@beautifulzzzz
智能硬件、物联网,热爱技术,关注产品
博客:http://blog.beautifulzzzz.com
园友交流群:414948975
[BlueZ] 1、Download install and use the BlueZ and hcitool on PI 3B+的更多相关文章
- [BlueZ] 2、使用bluetoothctl搜索、连接、配对、读写、使能notify蓝牙低功耗设备
星期三, 05. 九月 2018 02:03上午 - beautifulzzzz 1.前言 上一篇讲了如何编译安装BlueZ-5,本篇主要在于玩BlueZ,用命令行去操作BLE设备: [BlueZ] ...
- [BlueZ] 3、使用 meshctl 连接控制一个 sig mesh 灯
目录 前言 1.准备工作 2.meshctl 连接.配置.控制 sig mesh 灯 3.最终效果: LINKS 前言 本文介绍如何使用 meshctl 配对.连接.控制一个 sig mesh 球泡灯 ...
- Linux随笔之——./configure、make、make install(转)
原文连接:http://www.linuxidc.com/Linux/2011-02/32211.htm 这些都是典型的使用GNU的AUTOCONF和AUTOMAKE产生的程序的安装步骤. ./con ...
- ./configure、make、make install
这些都是典型的使用GNU的AUTOCONF和AUTOMAKE产生的程序的安装步骤 一.基本信息 1../configure 是用来检测你的安装平台的目标特征的.比如它会检测你是不是有CC或GCC,并不 ...
- package.json和npm install、cnpm install 的問題
問題:最近使用cnpm安装项目依赖后,运行项目出现样式错乱问题. 描述:最近项目开发,需求参插了很多个版本,所以在前端项目的主干上拉好几套分支代码.拉的分支并不会把node_modules也拉过去,所 ...
- Linux 命令详解(三)./configure、make、make install 命令
这些都是典型的使用GNU的AUTOCONF和AUTOMAKE产生的程序的安装步骤 一.基本信息 1../configure 是用来检测你的安装平台的目标特征的.比如它会检测你是不是有CC或GCC,并不 ...
- 转:eclipse maven build、maven install 等区别
原文地址:eclipse maven build.maven install 等区别
- eclipse中的maven build、maven clean、maven install和maven test的区别
eclipse中的maven build.maven clean.maven install和maven test的区别 https://www.cnblogs.com/Marydon20170307 ...
- Linux中./configure、make、make install详解
./configure && make && make install详解 2010-08-03 23:30:05 标签:休闲 ./configure &&a ...
随机推荐
- eclipse,代码中有错误,项目或者java类中却不显示红叉
修改eclipse代码提示级别1.单个项目修改项目上右键-->properties-->java compiler-->building-->enable project sp ...
- MUI之App开发
一般开发APP分为两种:1.原生ios和android语言开发.2.混合开发,里边穿插h5的东西. 3.第三种:现在因为前端用hbuilder工具开发的情况越来越多,这家公司又提供了更多的选择,所以近 ...
- 高可用Redis(四):列表,集合与有序集合
1.列表类型 1.1 列表数据结构 左边为key,是字符串类型 右边为value,是一个有序的队列,与python的列表结构相同 可以在Redis中对列表的value进行如下操作 从左边添加元素 从右 ...
- C# 高级编程02----手动创建C#程序
在日常工作中使用C# 开发的时候,通常使用宇宙第一神器VS进行开发.为了了解编译过程,这里采用文本编辑器的方式编写一个C#程序 一.创建一个C#程序 1.使用记事本工具创建一个名为First.cs的文 ...
- PADS Layout VX.2.3 出Gerber文件时遇到一个奇怪的现象
操作系统:Windows 10 x64 工具:PADS Layout VX.2.3 对CAM Documents的NC Drill的Units进行如下设置: 之后使用CAM Preview功能,查看N ...
- C++智能指针剖析(上)std::auto_ptr与boost::scoped_ptr
1. 引入 C++语言中的动态内存分配没有自动回收机制,动态开辟的空间需要用户自己来维护,在出函数作用域或者程序正常退出前必须释放掉. 即程序员每次 new 出来的内存都要手动 delete,否则会造 ...
- 函数式编程 - 函数缓存Memoization
函数式编程风格中有一个"纯函数"的概念,纯函数是一种无副作用的函数,除此之外纯函数还有一个显著的特点:对于同样的输入参数,总是返回同样的结果.在平时的开发过程中,我们也应该尽量把无 ...
- Docker使用Mysql镜像命令
本次使用的环境是win10下的hyper-v安装的CentOS7系统 控制台输入命令: docker run -p 3307:3306 --name mysql01 -v $PWD/conf:/etc ...
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisConnectionFactory' defined in class path resource
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'r ...
- 身份证号验证js程序
最近注册一个网站,居然让我输入个人身份证号,身份证号是个人信息,怎么能告诉你呢? 输入正确的身份证号没有任何问题. 我就仅仅改了最后一位,就告诉我身份证号不对,你是怎么知道的呢?所以,搜了下身份证号的 ...