在做 CC2541 上微信的時候,最好配合 AirSyncDebugger 軟件使用,這個軟件只有安卓版本,下載地址:http://iot.weixin.qq.com/download.html;所有的相關資料都可以在這裏下載,裏面有個 Demo 程序,是基於 Nordic nRF51822 平臺的。
在過 AirSyncDebugger 驗證的時候,第一二步前面有說,這裏說第三步。第三步主要是驗證服務和特徵值。wechatIOTAttrTbl[] 程序如下所示:
static gattAttribute_t wechatIOTAttrTbl[] ={
// wechatIOT Service
{
{ ATT_BT_UUID_SIZE, primaryServiceUUID } , /* type */
GATT_PERMIT_READ , /* permissions */
0 , /* handle */
(uint8 *)&wechatService /* pValue */
} ,
//////////////////////////////////////////////
// Indicate
//////////////////////////////////////////////
// 1. Characteristic Declaration
{
{ ATT_BT_UUID_SIZE, characterUUID },
GATT_PERMIT_READ,
0,
&wechatIndicateProps
},
// 2. Characteristic Value
{
{ ATT_BT_UUID_SIZE, wechatIndicateUUID },
0, //return READ_NOT_PERMITTED
0,
&wechatIndicate
},
// 3.Characteristic Configuration
{
{ ATT_BT_UUID_SIZE, clientCharCfgUUID },
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
0,
(uint8 *)&wechatIndicateConfig
},
//////////////////////////////////////////////
// Write
//////////////////////////////////////////////
// 4.Characteristic Declaration
{
{ ATT_BT_UUID_SIZE, characterUUID },
GATT_PERMIT_READ,
0,
&wechatWriteProps
},
// 5.Characteristic Value
{
{ ATT_BT_UUID_SIZE, wechatWriteUUID },
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
0,
&wechatWrite[0]
},
//////////////////////////////////////////////
// Read
//////////////////////////////////////////////
// 6.Characteristic Declaration
{
{ ATT_BT_UUID_SIZE, characterUUID },
GATT_PERMIT_READ,
0,
&wecharReadProps
},
// 7.Characteristic Value
{
{ ATT_BT_UUID_SIZE, wecharReadUUID },
GATT_PERMIT_READ ,
0 ,
&ownAddress[0]
} ,
} ;
這一塊如果不熟悉的話理解起來還是比較麻煩的,我也是先做了一年多的藍牙,把 CCC2541 的所有重要的地方都熟悉過了,在看上微信的程序才很容易,但是後面的封包、認證的程序就理解起來很困難,因爲根本沒有接觸過。