[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
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...