图片 11

如何设计VR应用,PI定制版本)版本Linux系统

星期三, 05. 九月 2018 02:03上午 – beautifulzzzz

Unity
Editor and Android Runtime for
Daydream

蓝牙 APIs 能够使得应用具备上边功用:

Receiving GATT Notifications

前言

多年来学习Linux相关的东西,个中三个思路是看书时用三星GALAXY Tab上的SSH连接Linux主机实验。先是认为台式机功耗大、噪音大,后来台式机电脑也感觉耗广播电视大学、噪音大。于是就悟出了马林派,Google查了一下后精通今后黄金时代度是二〇一五年七月出产的Raspberry
Pi 3 Model B型号了。

具体手艺参数:

1.2GHz 64-bit quad-core ARMv8 CPU
802.11n Wireless LAN
1GB RAM
4 USB ports/40 GPIO pins/Full HDMI port/Ethernet port
Bluetooth 4.1/Bluetooth Low Energy (BLE)
Combined 3.5mm audio jack and composite video
Camera interface (CSI)
Display interface (DSI)
Micro SD card slot (now push-pull rather than push-push)
VideoCore IV 3D graphics core

图片 1

Raspberry Pi 3 Model B 布局图

图片 2

Raspberry Pi 3 Model B 实物图

图片 3

Tmall购物到货图

图片 4

设置好外壳图

早先方的本事参数知道沙窝窝派CPU是1.2GHz 64-bit quad-core
ARMv8,所以要设置专门为ARM微机编译的Linux操作系统。先是安装了合法的Raspbian
Jessie(Debian 8 Jessie的Raspberry
PI定制版本)版本Linux系统,但因为是用以学习Linux命令和Wordpress服务器,那么些本子里剩下的东西太多了。后来比较了种种Raspberry
PI的Linux版本,选取了Minibian那么些系统(当然也是Jessie版本了)。

松木丛派官网(Raspbian
Jessie):http://www.raspbian.org

Minibian官方网站(Raspbian Jessie二零一四年7月十五一日版本):https://minibianpi.wordpress.com/

图片 5

Minibian系统运行截图

图片 6

 

5.与其余设施之间数据传输

BLE 权限


