原创 CC2540 微信蓝牙配置

2017-4-18 22:34 2696 14 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 2023-03-07 15:14
嵌入式面试之系统
最近一段时间在开始找工作,自己以前也面试过其他人,想从实际工作的角度,来提出一些有意义的问题并做一些浅薄的解答,期望帮助到找工作或者刚开始当面试官的朋友。我把面试要准备的地方列成一下几个注意点,大家...
Bruce-Woo 2023-02-25 21:59
芯片选型的思路
近来在面试,不知为何很多人问起我刚毕业的时候的项目中的一个芯片选型的事情,回过头来整理下,希望可以帮助到后面的朋友1. 开发难度 开发难度,要考虑本身的程序员的开发能力,擅长的领域和工具等。综合下你...
Bruce-Woo 2021-03-17 14:19
记一次调用动态库报错的处理过程( undefined symbol)
最近工作在调用其他同事的一个动态库的时候发现有 未识别的错误 特此记录一下         首先我们用ldd查一下动态库连接是否有问题   ...
Bruce-Woo 2021-03-11 15:03
ubuntu16.04下安装svn
SVN和GIT相信是大家使用最多的代码协同工具,不过可能在win下用的比较多,那今天在ubuntu上运行一遍,操作都差不多。某种程度上讲,我也更喜欢指令操作。1. 远程登录虚拟机,也可以页面操作,看个...
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....
我要评论
1
14
关闭 站长推荐上一条 /2 下一条