既然因為 UART 的問題將樹莓派 3 的速度調降,以求『藍牙』之『共存』,也已知道可能影響到『藍牙』的操作性,將如之何哉?由於
藍牙
藍牙(英語:Bluetooth),一種無線技術標準,用來讓固定與行動裝置,在短距離間交換資料,以形成個人區域網路(PAN)。其使用短波特高頻(UHF)無線電波,經由2.4至2.485 GHz的ISM頻段來進行通信[1]。1994年由電信商愛利信(Ericsson)發展出這個技術[2]。它最初的設計,是希望建立一個RS-232資料線的無線通訊替代版本。它能夠連結多個裝置,克服同步的問題。
藍牙技術目前由藍牙技術聯盟(SIG)來負責維護其技術標準。截至2013年為止,SIG已擁有超過20,000間公司成員,其成員的領域分布在電信、電腦、網路與消費性電子產品上[3]。IEEE曾經將藍牙技術標準化為IEEE 802.15.1,但是這個標準已經不再繼續使用。
名稱和LOGO
藍牙(Bluetooth)一詞是斯堪的納維亞語言詞彙Blåtand/Blåtann的英語化。這個詞的來源是10世紀丹麥和挪威國王藍牙哈拉爾(丹麥語:Harald Blåtand Gormsen),借國王的綽號「Blåtand」當名稱,[4]直接翻譯成中文爲「藍牙」(blå=藍,tand=牙)。在中文圈,「藍牙」又稱為「藍芽」。2006年,藍牙技術聯盟組織已將全球中文譯名統一改採直譯為「藍牙」,並註冊為該組織的註冊商標。
藍牙的標誌是盧恩字母 (Hagall,ᚼ)和 (Bjarkan,ᛒ)的組合,也就是Harald Blåtand的首字母HB的合寫。
……
藍牙4.0
- 藍牙4.0是Bluetooth SIG於2010年7月7日推出的新的規範。其最重要的特性是支援省電;
- Bluetooth 4.0,協定組成和當前主流的Bluetooth h2.x+EDR、還未普及的Bluetooth h3.0+HS不同,Bluetooth 4.0是Bluetooth從誕生至今唯一的一個綜合協定規範,
- 還提出了「低功耗藍牙」、「傳統藍牙」和「高速藍牙」三種模式。
- 其中:高速藍牙主攻資料交換與傳輸;傳統藍牙則以資訊溝通、裝置連線為重點;藍牙低功耗顧名思義,以不需占用太多頻寬的裝置連線為主。前身其實是 NOKIA開發的Wibree技術,本是作為一項專為行動裝置開發的極低功耗的移動無線通信技術,在被SIG接納並規範化之後重新命名為 Bluetooth Low Energy(後簡稱低功耗藍牙)。這三種協定規範還能夠互相組合搭配、從而實作更廣泛的應用模式,此外,Bluetooth 4.0還把藍牙的傳輸距離提升到100米以上(低功耗模式條件下)。
- 分Single mode與Dual mode。
- Single mode只能與BT4.0互相傳輸無法向下相容(與3.0/2.1/2.0無法相通);Dual mode可以向下相容可與BT4.0傳輸也可以跟3.0/2.1/2.0傳輸
- 超低的峰值、平均和待機模式功耗,覆蓋範圍增強,最大範圍可超過100米。
- 速度:支援1Mbps資料傳輸率下的超短封包,最少8個八組位,最多27個。所有連線都使用藍牙2.1加入的減速呼吸模式(sniff subrating)來達到超低工作迴圈。
- 跳頻:使用所有藍牙規範版本通用的自適應跳頻,最大程度地減少和其他2.4 GHz ISM頻段無線技術的串擾。
- 主控制:可以休眠更長時間,只在需要執行動作的時候才喚醒。
- 延遲:最短可在3毫秒內完成連線設定並開始傳輸資料。
- 健壯性:所有封包都使用24-bit CRC校驗,確保最大程度抵禦干擾。
- 安全:使用AES-128 CCM加密演算法進行封包加密和認證。
- 拓撲:每個封包的每次接收都使用32位元尋址,理論上可連線數十億裝置;針對一對一連線最佳化,並支援星形拓撲的一對多連線;使用快速連線和斷開,資料可以在網狀拓撲內轉移而無需維持複雜的網狀網路。
藍牙4.1
- 藍牙 4.1 是藍牙技術聯盟於 2013 年底推出的新的規範,其目的是為了讓 Bluetooth Smart 技術最終成為物聯網 (Internet of Everything) 發展的核心動力。
- 此版本為藍牙 4.0 的軟體更新版本,搭載藍牙 4.0 裝置的終端可通過軟體更新獲得此版本。
- 對於開發人員而言,該更新是藍牙技術發展史上一項重要的進步。該更新提供了更高的靈活性和掌控度,讓開發人員能創造更具創新並催化物聯網(IOT)發展的產品。
- 支援多裝置連接。
- 智慧連接:增加設置裝置間連接頻率的支援。製造商可以對裝置設置連接進行設置,使得裝置可以更加智慧的控制裝置電量。
藍牙4.2
- 藍牙4.2是藍牙技術聯盟於2014年12月推出的新的規範。
───
實在是個『大規範』,而且與時變遷!根本無從說起,故於此處先列出重要的資訊來源,以備不時之需︰
……… 《W!O+ 的《小伶鼬工坊演義》︰樹莓派 3 三兩事之藍牙篇【上】》
想要在 OpenWrt 上玩『藍牙』乎?因為樹莓派 3B 透過 UART 連接 Bluetooth ,因此這個 HowTo 文本
USB Bluetooth support
Installation
Manually installing all needed packages
If you wish to manually install all needed packages needed for bluetooth support just issue this command:
Space needed: ~1.3 MB
opkg update opkg install kmod-bluetooth bluez-libs bluez-utils kmod-usb-core kmod-usb-uhci kmod-usb2 usbutils
雖說僅供參考,至少可以知道如何安裝 bluez 呦!
由於 OpenWrt/LEDE 沒得用『bluetoothctl』程式,底下指南將以『藍牙 BLE 』為主︰
‧關閉 3B UART
nano /boot/config.txt
## enable_uart
## Enables or disables uart pin multiplexing
## Raspberry Pi 1/2: if unset, uart is enabled by default
## Raspberry Pi 3: if unset uart is disabled by default
##
# enable_uart=1
‧連接『藍牙』
root@LEDE:~# hciattach /dev/ttyAMA0 bcm43xx 115200 noflow -bcm43xx_init bcm43xx_init Flash firmware /lib/firmware/brcm/BCM43430A1.hcd Set Controller UART speed to 115200 bit/s Device setup complete
‧起始 hci0
root@LEDE:~# hciconfig hci0 up
[ 38.330465] uart-pl011 3f201000.uart: no DMA platform data
‧檢查狀態
root@LEDE:~# hciconfig -a hci0: Type: BR/EDR Bus: UART BD Address: B8:27:EB:68:1A:C4 ACL MTU: 1021:8 SCO MTU: 64:1 UP RUNNING RX bytes:1308 acl:0 sco:0 events:66 errors:0 TX bytes:838 acl:0 sco:0 commands:66 errors:0 Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87 Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 Link policy: RSWITCH SNIFF Link mode: SLAVE ACCEPT Name: 'BCM43438A1 37.4MHz Raspberry Pi 3-0062' Class: 0x000000 Service Classes: Unspecified Device Class: Miscellaneous, HCI Version: 4.1 (0x7) Revision: 0x168 LMP Version: 4.1 (0x7) Subversion: 0x2209 Manufacturer: Broadcom Corporation (15)
‧嘗試 scan
root@LEDE:~# hcitool scan Scanning ... 74:E5:43:88:E4:16 localhost.localdomain-0 51:73:00:0D:4A:1C Bluetooth 3.0 Keyboard
root@LEDE:~# hcitool lescan LE Scan ... 68:C9:0B:17:7E:80 (unknown) 68:C9:0B:17:7E:80 CC2650 SensorTag 12:AD:18:2F:78:08 (unknown) 50:B3:C7:C3:F2:A3 (unknown) 48:98:D3:CA:BA:20 (unknown) 50:B3:C7:C3:F2:A3 (unknown)
‧實測 TI SensorTag
root@LEDE:~# btmgmt le on hci0 Set Low Energy complete, settings: powered br/edr le root@LEDE:~# btmgmt -h btmgmt ver 5.38 Usage: btmgmt [options] <command> [command parameters] Options: --index <id> Specify adapter index --verbose Enable extra logging --help Display help Commands: version Get the MGMT Version commands List supported commands config Show configuration info info Show controller info extinfo Show extended controller info auto-power Power all available features power Toggle powered state discov Toggle discoverable state connectable Toggle connectable state fast-conn Toggle fast connectable state bondable Toggle bondable state pairable Toggle bondable state linksec Toggle link level security ssp Toggle SSP mode sc Toogle SC support hs Toggle HS support le Toggle LE support advertising Toggle LE advertising bredr Toggle BR/EDR support privacy Toggle privacy support class Set device major/minor class disconnect Disconnect device con List connections find Discover nearby devices find-service Discover nearby service stop-find Stop discovery name Set local name pair Pair with a remote device cancelpair Cancel pairing unpair Unpair device keys Load Link Keys ltks Load Long Term Keys irks Load Identity Resolving Keys block Block Device unblock Unblock Device add-uuid Add UUID rm-uuid Remove UUID clr-uuids Clear UUIDs local-oob Local OOB data remote-oob Remote OOB data did Set Device ID static-addr Set static address public-addr Set public address ext-config External configuration debug-keys Toogle debug keys conn-info Get connection information io-cap Set IO Capability scan-params Set Scan Parameters get-clock Get Clock Information add-device Add Device del-device Remove Device clr-devices Clear Devices bredr-oob Local OOB data (BR/EDR) le-oob Local OOB data (LE) advinfo Show advertising features advsize Show advertising size info add-adv Add advertising instance rm-adv Remove advertising instance clr-adv Clear advertising instances For more information on the usage of each command use: btmgmt <command> --help
root@LEDE:~# gatttool -b 68:C9:0B:17:7E:80 -I [68:C9:0B:17:7E:80][LE]> connect Attempting to connect to 68:C9:0B:17:7E:80 Connection successful [68:C9:0B:17:7E:80][LE]> char-write-cmd 0x24 01 [68:C9:0B:17:7E:80][LE]> char-read-hnd 0x21 Characteristic value/descriptor: 40 0b 34 0e [68:C9:0B:17:7E:80][LE]> quit (gatttool:957): GLib-WARNING **: Invalid file descriptor.