tag 标签: 微信蓝牙配置

相关博文
  • 热度 2
    2017-4-18 22:34
    2696 次阅读|
    1 个评论
    写在前面,最近公司在开发一款蓝牙设备,在这里我就和大家分享一下如何在微信配置蓝牙设备。 参考资料 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. 首先我们看一下流程 BLE设备要发出符合格式的广播包 微信扫到BLE设备发出的广播包,如果广播包符合微信配置的设备要求,则微信会请求建立与BLE设备的连接, 连接建立后,通过读Indicate Descriptor确认Indicate Characteristic是否有Indicate属性, 有的话会往Indicate Descriptor写值,BLE设备收到Deiscriptor写操作后, 通过Indicate Characteristic往微信发Auth请求,微信通过Write Characteristic回应Auth请求,BLE设备收到Auth回应合, 接着发Init请求,微信则回应Init请求, 至此,连接就建立了,后面就可以不分先后往对方发数据了 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***** 3.几个特征值的配置情况 ~O0@X{YRAC Write Characteristic 是微信向BLE设备发数据的通道。 Indicate Characteristic 是BLE设备向微信发数据的通道。 Read Characteristic 返回MAC地址 通信主要由Writet和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 各个标志位的属性配置要做好,这里需要多时间注意一下。 ` static gattAttribute_t simpleProfileAttrTbl = { // 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 }, }; ` 特别注意当微信向BLE设备发生init指令的时候,是对于 ‘Write Characteristic’进行操作,通过‘indicate’回复 有些协议需要 回复mac ,每个设备的mac都不同 自由通讯