原创 CC2540 微信蓝牙配置

2017-4-18 22:34 1445 4 2 分类: MCU/ 嵌入式 文集: 蓝牙开发
写在前面,最近公司在开发一款蓝牙设备,在这里我就和大家分享一下如何在微信配置蓝牙设备。
参考资料

http://blog.csdn.net/skdev/article/details/50974343

http://blog.csdn.net/sadshen/article/details/47761801

http://blog.csdn.net/feilusia/article/details/48917625



测试APP 微信蓝牙协议调试工具AirSyncDebugger 这里可以下载 https://blog.csdn.net/skdev/article/details/50974343
1. 首先我们看一下流程

S9){FC7LLRC0M@AP{BOP7E3



  1. BLE设备要发出符合格式的广播包

  2. 微信扫到BLE设备发出的广播包,如果广播包符合微信配置的设备要求,则微信会请求建立与BLE设备的连接,

  3. 连接建立后,通过读Indicate Descriptor确认Indicate Characteristic是否有Indicate属性,

  4. 有的话会往Indicate Descriptor写值,BLE设备收到Deiscriptor写操作后,

  5. 通过Indicate Characteristic往微信发Auth请求,微信通过Write Characteristic回应Auth请求,BLE设备收到Auth回应合,

  6. 接着发Init请求,微信则回应Init请求,

  7. 至此,连接就建立了,后面就可以不分先后往对方发数据了


2.AirSyncDebugger的日志,完整流程

*****************BLE: TwoWinter******************


***** onTestBroadcastRecord *****

result = true, Has 0xfee7 or standard service in broadcast record


广播包:02 01 06 03 02 E7 FE 09 FF 0D 00 90 59 AF 0E 62 88(这几个是mac) 0A 09 54 77 6F 57 69 6E 74 65 72 05 12 50 00 20 03 02 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00


***** onTestManufatureData *****

resut= true, 广播包中 manufacture specific data 字段中MAC地址校验成功.



如果这里显示警告,就是的mac地址不对,这里说一下mac的数据是可以自己写的,但是前提要前后保持一致



***** onDiscoverService *****

result = true, DiscoverService success

Discovered Services

ServiceUUID: 00001800-0000-1000-8000-00805f9b34fb

ServiceUUID: 00001801-0000-1000-8000-00805f9b34fb

ServiceUUID: 0000180a-0000-1000-8000-00805f9b34fb

ServiceUUID: 0000fee7-0000-1000-8000-00805f9b34fb


***** onTestHasWeChatService *****

result = true, has WeChatService or standard service


***** onTestHasIndicateCharacteristic *****

result = true, has WeChat Indicate Characteristic


***** onTestHasWriteCharacteristic *****

result = true, has Wechat Write Characteristic


***** onTestHasReadCharacteristic *****

result = true, Has WeChat read characteristic


***** onTestWriteCharacteristicPermisson *****

result = true, has Write permission


***** onTestIndicateCharacteristicPermisson *****

result = true, has Indication permission


***** onTestReadCharacteristicPermisson *****

result = true, Read Characteristic is read able


***** onTestStartIndicating *****

result = true, can Start Indicate


***** onConnected *****

result = true, connected


------onDataReceived------

data length = 20

data dump = FE 01 00 24 27 11 00 01 0A 00 18 84 80 04 20 01 28 02 3A 06

data receive seq = 0


------onDataReceived------

data length = 16

data dump = 90 59 AF 0E 62 88(MAC) 62 08 6D 79 64 65 76 69 63 65

data receive seq = 1


***** onTestRecvAuthReqtWhenStartedIndicating *****

result = true, received auth request pack


***** onTestIsValidAuthReqPack *****

result = true, is a valid auth request pack

AuthRequestPack: FE 01 00 24 27 11 00 01 0A 00 18 84 80 04 20 01 28 02 3A 06 90 59 AF 0E 62 88 62 08 6D 79 64 65 76 69 63 65

has BaseRequest

no Md5DeviceTypeAndDeviceId field!

has MacAddress field, Mac Address = 90 59 AF 0E 62 88

MacAddress BitLength = 48bit

Mac Address from broadcast record = 90:59:AF:0E:62:88

Mac address checkout success

has ProtoVersion field, ProtoVersion = 65540

has AuthProto field, AuthProto = 1

has AuthMethod field, AuthMethod = EAM_macNoEncrypt

no AesSign field!

has DeviceName field, DeviceName = mydevice


**** send auth response ****

data len = 14

data dump = FE 01 00 0E 4E 21 00 01 0A 02 08 00 12 00


**------onDataReceived------

data length = 16

data dump = FE 01 00 10 27 13 00 02 0A 00 1A 04 11 22 33 44

data receive seq = 2


***** onTestRecvInitReqPack *****

result = true, received init request pack


***** onTestIsValidInitReqPack *****

result = true, valid init request pack: has BaseRequest

has Challenge field, Challenge = 11 22 33 44


*****Disconnected Device*****


418971839110117919


3.几个特征值的配置情况

![>L@KVR4${L1(8>~O0@X{YRAC


Write Characteristic 是微信向BLE设备发数据的通道。

Indicate Characteristic 是BLE设备向微信发数据的通道。

Read Characteristic 返回MAC地址

通信主要由Writet和Indicate 两个特征来完成。

___________________

有几点强调一下



  1. BlE indicate > http://blog.csdn.net/feilusia/article/details/48917625 我当初看这个文档收获很多,感谢原作者,后来者也仔细看看该文件. 当检测到微信发过来的初始化指令的时候,做一个标志位,在定时器里面处理发送,而且要发两次,中间要加点时间间隔,不加的话可能只能发前面一帧数据,不可过大不然会被看成不同的两帧,因为蓝牙协议栈最多支持20个字节的传输,关于AUTH的指令的协议的字节数大于20,所以要发两帧



    ------onDataReceived------

    data length = 20

    data dump = FE 01 00 24 27 11 00 01 0A 00 18 84 80 04 20 01 28 02 3A 06

    data receive seq = 0





------onDataReceived------

data length = 16

data dump = 90 59 AF 0E 62 88(MAC) 62 08 6D 79 64 65 76 69 63 65

data receive seq = 1




  1. 各个标志位的属性配置要做好,这里需要多时间注意一下。



    `

    static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] =

    {

    // Simple Profile Service

    {

    { ATT_BT_UUID_SIZE, primaryServiceUUID }, /* type /

    GATT_PERMIT_READ, /
    permissions /

    0, /
    handle /

    (uint8
    )&simpleProfileService /* pValue */

    },



    // Characteristic 1 Declaration

    {

    { ATT_BT_UUID_SIZE, characterUUID },

    GATT_PERMIT_READ,

    0,

    &simpleProfileChar1Props

    },


    // Characteristic Value 1

    {

    { ATT_BT_UUID_SIZE, simpleProfilechar1UUID },

    GATT_PERMIT_READ | GATT_PERMIT_WRITE,

    0,

    &simpleProfileChar1

    },


    // Characteristic 1 User Description

    {

    { ATT_BT_UUID_SIZE, charUserDescUUID },

    GATT_PERMIT_READ,

    0,

    simpleProfileChar1UserDesp

    },


    // Characteristic 2 Declaration

    {

    { ATT_BT_UUID_SIZE, characterUUID },

    GATT_PERMIT_READ,

    0,

    &simpleProfileChar2Props

    },


    // Characteristic Value 2

    {

    { ATT_BT_UUID_SIZE, simpleProfilechar2UUID },

    GATT_PERMIT_READ,

    0,

    simpleProfileChar2

    },


    // Characteristic 2 User Description

    {

    { ATT_BT_UUID_SIZE, charUserDescUUID },

    GATT_PERMIT_READ,

    0,

    simpleProfileChar2UserDesp

    },


    // Characteristic 3 Declaration

    {

    { ATT_BT_UUID_SIZE, characterUUID },

    GATT_PERMIT_READ,

    0,

    &simpleProfileChar3Props

    },


    // Characteristic Value 3

    {

    { ATT_BT_UUID_SIZE, simpleProfilechar3UUID },

    GATT_PERMIT_WRITE,

    0,

    simpleProfileChar3

    },


    // Characteristic 3 User Description

    {

    { ATT_BT_UUID_SIZE, charUserDescUUID },

    GATT_PERMIT_READ,

    0,

    simpleProfileChar3UserDesp

    },


    // Characteristic 4 Declaration

    {

    { ATT_BT_UUID_SIZE, characterUUID },

    GATT_PERMIT_READ,

    0,

    &simpleProfileChar4Props

    },


    // Characteristic Value 4

    {

    { ATT_BT_UUID_SIZE, simpleProfilechar4UUID },

    0,

    0,

    simpleProfileChar4

    },


    // Characteristic 4 configuration

    {

    { ATT_BT_UUID_SIZE, clientCharCfgUUID },

    GATT_PERMIT_READ | GATT_PERMIT_WRITE,

    0,

    (uint8 *)simpleProfileChar4Config

    },


    // Characteristic 4 User Description

    {

    { ATT_BT_UUID_SIZE, charUserDescUUID },

    GATT_PERMIT_READ | GATT_PERMIT_WRITE,

    0,

    simpleProfileChar4UserDesp

    },


    // Characteristic 5 Declaration

    {

    { ATT_BT_UUID_SIZE, characterUUID },

    GATT_PERMIT_READ,

    0,

    &simpleProfileChar5Props

    },


    // Characteristic Value 5

    {

    { ATT_BT_UUID_SIZE, simpleProfilechar5UUID },

    GATT_PERMIT_READ,

    0,

    simpleProfileChar5

    },


    // Characteristic 5 User Description

    {

    { ATT_BT_UUID_SIZE, charUserDescUUID },

    GATT_PERMIT_READ,

    0,

    simpleProfileChar5UserDesp

    },


    // Characteristic 6 Declaration

    {

    { ATT_BT_UUID_SIZE, characterUUID },

    GATT_PERMIT_READ,

    0,

    &simpleProfileChar6Props

    },


    // Characteristic Value 6

    {

    { ATT_BT_UUID_SIZE, simpleProfilechar6UUID },

    GATT_PERMIT_READ|GATT_PERMIT_WRITE,

    0,

    simpleProfileChar6

    },


    // Characteristic 6 configuration

    {

    { ATT_BT_UUID_SIZE, clientCharCfgUUID },

    GATT_PERMIT_READ | GATT_PERMIT_WRITE,

    0,

    (uint8 *)simpleProfileChar6Config

    },


    // Characteristic 6 User Description

    {

    { ATT_BT_UUID_SIZE, charUserDescUUID },

    GATT_PERMIT_READ,

    0,

    simpleProfileChar6UserDesp

    },

    };

    `

  2. 特别注意当微信向BLE设备发生init指令的时候,是对于 ‘Write Characteristic’进行操作,通过‘indicate’回复

  3. 有些协议需要回复mac,每个设备的mac都不同

  4. 自由通讯



作者: Bruce-Woo, 来源:面包板社区

链接: https://mbb.eet-china.com/blog/uid-me-1850657.html

版权声明:本文为博主原创,未经本人允许,禁止转载!

文章评论1条评论)

登录后参与讨论

moniqiuwen 2021-1-25 14:09

感谢总结

Rain社区管理 2017-4-19 02:23

欢迎归来重新开始博客之旅 :grinning:

相关推荐阅读
Bruce-Woo 2021-02-09 01:08
2020,我想和你谈谈
这篇文字无关技术,也没有代码。 这是最好的时代,也是最坏的时代!写在回家前夜。 不到10个小时后就要开始坐车回家,手头的工作也没有做完。正经的事儿没完成,乱七八糟的事情倒是想了不少,说话是一种表达方...
Bruce-Woo 2021-01-19 12:34
cmake的安装过程
今天在编译opencv的时候突然发现cmake失败,显示版本不同遂决定修复之方法如下下载更高版本cmake,可在cmake官网下载 解压 tar -zxvf cmake-3.19....
Bruce-Woo 2021-01-18 23:02
谈谈STM32的bootload方案
这个话题相信很多嵌入式的同行都困惑过很长一段时间,其实说起来也不算复杂,借此机会,也把以前做过的bootloader方案说一下先说怎么实现的,要知道bootloader本身其实也是一个应用程序,不过这...
Bruce-Woo 2021-01-18 20:20
谈谈低功耗
     从事嵌入式相关的工作也好几年,陆陆续续做过几个项目的。在这里借此机会,也回顾一下这些年的低功耗探索之路。感谢以下文章给我的提醒    [ht...
Bruce-Woo 2021-01-18 10:44
蓝牙应用的基本思路
该文件更新日志2021.01.18 初版,涉及文档部分区别等方面2021.01.21 增加部分解释大家好,我是BruceWoo 很久没有写博客了,刚好最近把玩了一个HF270的开发板。准备趁着这热情把...
广告
我要评论
1
4
1
2
3
4
5
6
7
8
9
0
广告
关闭 热点推荐上一条 /2 下一条