[BlueZ] 1、Download install and use the BlueZ and hcitool on PI 3B+

来源:https://www.cnblogs.com/zjutlitao/archive/2018/09/03/9576589.html
-Advertisement-
Play Games

星期日, 02. 九月 2018 11:58下午 beautifulzzzz ![][ bar] 1. Introduction Bluez is the default Bluetooth protocol stack on Linux. It should be present and inst ...


星期日, 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.

@beautifulzzzz
智能硬體、物聯網,熱愛技術,關註產品
博客:http://blog.beautifulzzzz.com
園友交流群:414948975

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • Win10隱藏了20%的網速,下麵叫你怎麼釋放它: 1.按Win+R調出運行,輸入gpedit.msc點擊確定; 2.點擊windows設置,右擊基於策略Qos,選擇高級Qos設置: 3.勾選如圖方框,選擇級別3: 4.選擇管理模板-網路-Qos數據包計劃程式,雙擊限制可保留帶寬,進入: 5.選擇已 ...
  • RHEL6.5 DHCP伺服器搭建: DHCP伺服器是用來分配給其它客戶端IP地址用的,在RHEL 6.5中DHCP伺服器搭建方法如下: 第一步,通過yum安裝dhcp服務: 命令:yum install dhcp 第二步:備份dhcp的主配置文件: 命令:mv /etc/dhcp/dhcpd.co ...
  • 轉自[LCD顯示異常分析——開機閃現花屏 ](https://blog.csdn.net/hexiaolong2009/article/details/79190789) 最近在工作中,有同事遇到LCD開機瞬間會閃現雪花屏的問題,而這類問題都有個共同點,那就是都發生在帶GRAM的屏上,同樣的問題,在 ...
  • 一、Centos7使用firewall的管理防火牆 1.firewalld基本使用 啟動:systemctl start firewalld 關閉:systemctl stop firewalld 狀態:systemctl status firewalld 開機禁用:systemctl disabl ...
  • 參考鏈接: Windows下如何查看某個埠被誰占用 1. 遇到的問題 在Windows下的IDEA中啟動Web服務顯示8080埠被占用,程式無法正確啟動。 2. 解決思路 關閉占用進程的應用 通過Google檢索遇到的問題 查到了 Windows下如何查看某個埠被誰占用 3. 解決方案 3.1 ...
  • 一.初識bash shell 1.1 啟動 shell GNU bash shell 能提供對Linux系統的互動式訪問。通常是在用戶登錄終端時啟動,登錄時系統啟動shell依賴於用戶賬戶的配置。etc/passwd文件包含了所有系統用戶列表以及每個用戶的基本配置信息。 如上圖:最後一個欄位,告訴用 ...
  • 在正式講述虛擬記憶體之前需要提及存儲器的層級結構以及進程在記憶體中的結構。 存儲器的層級結構速度從快到慢排列如下 寄存器——L1高速緩存——L2高速緩存——L3高速緩存——主存——磁碟——分散式文件系統 而成本也是從高到低,空間是從低到高。 兩個相鄰的存儲設備,前者往往是充當後者的高速緩存,後者往往存儲 ...
  • WHMCS 7.5 發佈了,它開始支持 PHP 7.2,這裡就寫個簡單的教程記錄一下安裝方式。 1、準備工作 首先,我們需要按照 在Debian 9 / Debian 8 下使用源安裝方式安裝 LEMP 一文,安裝好 LEMP 環境,可以選一些需要用到的 PHP 7.2 軟體包: 2、安裝 ionC ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...