In order to use Bluetooth features in your application, you must declare
the Bluetooth permission BLUETOOTH. You need this permission to perform
any Bluetooth communication, such as requesting a connection, accepting
a connection, and transferring data.
为了在你的选拔中采纳蓝牙5.0特点,你应当要评释Bluetooth权限 BLUETOOTH
。你要此权限技能实践别的蓝牙( Bluetooth® 卡塔尔通讯,如:央求三个总是,接纳贰个总是,和传输数据。

If you want your app to initiate device discovery or manipulate
Bluetooth settings, you must also declare the BLUETOOTH_ADMIN
permission. Note: If you use the BLUETOOTH_ADMIN permission, then you
must also have the BLUETOOTH permission.
假诺您想要你的app运行设备开掘或调控蓝牙5.0设置,你必需也要申明BLUETOOTH_ADMIN 权限。注意:如若您用了 BLUETOOTH_ADMIN
权限,则还必得有 BLUETOOTH 权限。

Declare the Bluetooth permission(s) in your application manifest file.
For example:
声称蓝牙5.0权限在您的行使manifest文件,譬如:

<uses-permission android:name=”android.permission.BLUETOOTH”/>
<uses-permission
android:name=”android.permission.BLUETOOTH_ADMIN”/>

If you want to declare that your app is available to BLE-capable devices
only, include the following in your app’s manifest:
万黄金时代您想要评释你的app仅支持有BLE作用的设施,在你的app的manifest中填上如下内容:

<uses-feature android:name=”android.hardware.bluetooth_le”
android:required=”true”/>
However, if you want to make your app available to devices that don’t
support BLE, you should still include this element in your app’s
manifest, but set required=”false”. Then at run-time you can determine
BLE availability by using PackageManager.hasSystemFeature():
下一场,倘若你想要你的app能够被不帮助BLE的配备取得,你照旧亟待满含那个因素在你的app的manifest文件中,但是,供给安装required为false。然后在您的代码运营时,你能够通过使用确认PackageManager.hasSystemFeature(卡塔尔方法来承认BLE是不是可获得。

// Use this check to determine whether BLE is supported on the device. Then
// you can selectively disable BLE-related features.
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
    Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
    finish();
}

Note: LE Beacons are often associated with location. In order to use
BluetoothLeScanner without a filter, you must request the user’s
permission by declaring either the ACCESS_COARSE_LOCATION or
ACCESS_FINE_LOCATION permission in your app’s manifest file. Without
these permissions, scans won’t return any results.

注意:LE信标常常与地方相关联。
为了在还没过滤器之处下选取蓝牙( Bluetooth® 卡塔尔(英语:State of Qatar)( Bluetooth® 卡塔尔LeScanner,您必得经过注解应用程序的清单文件中的ACCESS_COARSE_LOCATION或ACCESS_FINE_LOCATION权限来倡议客户的权杖。

安装操作系统

安装Minibian的手续(以安装了Microsoft Windows 10
X64的计算机作为帮忙平台):
1、策画几个Micro SD读取卡,体积在16GB至64GB之间就可以,速度越快越好;
2、将Micro SDHC卡以FAT格式化;
3、将下载的“二〇一五-03-12-jessie-minibian.tar.gz”解压缩;
4、使用Win32 Disk
Imager(链接地址:https://sourceforge.net/projects/win32diskimager/)将解压拿到的“二〇一六-03-12-jessie-minibian.img”文件写入Micro
CF内存卡;
5、将写有Minibian系统的Micro SD卡放入悬钩子派的Micro TF内存卡槽(Micro SD
卡德 Slot);
6、欧洲红树莓派加电开机,Minibian的客商名字为“root”,开头密码为“raspberry”(记得登入后先是件事正是运用“passwd
root”命令矫正root客商的密码)。

相对记得:改正root客户的密码,修改root客商的密码,改善root客户的密码!

3、bluetoothctl——NB的新工具

指令行踏向bluetoothctl操作情形([\#6](https://mcuoneclipse.com/2016/12/19/tutorial-ble-pairing-the-raspberry-pi-3-model-b-with-hexiwear/))

bluetoothctl

自己在手提式有线话机上用lightblue模拟一个BLE设备ty_prod,之后对其service进行订正,调用scan
on实行检索照旧老的,
谈到底发掘要先用remove移除此前的装置,之后再scan就能现出[NEW] Device 72:3B:E1:81:4E:4F ty_prod设备
注: 用lightblue模拟的装置的MAC不是向来的
注:
笔者发觉在lightblue中不管怎么模拟BLE设备,大器晚成旦被连上寻找到的service都以IPone的

[bluetooth]# devices
Device 28:ED:6A:A0:26:B7 ty_prod
Device 58:71:33:00:00:24 Bluetooth Keyboard
Device 00:1A:7D:DA:71:0A SHEN-PC
Device 94:87:E0:B3:AC:6F Mi Phone
[bluetooth]# remove 28:ED:6A:A0:26:B7 
...
[bluetooth]# scan on
Discovery started
[NEW] Device 72:3B:E1:81:4E:4F ty_prod
[bluetooth]# scan off
...
Discovery stopped
[bluetooth]# connect 72:3B:E1:81:4E:4F
Attempting to connect to 72:3B:E1:81:4E:4F
[CHG] Device 72:3B:E1:81:4E:4F Connected: yes
Connection successful
[ty_prod]

大约就用IPhone自带的劳动做测量检验了~

[ty_prod]# info
Device 28:ED:6A:A0:26:B7 (public)
    Name: tuya_mdev_test
    Alias: tuya_mdev_test
    Appearance: 0x0040
    Icon: phone
    Paired: yes
    Trusted: no
    Blocked: no
    Connected: yes
    LegacyPairing: no
    UUID: Fax                       (00001111-0000-1000-8000-00805f9b34fb)
    UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
    UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
    UUID: Current Time Service      (00001805-0000-1000-8000-00805f9b34fb)
    UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
    UUID: Battery Service           (0000180f-0000-1000-8000-00805f9b34fb)
    UUID: Vendor specific           (7905f431-b5ce-4e99-a40f-4b1e122d00d0)
    UUID: Vendor specific           (89d3502b-0f36-433a-8ef4-c502ad55f8dc)
    UUID: Vendor specific           (9fa480e0-4967-4542-9390-d343dc5d04ae)
    UUID: Vendor specific           (d0611e78-bbb4-4591-a5f8-487910ae4366)
[CHG] Device 28:ED:6A:A0:26:B7 ServicesResolved: no
[CHG] Device 28:ED:6A:A0:26:B7 Connected: no

小编们用Current 提姆e Service,列出装有attributes操作如下:

[tuya_mdev_test]# menu gatt
[tuya_mdev_test]# list-attributes 28:ED:6A:A0:26:B7
...
Primary Service
    /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041
    00001805-0000-1000-8000-00805f9b34fb
    Current Time Service
Characteristic
    /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041/char0045
    00002a0f-0000-1000-8000-00805f9b34fb
    Local Time Information
Characteristic
    /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041/char0042
    00002a2b-0000-1000-8000-00805f9b34fb
    Current Time
Descriptor
    /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041/char0042/desc0044
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
...

上面Current Time Service对应的服务如下图:

图片 7

大家选择Current Time举办操作UUID:0x2A2B

[ty_prod]# select-attribute /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041/char0042
[tuya_mdev_test:/service0041/char0042]# read
Attempting to read /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041/char0042
[CHG] Attribute /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041/char0042 Value:
  e2 07 09 05 01 24 11 03 f1 02                    .....$....      
  e2 07 09 05 01 24 11 03 f1 02                    .....$.... 
[tuya_mdev_test:/service0041/char0042]# attribute-info
Characteristic - Current Time
    UUID: 00002a2b-0000-1000-8000-00805f9b34fb
    Service: /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0041
    Value:
  e2 07 09 05 01 2e 01 03 f5 02                    ..........      
    Notifying: yes
    Flags: read
    Flags: notify

读出结果大概意思应该是:2018-9/5-1:36:17 周三

读取一下0x180A的Device Information:

[tuya_mdev_test:/service0006/char0007]# select-attribute /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0047/char004a
[tuya_mdev_test:/service0047/char004a]# attribute-info
Characteristic - Model Number String
    UUID: 00002a24-0000-1000-8000-00805f9b34fb
    Service: /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0047
    Flags: read
[tuya_mdev_test:/service0047/char004a]# read
Attempting to read /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0047/char004a
[CHG] Attribute /org/bluez/hci0/dev_47_B1_26_C1_81_18/service0047/char004a Value:
  69 50 68 6f 6e 65 36 2c 32                       iPhone6,2       
  69 50 68 6f 6e 65 36 2c 32                       iPhone6,2    

本来写、使能notify也非常粗大略,看help就能够。最终断开连接、并退出!!!

[tuya_mdev_test:/service0047/char004a]# disconnect 28:ED:6A:A0:26:B7
Attempting to disconnect from 28:ED:6A:A0:26:B7
[CHG] Device 28:ED:6A:A0:26:B7 ServicesResolved: no
Successful disconnected
[CHG] Device 28:ED:6A:A0:26:B7 Connected: no
[bluetooth]# quit

图片 8

Google
Daydream Controller
Teardown

android.bluttooth

Reading BLE Attributes

读取BLE属性

Once your Android app has connected to a GATT server and discovered
services, it can read and write attributes, where supported. For
example, this snippet iterates through the server’s services and
characteristics and displays them in the UI:
若是你的Android应用连接到GATT服务器并开采了服务,倘诺GATT服务器帮助,它就能够读取和写入属性了。例如:这一片段代码遍历了这一个服务器的劳动和特色,,并将其出示在UI中:

public class DeviceControlActivity extends Activity {
    ...
    // Demonstrates how to iterate through the supported GATT
    // Services/Characteristics.
    // In this sample, we populate the data structure that is bound to the
    // ExpandableListView on the UI.
    private void displayGattServices(List<BluetoothGattService> gattServices) {
        if (gattServices == null) return;
        String uuid = null;
        String unknownServiceString = getResources().
                getString(R.string.unknown_service);
        String unknownCharaString = getResources().
                getString(R.string.unknown_characteristic);
        ArrayList<HashMap<String, String>> gattServiceData =
                new ArrayList<HashMap<String, String>>();
        ArrayList<ArrayList<HashMap<String, String>>> gattCharacteristicData
                = new ArrayList<ArrayList<HashMap<String, String>>>();
        mGattCharacteristics =
                new ArrayList<ArrayList<BluetoothGattCharacteristic>>();

        // Loops through available GATT Services.
        for (BluetoothGattService gattService : gattServices) {
            HashMap<String, String> currentServiceData =
                    new HashMap<String, String>();
            uuid = gattService.getUuid().toString();
            currentServiceData.put(
                    LIST_NAME, SampleGattAttributes.
                            lookup(uuid, unknownServiceString));
            currentServiceData.put(LIST_UUID, uuid);
            gattServiceData.add(currentServiceData);

            ArrayList<HashMap<String, String>> gattCharacteristicGroupData =
                    new ArrayList<HashMap<String, String>>();
            List<BluetoothGattCharacteristic> gattCharacteristics =
                    gattService.getCharacteristics();
            ArrayList<BluetoothGattCharacteristic> charas =
                    new ArrayList<BluetoothGattCharacteristic>();
           // Loops through available Characteristics.
            for (BluetoothGattCharacteristic gattCharacteristic :
                    gattCharacteristics) {
                charas.add(gattCharacteristic);
                HashMap<String, String> currentCharaData =
                        new HashMap<String, String>();
                uuid = gattCharacteristic.getUuid().toString();
                currentCharaData.put(
                        LIST_NAME, SampleGattAttributes.lookup(uuid,
                                unknownCharaString));
                currentCharaData.put(LIST_UUID, uuid);
                gattCharacteristicGroupData.add(currentCharaData);
            }
            mGattCharacteristics.add(charas);
            gattCharacteristicData.add(gattCharacteristicGroupData);
         }
    ...
    }
...
}

安装Wordpress

1、 安装Wordpress在此之前的操作:更换Micro SDXC卡的Linux数据分区的空中

fdisk /dev/mmcblk0

键入“p”查看当前的分区情形;
先键入“d”再键入“2”删除当前的数目分区;
梯次键入“n”“p”“2”创立新的数码分区,作者动用的二零一六-03-12本子的Minibian是从125056发端的分区,这里要小心一下;
键入“w”写入分区表。

分区生效须求选拔“reboot”重启欧洲红树莓派。
开始后键入“resize2fs /dev/mmcblk0p2”命令才算完毕。
利用“df -h”查看一下改成后的分区意况。
使用“dpkg-reconfigure tzdata”命令改过时区。

2、 更新系统

apt-get update
apt-get upgrade
apt-get dist-upgrade
apt-get install nano

此处有人推荐校勘/etc/apt/sources.list这一个文件,改良Minibian的源,因为官方的“deb
http://mirrordirector.raspbian.org/raspbian
jessie main firmware non-free”和“deb
http://archive.raspberrypi.org/debian
jessie
main”那七个源太慢,小编试了多少个网络给的源,要么版本不对,要么已经失效了,因为急需立异的事物非常少,笔者要么接受官方的源。

依赖自身的/etc/apt/sources.list文件:

deb
http://archive.raspbian.org/raspbian
jessie main contrib non-free
deb-src
http://archive.raspbian.org/raspbian
jessie main contrib non-free
deb
http://mirrors.ustc.edu.cn/raspbian/raspbian/
jessie main non-free contrib
deb-src
http://mirrors.ustc.edu.cn/raspbian/raspbian/
jessie main non-free contrib
deb
http://mirrordirector.raspbian.org/raspbian
jessie main firmware non-free
deb
http://archive.raspberrypi.org/debian
jessie main

3、安装Apache网站服务器

apt-get install apache2 –y

完了后得以在计算机上的浏览器地址栏输入“http://localhost”或许用“hostname
-I”获得的IP地址测量检验。

4、安装PHP

apt-get install php5 libapache2-mod-php5 php5-gd –y

5、安装MySQL

apt-get install mysql-server php5-mysql –y

此处会供给输入数据库管理员的口令,不忘了!
重启Apache服务:

service apache2 restart

6、安装Wordpress
下载Wordpress。
Wordpress官网:https://wordpress.org/
查看下载链接地址:https://wordpress.org/latest.tar.gz

cd /var/www/html/
rm *
wget
https://wordpress.org/latest.tar.gz

解压缩安装

tar xzf wordpress.org/latest.tar.gz
mv wordpress/* .
rm wordpress.org/latest.tar.gz
chown -R www-data

创建Wordpress数据库

mysql -uroot –p’password’
mysql> create database wordpress;
mysql> quit
service apache2 restart

WordPress初始化http://YOUR-IP-ADDRESS,点击“Let’s
go!” 。

图片 9

WordPress开头化分界面(依版本和语种分歧或者不相同)

图片 10

填入相应的内容后,点击“提交”,在随之的页面中式茶食击“安装”

7、安装花生壳
花生壳官方网址下载页:http://hsk.oray.com/download/

wget
http://hsk.oray.com/download/download?id=25
tar zxvf phddns_raspberry.tgz
cd phddns2
./oraynewph start
oraynewph status

在运作后回到的源委中找到“SN:RAPIxxxxxxxxxxxxxxxxx”肖似的SN码,在浏览器地址栏输入:http://b.oray.com

顾客名是SN码,开首口令是“admin”

登入后就可以展开花生壳的内网地址映射的装置了。万生龙活虎你忘记了友好的花生壳登入信息,用那些命令:

oraynewph reset

图片 11

策动参谋的书本,眼观四路,样样稀松,只援用小白购买

LINKS

[1].Cannot connect to BLE device on Raspberry
Pi
[2].Invalid file descriptor gatttool of bluez
5.32
[3].Get Started with Bluetooth Low Energy on
Linux
[4].Reverse Engineering a Bluetooth Low Energy Light
Bulb
[5].Doing Bluetooth Low Energy on
Linux
[6].Tutorial: BLE Pairing the Raspberry Pi 3 Model B with
Hexiwear

图片 12

@beautifulzzzz
智能硬件、物联网,热爱技术,关注产品
博客:http://blog.beautifulzzzz.com
园友交流群:414948975

Front
Buffer
Rendering

1.对于别的的蓝牙5.0设备的扫描(包涵BLE设备卡塔尔

Finding BLE Devices

寻找BLE设备

To find BLE devices, you use the startLeScan() method. This method takes
a BluetoothAdapter.LeScanCallback as a parameter. You must implement
this callback, because that is how scan results are returned. Because
scanning is battery-intensive, you should observe the following
guidelines:
要搜求BLE设备,你能够应用startLeScan(卡塔尔方法。那么些办法蕴含叁个蓝牙( Bluetooth® 卡塔尔( Bluetooth® 卡塔尔(قطر‎艾达pter.LeScanCallback作为参数。你不能不要完结这么些回调,因为这是何许回到扫描结果的(因为扫描结果是因此那几个重返的)。因为扫描是电池密集型的,你要求根据以下的法则:

  • As soon as you find the desired device, stop scanning.
    假诺您黄金时代找到了想要的设施,就甘休扫描
  • Never scan on a loop, and set a time limit on your scan. A device
    that was previously available may have moved out of range, and
    continuing to scan drains the battery.
    切勿在循环里扫描,且要安装三个扫描时间节制。
    叁个事情发生之前能够博得的设施或许已经移出了节制,持续围观消功耗池。

The following snippet shows how to start and stop a scan:
下边的代码片段显示了什么样开端和结束扫描:

/**
 * Activity for scanning and displaying available BLE devices.
 */
public class DeviceScanActivity extends ListActivity {

    private BluetoothAdapter mBluetoothAdapter;
    private boolean mScanning;
    private Handler mHandler;

    // Stops scanning after 10 seconds.
    private static final long SCAN_PERIOD = 10000;
    ...
    private void scanLeDevice(final boolean enable) {
        if (enable) {
            // Stops scanning after a pre-defined scan period.
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mScanning = false;
                    mBluetoothAdapter.stopLeScan(mLeScanCallback);
                }
            }, SCAN_PERIOD);

            mScanning = true;
            mBluetoothAdapter.startLeScan(mLeScanCallback);
        } else {
            mScanning = false;
            mBluetoothAdapter.stopLeScan(mLeScanCallback);
        }
        ...
    }
...
}

If you want to scan for only specific types of peripherals, you can
instead call startLeScan(UUID[], BluetoothAdapter.LeScanCallback),
providing an array of UUID objects that specify the GATT services your
app supports.
假设您想扫描特定类型的外设,你能够替换调用startLeScan(UUID[],
蓝牙( Bluetooth® 卡塔尔( Bluetooth® 卡塔尔(قطر‎艾达pter.LeScanCallback卡塔尔(英语:State of Qatar),提供一个一定的您的app扶助的GATT服务UUID设备数组。

Here is an implementation of the BluetoothAdapter.LeScanCallback, which
is the interface used to deliver BLE scan results:
此地有一个Bluetooth( Bluetooth® 卡塔尔(قطر‎Adapter.LeScanCallback的兑现,它是一个接口,用来传输BLE扫描结果:

private LeDeviceListAdapter mLeDeviceListAdapter;
...
// Device scan callback.
private BluetoothAdapter.LeScanCallback mLeScanCallback =
        new BluetoothAdapter.LeScanCallback() {
    @Override
    public void onLeScan(final BluetoothDevice device, int rssi,
            byte[] scanRecord) {
        runOnUiThread(new Runnable() {
           @Override
           public void run() {
               mLeDeviceListAdapter.addDevice(device);
               mLeDeviceListAdapter.notifyDataSetChanged();
           }
       });
   }
};

Note: You can only scan for Bluetooth LE devices or scan for Classic
Bluetooth devices, as described in Bluetooth. You cannot scan for both
Bluetooth LE and classic devices at the same time.

留意:你能够扫描低功耗蓝牙( Bluetooth® 卡塔尔(英语:State of Qatar)设备或卓绝Bluetooth设备,如蓝牙5.0所述。你无法並且扫视低耗电蓝牙( Bluetooth® 卡塔尔国设备和经文蓝牙( Bluetooth® 卡塔尔(英语:State of Qatar)设备。

1、前言

上一篇讲了怎样编写翻译安装逼lueZ-5,本篇首要在于玩BlueZ,用命令行去操作BLE设备:

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

图片 13

googlevr

6.与BLE设备交换。比方相似传感器,心率监视器,强健体魄设施,等等

重大术语和概念

Here is a summary of key BLE terms and concepts:
以下是有关BLE的首要术语和概念的摘要

  • Generic Attribute Profile (GATT)—The GATT profile is a general
    specification for sending and receiving short pieces of data known
    as “attributes” over a BLE link. All current Low Energy application
    profiles are based on GATT.
    通用属性配置文件(GATT)–通用属性配置文件是三个透过BLE链接发送或选取短小片段数据或被喻为“属性”的通用标准。当前具有的低功耗应用配置文件都基于GATT。

    • The Bluetooth SIG defines many profiles for Low Energy devices.
      A profile is a specification for how a device works in a
      particular application. Note that a device can implement more
      than one profile. For example, a device could contain a heart
      rate monitor and a battery level detector.
    • 蓝牙5.0技艺缔盟为低耗电设备定义了数不尽附属文件。配置文件是三个在一定应用中器材如何是好事的规范。请留神,叁个设备能够兑现多少个布局文件。比如:叁个配备得以包涵二个心跳检查实验器和八个电量检查测量检验器
  • Attribute Protocol (ATT)—GATT is built on top of the Attribute
    Protocol (ATT). This is also referred to as GATT/ATT. ATT is
    optimized to run on BLE devices. To this end, it uses as few bytes
    as possible. Each attribute is uniquely identified by a Universally
    Unique Identifier (UUID), which is a standardized 128-bit format for
    a string ID used to uniquely identify information. The attributes
    transported by ATT are formatted as characteristics and services.
    个性公约(ATT)——GATT建设构造在性质量管理协会议(ATT)之上。那也被称之为GATT/ATT。ATT经过优化,可在BLE设备上运转。为此,它应用尽恐怕少的字节。每一种属性由通用唯朝气蓬勃标志符(UUID)唯后生可畏标志,该标记符是用于唯生机勃勃标记新闻的规范化128-bit格式的字符串ID。由ATT传输的习性被格式化为特征和劳动

  • Characteristic—A characteristic contains a single value and 0-n
    descriptors that describe the characteristic’s value. A
    characteristic can be thought of as a type, analogous to a class.
    特色——二个特征包罗贰个值和0至四个描述特征的呈报符。一个特色能够被以为是大器晚成系列型,近似于三个类。

  • Descriptor—Descriptors are defined attributes that describe a
    characteristic value. For example, a descriptor might specify a
    human-readable description, an acceptable range for a
    characteristic’s value, or a unit of measure that is specific to a
    characteristic’s value.
    陈诉符——描述符是描述特征值的概念属性。譬喻:描述符恐怕能够钦赐一人类可读的描述,特征值的可选取范围,或特征值特有的单位

  • Service—A service is a collection of characteristics. For example,
    you could have a service called “Heart Rate Monitor” that includes
    characteristics such as “heart rate measurement.” You can find a
    list of existing GATT-based profiles and services on
    bluetooth.org.
    劳动——服务是叁个特点的会师。举例:你可以选择一个誉为“心跳检验器”的服务,在那之中囊括“心跳度量”等特点。你可以在bluetooth.org上找到几个业已存在的基于GATT的配置文件和服务的列表

2、gatttool —— 老工具趟坑

刚初步跟着 Get Started with Bluetooth Low Energy on
Linux
操作gatttool,发掘坑太多(主要缘由是工具老了):

采用sudo gatttool -b 4D:69:98:0E:91:5E -I去连接
发觉会报错:Error: connect error: Connection refused (111)
说起底参谋LINK-11开掘要求加random选项([\#1](https://stackoverflow.com/questions/32947807/cannot-connect-to-ble-device-on-raspberry-pi))

➜  ~  sudo gatttool -b 4D:69:98:0E:91:5E -I
[4D:69:98:0E:91:5E][LE]> connect
Attempting to connect to 4D:69:98:0E:91:5E
Error: connect error: Connection refused (111)
[4D:69:98:0E:91:5E][LE]> exit
➜  ~  sudo gatttool  -t random  -b 4D:69:98:0E:91:5E -I
[4D:69:98:0E:91:5E][LE]> connect
Attempting to connect to 4D:69:98:0E:91:5E
Connection successful
[4D:69:98:0E:91:5E][LE]> 
(gatttool:3104): GLib-WARNING **: Invalid file descriptor.

过叁遍会10S机关断开,英特网说这么些工具老了,不提出用了([\#2](https://www.spinics.net/lists/linux-bluetooth/msg67617.html)):

There are new tools to use with GATT, bluetoothctl/bluetoothd is the preferred since with that you have GAP, etc, 
but if want to use a stand alone tool then I suggest you use btgatt-client.

图片 14

Unity
Download

Note: Not all Android-powered devices provide Bluetooth
functionality.

关门客商端app

Once your app has finished using a BLE device, it should call close() so
the system can release resources appropriately:
假如您的应用程序完毕使用BLE设备,它应当调用close(卡塔尔(قطر‎,以便系统能够准确释放能源:

public void close() {
    if (mBluetoothGatt == null) {
        return;
    }
    mBluetoothGatt.close();
    mBluetoothGatt = null;
}

后记:本文翻译自google开辟者网址。链接如下:
https://developer.android.google.cn/guide/topics/connectivity/bluetooth-le.html
招待转载,但请尊重小编专门的工作,留下本文后记
作者:Jaesoon
邮箱:jayyuz@163.com
日期:2017-09-17

NordicSemiconductor

2.为配没错蓝牙( Bluetooth® 卡塔尔国设备查询当地蓝牙5.0适配器

Setting Up BLE

设置BLE
Before your application can communicate over BLE, you need to verify
that BLE is supported on the device, and if so, ensure that it is
enabled. Note that this check is only necessary if
<uses-feature…/> is set to false.
在你使用能够由此BLE通讯在此之前,你要求证明这么些设备是或不是扶植BLE,借使可以,确认BLE是使能的。须要静心的是独有当<uses-feature…/>设置为false这些是检查供给的

If BLE is not supported, then you should gracefully disable any BLE
features. If BLE is supported, but disabled, then you can request that
the user enable Bluetooth without leaving your application. This setup
is accomplished in two steps, using the BluetoothAdapter.
如果BLE不被支持,则你必要高贵的除能全部的BLE性子。要是BLE被补助,不过被除能了,则你要求必要客商使能Bluetooth而不离开的行使。该装置使用蓝牙( Bluetooth® 卡塔尔国( Bluetooth® 卡塔尔Adapter在七个步骤中成功。

  1. Get the BluetoothAdapter
    获取BluetoothAdapter
    The BluetoothAdapter is required for any and all Bluetooth activity.
    The BluetoothAdapter represents the device’s own Bluetooth adapter
    (the Bluetooth radio). There’s one Bluetooth adapter for the entire
    system, and your application can interact with it using this object.
    The snippet below shows how to get the adapter. Note that this
    approach uses getSystemService() to return an instance of
    BluetoothManager, which is then used to get the adapter. Android 4.3
    (API Level 18) introduces BluetoothManager:
    富有的BluetoothActivity中都亟待Bluetooth适配器。蓝牙适配器表示了那些装置自带的Bluetooth适配器(Bluetooth有线电)。整个种类有一个蓝牙( Bluetooth® 卡塔尔(قطر‎适配器,你的使用能够通过这一个指标和它人机联作。下面包车型地铁代码片段展示了怎么着赢得那几个适配器。必要注意的是以此措施运用getSystemService(卡塔尔(قطر‎去赢得Bluetooth( Bluetooth® 卡塔尔Manager的二个实例,然后用于获取适配器。Android
    4.3(API Level 18)介绍了BluetoothManager。

    private BluetoothAdapter mBluetoothAdapter;
    ...
    // Initializes Bluetooth adapter.
    final BluetoothManager bluetoothManager =
            (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    mBluetoothAdapter = bluetoothManager.getAdapter();
    
  2. Enable Bluetooth
    使能蓝牙( Bluetooth® 卡塔尔国
    Next, you need to ensure that Bluetooth is enabled. Call isEnabled()
    to check whether Bluetooth is currently enabled. If this method
    returns false, then Bluetooth is disabled. The following snippet
    checks whether Bluetooth is enabled. If it isn’t, the snippet
    displays an error prompting the user to go to Settings to enable
    Bluetooth:
    接下去,你须求认同Bluetooth是使能的。调用isEnable(卡塔尔(قطر‎去检查是否蓝牙( Bluetooth® 卡塔尔国当下是或不是使能。如果这么些主意重回false,则Bluetooth是除能的。接下来的代码片段检查是还是不是蓝牙( Bluetooth® 卡塔尔国是是能的。若无使能,代码片段会显示两个顾客去设置开启蓝牙( Bluetooth® 卡塔尔国的错误提醒。

    // Ensures Bluetooth is available on the device and it is enabled. If not,
    // displays a dialog requesting user permission to enable Bluetooth.
    if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
    }
    

Note: The REQUEST_ENABLE_BT constant passed to
startActivityForResult(android.content.Intent, int) is a
locally-defined integer (which must be greater than 0) that the system
passes back to you in your onActivityResult(int, int,
android.content.Intent) implementation as the requestCode parameter.

注意:传送给startActivityForResult()的常量REQUEST_ENABLE_BT是叁个本地定义的平头(必需大于0),那个大背头系统会兑现为requestCode参数,在您的onActivityResult(卡塔尔方法中,回传给您。

Qualcomm

接口:

BluetoothAdapter.LeScanCallback
:用来提供LE扫描结果的回调接口

BluetoothProfile:Bluetooth
Profiles的公共APIs

BluetoothProfile.ServiceListener:蓝牙5.0( Bluetooth® 卡塔尔Profile
IPC client与service的连天和断开时的贰个通报接口

Roles and Responsibilities

Maximizing BLE
Throughput on iOS and
Android

关于非常多任何的精华蓝牙5.0音讯。可以看蓝牙5.0指南。有关相当多任何的低耗电蓝牙( Bluetooth® 卡塔尔(قطر‎的新闻,能够看BLE指南。

接收GATT通知

It’s common for BLE apps to ask to be notified when a particular
characteristic changes on the device. This snippet shows how to set a
notification for a characteristic, using the
setCharacteristicNotification() method:
当设备上三个一定的特征产生退换时,BLE应用去必要被通报很普及。这段代码体现了什么通过选拔setCharacteristicNotification(卡塔尔方法,去为叁个风味设置二个通报:

private BluetoothGatt mBluetoothGatt;
BluetoothGattCharacteristic characteristic;
boolean enabled;
...
mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
...
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
        UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);

Once notifications are enabled for a characteristic, an
onCharacteristicChanged() callback is triggered if the characteristic
changes on the remote device:
假诺一个特征被使能布告,即便远程设备上的那几个特点发生了改动,一个onCharacteristicChanged(卡塔尔国回调被触发。

@Override
// Characteristic notification
public void onCharacteristicChanged(BluetoothGatt gatt,
        BluetoothGattCharacteristic characteristic) {
    broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
}

Daydream
Controller手柄数据的剖释

Provides classes that manage Bluetooth functionality, such as scanning
for devices, connecting with devices, and managing data transfer between
devices. The Bluetooth API supports both “Classic Bluetooth” and
Bluetooth Low Energy.

Key Terms And Concepts

GVR SDK
and NDK Release
Notes

7.作为GATTclient或GATT服务端

Closing the Client App

Tools

4.延续在任何装置上点名的sockets

Connecting to a GATT Server

连接GATT服务器

The first step in interacting with a BLE device is connecting to it—
more specifically, connecting to the GATT server on the device. To
connect to a GATT server on a BLE device, you use the connectGatt()
method. This method takes three parameters: a Context object,
autoConnect (boolean indicating whether to automatically connect to the
BLE device as soon as it becomes available), and a reference to a
BluetoothGattCallback:
与BLE设备的互相的首先步是连采纳它-更现实的说,连接在这里个BLE设备上的GATT服务器。为了连接上在这里个BLE设备上的GATT服务器,你能够动用connectGatt(卡塔尔(英语:State of Qatar)方法。那一个方式有四个参数:叁个上下文对象,是或不是自动接二连三(贰个布尔值,注明只要这一个BLE设备是足以博得的,是或不是自动的接连上它),八个指向BluetoothGattCallback的引用。

mBluetoothGatt = device.connectGatt(this, false, mGattCallback);

This connects to the GATT server hosted by the BLE device, and returns a
BluetoothGatt instance, which you can then use to conduct GATT client
operations. The caller (the Android app) is the GATT client. The
BluetoothGattCallback is used to deliver results to the client, such as
connection status, as well as any further GATT client operations.
那会连选择由BLE设备管理的GATT服务器,并赶回三个蓝牙5.0( Bluetooth® 卡塔尔(英语:State of Qatar)Gatt实例,然后你基本上能用它来开展GATT客商端操作。调用者(Android
app)是GATT客商端。Bluetooth( Bluetooth® 卡塔尔国GattCallback用来传送结果给客商端,举个例子连接情形,以至任何更上一层楼的GATT顾客端操作。

In this example, the BLE app provides an activity
(DeviceControlActivity) to connect, display data, and display GATT
services and characteristics supported by the device. Based on user
input, this activity communicates with a Service called
BluetoothLeService, which interacts with the BLE device via the Android
BLE API:
其意气风发例子中,这几个BLE应用提供二个平移(DeviceControlActivity)用于连接装置,展现由器材提供的多寡,GATT服务和脾性。基于顾客输入,这么些活动与一个名字为BluetoothLeService的劳动通讯,该服务通过Android
BLE API与BLE设备进行相互影响:

// A service that interacts with the BLE device via the Android BLE API.
public class BluetoothLeService extends Service {
    private final static String TAG = BluetoothLeService.class.getSimpleName();

    private BluetoothManager mBluetoothManager;
    private BluetoothAdapter mBluetoothAdapter;
    private String mBluetoothDeviceAddress;
    private BluetoothGatt mBluetoothGatt;
    private int mConnectionState = STATE_DISCONNECTED;

    private static final int STATE_DISCONNECTED = 0;
    private static final int STATE_CONNECTING = 1;
    private static final int STATE_CONNECTED = 2;

    public final static String ACTION_GATT_CONNECTED =
            "com.example.bluetooth.le.ACTION_GATT_CONNECTED";
    public final static String ACTION_GATT_DISCONNECTED =
            "com.example.bluetooth.le.ACTION_GATT_DISCONNECTED";
    public final static String ACTION_GATT_SERVICES_DISCOVERED =
            "com.example.bluetooth.le.ACTION_GATT_SERVICES_DISCOVERED";
    public final static String ACTION_DATA_AVAILABLE =
            "com.example.bluetooth.le.ACTION_DATA_AVAILABLE";
    public final static String EXTRA_DATA =
            "com.example.bluetooth.le.EXTRA_DATA";

    public final static UUID UUID_HEART_RATE_MEASUREMENT =
            UUID.fromString(SampleGattAttributes.HEART_RATE_MEASUREMENT);

    // Various callback methods defined by the BLE API.
    private final BluetoothGattCallback mGattCallback =
            new BluetoothGattCallback() {
        @Override
        public void onConnectionStateChange(BluetoothGatt gatt, int status,
                int newState) {
            String intentAction;
            if (newState == BluetoothProfile.STATE_CONNECTED) {
                intentAction = ACTION_GATT_CONNECTED;
                mConnectionState = STATE_CONNECTED;
                broadcastUpdate(intentAction);
                Log.i(TAG, "Connected to GATT server.");
                Log.i(TAG, "Attempting to start service discovery:" +
                        mBluetoothGatt.discoverServices());

            } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
                intentAction = ACTION_GATT_DISCONNECTED;
                mConnectionState = STATE_DISCONNECTED;
                Log.i(TAG, "Disconnected from GATT server.");
                broadcastUpdate(intentAction);
            }
        }

        @Override
        // New services discovered
        public void onServicesDiscovered(BluetoothGatt gatt, int status) {
            if (status == BluetoothGatt.GATT_SUCCESS) {
                broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED);
            } else {
                Log.w(TAG, "onServicesDiscovered received: " + status);
            }
        }

        @Override
        // Result of a characteristic read operation
        public void onCharacteristicRead(BluetoothGatt gatt,
                BluetoothGattCharacteristic characteristic,
                int status) {
            if (status == BluetoothGatt.GATT_SUCCESS) {
                broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
            }
        }
     ...
    };
...
}

When a particular callback is triggered, it calls the appropriate
broadcastUpdate() helper method and passes it an action. Note that the
data parsing in this section is performed in accordance with the
Bluetooth Heart Rate Measurement profile specifications:
当特定的回调被触发时,它调用相应的broadcastUpdate(卡塔尔(英语:State of Qatar)扶植方法并传递三个动作。请留意,本节中的数据拆解解析是凭借Bluetooth心率衡量配置文件标准实践的:

private void broadcastUpdate(final String action) {
    final Intent intent = new Intent(action);
    sendBroadcast(intent);
}

private void broadcastUpdate(final String action,
                             final BluetoothGattCharacteristic characteristic) {
    final Intent intent = new Intent(action);

    // This is special handling for the Heart Rate Measurement profile. Data
    // parsing is carried out as per profile specifications.
    if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {
        int flag = characteristic.getProperties();
        int format = -1;
        if ((flag & 0x01) != 0) {
            format = BluetoothGattCharacteristic.FORMAT_UINT16;
            Log.d(TAG, "Heart rate format UINT16.");
        } else {
            format = BluetoothGattCharacteristic.FORMAT_UINT8;
            Log.d(TAG, "Heart rate format UINT8.");
        }
        final int heartRate = characteristic.getIntValue(format, 1);
        Log.d(TAG, String.format("Received heart rate: %d", heartRate));
        intent.putExtra(EXTRA_DATA, String.valueOf(heartRate));
    } else {
        // For all other profiles, writes the data formatted in HEX.
        final byte[] data = characteristic.getValue();
        if (data != null && data.length > 0) {
            final StringBuilder stringBuilder = new StringBuilder(data.length);
            for(byte byteChar : data)
                stringBuilder.append(String.format("%02X ", byteChar));
            intent.putExtra(EXTRA_DATA, new String(data) + "\n" +
                    stringBuilder.toString());
        }
    }
    sendBroadcast(intent);
}

Back in DeviceControlActivity, these events are handled by a
BroadcastReceiver:
归来DeviceControlActivity,这个事件都被一个布罗兹castReceiver选用场理:

// Handles various events fired by the Service.
// ACTION_GATT_CONNECTED: connected to a GATT server.
// ACTION_GATT_DISCONNECTED: disconnected from a GATT server.
// ACTION_GATT_SERVICES_DISCOVERED: discovered GATT services.
// ACTION_DATA_AVAILABLE: received data from the device. This can be a
// result of read or notification operations.
private final BroadcastReceiver mGattUpdateReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        final String action = intent.getAction();
        if (BluetoothLeService.ACTION_GATT_CONNECTED.equals(action)) {
            mConnected = true;
            updateConnectionState(R.string.connected);
            invalidateOptionsMenu();
        } else if (BluetoothLeService.ACTION_GATT_DISCONNECTED.equals(action)) {
            mConnected = false;
            updateConnectionState(R.string.disconnected);
            invalidateOptionsMenu();
            clearUI();
        } else if (BluetoothLeService.
                ACTION_GATT_SERVICES_DISCOVERED.equals(action)) {
            // Show all the supported services and characteristics on the
            // user interface.
            displayGattServices(mBluetoothLeService.getSupportedGattServices());
        } else if (BluetoothLeService.ACTION_DATA_AVAILABLE.equals(action)) {
            displayData(intent.getStringExtra(BluetoothLeService.EXTRA_DATA));
        }
    }
};

 

类:

BluetoothA2dp:那几个类提供调节BluetoothA2DP profile的公共APIs

BluetoothAdapter:代表本地设备的Bluetooth( Bluetooth® 卡塔尔(英语:State of Qatar)adapter.
BluetoothAssignedNumbers:Bluetooth分配号码

BluetoothClass:代表二个蓝牙( Bluetooth® 卡塔尔(英语:State of Qatar)类。它形容陈说了设施的日常特征(characteristics卡塔尔(قطر‎和本领(capabilities卡塔尔(قطر‎

BluetoothClass.Device:定义全部配备类的常量

BluetoothClass.Device.Major:定义整体重大器械类的常量

BluetoothClass.Service:定义全部服务类的常量

BluetoothDevice:代表叁个远程蓝牙( Bluetooth® 卡塔尔(قطر‎设备

=============================================================================================

BluetoothGatt:蓝牙GATT
Profile的公共APIs

BluetoothGattCallback:那么些抽象类用于贯彻蓝牙Gatt回调

BluetoothGattCharacteristic:代表多个蓝牙5.0( Bluetooth® 卡塔尔(قطر‎GATT Characteristic.

                                              一个GATT
Characteristic是用来组织叁个GATT
service,BluetoothGattService的中坚数据成分

BluetoothGattDescriptor:代表叁个Bluetooth( Bluetooth® 卡塔尔GATT Descriptor.

                                           GATT Descriptor包罗多少个GATT
characteristic,BluetoothGattCharacteristic的附加音讯和属性.

Classes


BluetoothA2dp This class provides the public APIs to control the Bluetooth A2DP profile. 
BluetoothAdapter Represents the local device Bluetooth adapter. 
BluetoothAssignedNumbers Bluetooth Assigned Numbers. 
BluetoothClass Represents a Bluetooth class, which describes general characteristics and capabilities of a device. 
BluetoothClass.Device Defines all device class constants. 
BluetoothClass.Device.Major Defines all major device class constants. 
BluetoothClass.Service Defines all service class constants. 
BluetoothDevice Represents a remote Bluetooth device. 
BluetoothGatt Public API for the Bluetooth GATT Profile. 
BluetoothGattCallback This abstract class is used to implement BluetoothGatt callbacks. 
BluetoothGattCharacteristic Represents a Bluetooth GATT Characteristic

A GATT characteristic is a basic data element used to construct a GATT service,BluetoothGattService

BluetoothGattDescriptor Represents a Bluetooth GATT Descriptor

GATT Descriptors contain additional information and attributes of a GATT characteristic,BluetoothGattCharacteristic

BluetoothGattServer Public API for the Bluetooth GATT Profile server role. 
BluetoothGattServerCallback This abstract class is used to implement BluetoothGattServer callbacks. 
BluetoothGattService Represents a Bluetooth GATT Service

Gatt Service contains a collection of BluetoothGattCharacteristic, as well as referenced services. 

BluetoothHeadset Public API for controlling the Bluetooth Headset Service. 
BluetoothHealth Public API for Bluetooth Health Profile. 
BluetoothHealthAppConfiguration The Bluetooth Health Application Configuration that is used in conjunction with the BluetoothHealthclass. 
BluetoothHealthCallback This abstract class is used to implement BluetoothHealth callbacks. 
BluetoothManager High level manager used to obtain an instance of an BluetoothAdapter and to conduct overall Bluetooth Management. 
BluetoothServerSocket A listening Bluetooth socket. 
BluetoothSocket A connected or connecting Bluetooth socket. 

BluetoothGattServer:蓝牙GATT Profileserver剧中人物的公共APIs.

BluetoothGattServerCallback:这一个抽象类用于贯彻BluetoothGattServer回调.

BluetoothGattService:代表一个BluetoothGATT 瑟维斯.

================================================================================

BluetoothHeadset:调整Bluetooth动圈耳机(Headset卡塔尔服务的公共API.

BluetoothHealth:蓝牙Health
Profile的公共API.

BluetoothHealthAppConfiguration:The
Bluetooth Health Application
Configuration(配置)用来与BluetoothHealth类结合.

BluetoothHealthCallback:用于落到实处BluetoothHealth回调的抽象类

BluetoothManager:用来博取BluetoothAdapter的实例的公司主,实行周密的蓝牙5.0管理

BluetoothServerSocket:一个监听Bluetooth的socket

BluetoothSocket:一个已三回九转或正在连接的蓝牙5.0socket.

剧中人物和义务

Here are the roles and responsibilities that apply when an Android
device interacts with a BLE device:
此地是Android设备与BLE设备人机联作时适用的角色和任务:

  • Central vs. peripheral. This applies to the BLE connection itself.
    The device in the central role scans, looking for advertisement, and
    the device in the peripheral role makes the advertisement.
    主旨和外设。那适用于BLE连接自身。中心设备剧中人物扫描,寻觅广告,同一时间外角色设备成立广告。

  • GATT server vs. GATT client. This determines how two devices talk to
    each other once they’ve established the connection.
    GATT服务器和GATT客商端。这决定了四个设备创建连接之后怎么通讯。

To understand the distinction, imagine that you have an Android phone
and an activity tracker that is a BLE device. The phone supports the
central role; the activity tracker supports the peripheral role (to
establish a BLE connection you need one of each—two things that only
support peripheral couldn’t talk to each other, nor could two things
that only support central).
为了掌握那个特点,假令你有所叁个Android手提式无线电话机和一个BLE活动追踪器设备。手提式有线电话机担当中心角色;活动追踪器负责外设剧中人物(为了树立BLE连接,你须要有的的这么的装置。只扶助外设剧中人物的多个设备不可能互相通讯,同样,仅帮忙核心剧中人物的多个设备也不可能互相通讯)

Once the phone and the activity tracker have established a connection,
they start transferring GATT metadata to one another. Depending on the
kind of data they transfer, one or the other might act as the server.
For example, if the activity tracker wants to report sensor data to the
phone, it might make sense for the activity tracker to act as the
server. If the activity tracker wants to receive updates from the phone,
then it might make sense for the phone to act as the server.
手提式有线电话机和移动追踪器风华正茂旦确立了三回九转,他们就从头相互传输GATT元数据。信任于他们传输的多少,当中的一个起来充作服务器。比方:若是运动追踪器希望将传感器数据报告给手提式有线电话机,那么活动追踪器大概会担负服务器。怎么样运动追踪器想要从手提式有线电话机接到更新,那么手机可能会肩负服务器。

In the example used in this document, the Android app (running on an
Android device) is the GATT client. The app gets data from the GATT
server, which is a BLE heart rate monitor that supports the Heart Rate
Profile. But you could alternatively design your Android app to play the
GATT server role. See BluetoothGattServer for more information.
其一文书档案中利用的例证中,Android
APP(运维在Android设备上)是GATT顾客端。App从三个GATT服务器中获取数据,GATT服务器是三个提供心跳配置文件的BLE心跳检查测量检验器。然而你也足以安插你的安卓App充任GATT服务器的剧中人物。有关详细音信,请查看蓝牙( Bluetooth® 卡塔尔(قطر‎( Bluetooth® 卡塔尔(قطر‎GattServer。

Dialog-semiconductor

To perform Bluetooth communication using these APIs, an application must
declare the BLUETOOTH permission. Some additional functionality, such
as requesting device discovery, also requires
the BLUETOOTH_ADMIN permission.

 

Interfaces


BluetoothAdapter.LeScanCallback Callback interface used to deliver LE scan results. 
BluetoothProfile Public APIs for the Bluetooth Profiles. 
BluetoothProfile.ServiceListener An interface for notifying BluetoothProfile IPC clients when they have been connected or disconnected to the service. 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

相关文章