Android_低功耗

概念

=============================ATT=================================

ATT (attribute protocol) 属性协议,

1.属性(attribute)是不连续的一个值,与之关联的有三个元素(值、类型、一系列的权限)。

1).Handler句柄 The address of the attribute in the table //用来访问Attribute Value 

就是服务数据在数据中心的地址

2).Type类型 Tells what the data represents //由UUID(Universally Unique IDentifier)来定义

3).一系列的权限A set of permissions //控制是否该Attribute可读、可写、属性值是否通过加密链路发送


2.允许为属性分配不同的权限,包括:可读、可写、是否需要添加额外的安全访问方式

3. 服务器端提供数据,客户端使用数据,服务器端通过属性暴露数据


ATT用于发现、读、写对端设备的协议(针对BLE设备)

ATT就是已属性的方式了无线协议,包含读、写、搜索等属性(Attribute),属性包括三个元素:地址(Handle)、类型(Type)、权限(Perssions)


========================GATT============================

GATT (Generic Attribute Profile)通用属性配置的定义

GATT包含若干个Profile,一个Profile包含若干个Services,一个Service包含若干个Characteristics,一个Characteristic包含Properties字段和若干个Descriptor(可选)

Profile

Service

Characteristic

Descriptor



当两个BLE设备处于连接状态时,GATT客户端设备可以和GATT服务器端设备进行通信

包括:

1)搜索设备

Discover Characteristic by UUID –search the GATT server for all attributes with type that matches the specified UUID 通过UUID搜索特征

2)读特征值

Read Characteristic Value –read the value of the characteristic at the specified handle 读取特征值

3)写特征值

Write Characteristic Value –write a new value to the characteristic at the specified handle 写特征值


GATT服务器端可以没有提示的向客户端发送消息。如果需要没有提示的向客户端发送消息,以下面两种方式进行

1)Notification 

The value a characteristic is sent from the server to the client without receiving a read request, and does not need to be acknowledged

通知-----这种方式可以直接向客户端发送特征值,不需要客户端请求并且不需要客户端确认。

2)Indication 

The value a characteristic is sent from the server to the client without receiving a read request, but must be acknowledged before any further data can be sent

指示-----这种方式可以直接向客户端发送特征值,不需要客户端请求但是需要客户端确认才能进行下一次发送。


更加详细的介绍参考链接:

http://www.pinnace.cn/bluetooth/tech/1938.shtml

http://www.cnblogs.com/hzl6255/p/4133596.html

http://www.cnblogs.com/hzl6255/p/4141505.html

http://www.cnblogs.com/savagemorgan/p/3722657.html

http://my.oschina.net/tingzi/blog/215008

http://blog.csdn.net/woshasanguo/article/details/41082395 代码解释详细,并且与之前的socket方式做了比较说明

http://www.jb51.net/article/53485.htm

更多代码案例:

http://wenku.baidu.com/view/77605a777c1cfad6185fa70f.html (代码非常详细清晰)

详细API介绍

http://www.2cto.com/kf/201411/349575.html


总结

http://www.eoeandroid.com/thread-573261-1-6.html?_dsign=7fe4649e


问题解决:

1.GATT Notification not received

To receive notification in Android you need to set characteristic notification to true

gatt.setCharacteristicNotification(characteristic, true);

You also need to set the client characteristic configuration descriptor 0x2902

// 0x2902 org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml
UUID uuid = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(uuid);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
gatt.writeDescriptor(descriptor);
http://stackoverflow.com/questions/17910322/android-ble-api-gatt-notification-not-received
https://github.com/devunwired/accessory-samples/blob/master/BluetoothGatt/src/com/example/bluetoothgatt/MainActivity.java
http://blog.csdn.net/woshasanguo/article/details/41082395

        

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值