BLE4.0 Client发送数据给Server
(2014-06-11 23:11:49)
标签:
it技术文档蓝牙4.0教育 |
分类: 技术文档 |
Client 发送数据给Server
使用的器件:USBdongle+MiniDK + usb转串口
功能:通过串口发送数据给USBDongle,触发USBDongle发送数据给MiniDK
使用例程:SimpleBLEPeripheral与,SimpleBLECentral
在SimpleBLEPeripheral中添加自定义特性值6
修改simpleGATTprofile.c,simpleGATTprofile.h
添加可读写的20个字节的SIMPLEPROFILE_CHAR6
在center中,一旦与simplePeripheral建立连接,就可获取到所有ServerUUID,并能得到相应
特性值的Handle,
获取特性值Handle
bStatus_t
GATT_WriteCharValue
attWriteReq_t *
uint8
)
只有当Client端(USBDongle)知道Server端(MiniDK)相应characteristic value 的Handle.
并且已经连接上才能写入成功
Parameters:
connHandle
pReq
taskId
Returns:
SUCCESS: Request was sent successfully.
INVALIDPARAMETER: Invalid connection handle or request field.
MSG_BUFFER_NOT_AVAIL: No HCI buffer is available.
bleNotConnected: Connection is down.
blePending: A response is pending with this server.
bleMemAllocError: Memory allocation error occurred.
bleTimeout: Previous transaction timed out.
typedef struct
{
} attWriteReq_t;
-----------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
在center中通过串口控制来向从机发送数据,
由于simpleperipheral中的characteristic中的内容改变了,会触发相应的CallBack函数
在simpleperipheral中
static void simpleProfileChangeCB( uint8 paramID )为charasteristic值改变的回调函数paramID为
charasteristic的uuid
通过switch(paramID)查找到对应的characteristic通过
SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR6, newChar
);
就能得到所接收到的数据。不过数据最大长度只有20个字节。
SimpleProfile_GetParameter直接将char6的内容复制给了newChar,这样就得到了center发送过来的数据了。