用BTtool去read/wrtie 某个服务失败
时间:10-02
整理:3721RD
点击:
用BTtool去read 蓝牙温度计(ifever)0x291C(蓝牙温度计的温度))的时候提示READ_NOT_PERMITTED,在lightblue中点击Listen to otifications,则会不断地显示温度数据。请问应该如何操作,本人新手,请赐教。
chao,
这是notification.
listen for notifications就是打开了蓝牙温度计的Notification,自动发温度值过来。
这个特征值应该没有read属性,所以你没法用BTool去读这个值。
Hi Yan:
用BTool 只是去测试,我最终的目的是要用CC2541去拿到这个数据,如果是用2541的话应该如何去读取,谢谢。
使用cc2541的主机例程,也就是SimpleBLECentral来读取就可以。具体的,修改如下代码,加入notify处理分支
static void simpleBLECentralProcessGATTMsg( gattMsgEvent_t *pMsg ) { if ( simpleBLEState != BLE_STATE_CONNECTED ) { // In case a GATT message came after a connection has dropped, // ignore the message return; } if ( ( pMsg->method == ATT_READ_RSP ) || ( ( pMsg->method == ATT_ERROR_RSP ) && ( pMsg->msg.errorRsp.reqOpcode == ATT_READ_REQ ) ) ) { if ( pMsg->method == ATT_ERROR_RSP ) { uint8 status = pMsg->msg.errorRsp.errCode; //LCD_WRITE_STRING_VALUE( "Read Error", status, 10, HAL_LCD_LINE_1 ); } else { // After a successful read, display the read value uint8 valueRead = pMsg->msg.readRsp.value[0]; //LCD_WRITE_STRING_VALUE( "Read rsp:", valueRead, 10, HAL_LCD_LINE_1 ); } simpleBLEProcedureInProgress = FALSE; } else if ( ( pMsg->method == ATT_WRITE_RSP ) || ( ( pMsg->method == ATT_ERROR_RSP ) && ( pMsg->msg.errorRsp.reqOpcode == ATT_WRITE_REQ ) ) ) { if ( pMsg->method == ATT_ERROR_RSP == ATT_ERROR_RSP ) { uint8 status = pMsg->msg.errorRsp.errCode; //LCD_WRITE_STRING_VALUE( "Write Error", status, 10, HAL_LCD_LINE_1 ); } else { // After a succesful write, display the value that was written and increment value //LCD_WRITE_STRING_VALUE( "Write sent:", simpleBLECharVal++, 10, HAL_LCD_LINE_1 ); } simpleBLEProcedureInProgress = FALSE; } else if ( pMsg->method == ATT_HANDLE_VALUE_NOTI || pMsg->method == ATT_HANDLE_VALUE_IND ) { if(pMsg->msg.handleValueNoti.handle == 0x001B) { //在此处处理notify,注意对应的handle替换成正确的值 } else if(pMsg->msg.handleValueInd.handle == 0x001F) { //在此处处理indicate,注意对应的handle替换成正确的值 ATT_HandleValueCfm(simpleBLEConnHandle); } } else if ( simpleBLEDiscState != BLE_DISC_STATE_IDLE ) { simpleBLEGATTDiscoveryEvent( pMsg ); } }
pMsg->msg.handleValueNoti.handle需要自己想办法获取到。另外在这之前,要使能notification
attWriteReq_t writeReq; writeReq.handle = 0x001C; writeReq.len = ATT_BT_UUID_SIZE; writeReq.value[0] = LO_UINT16(GATT_CLIENT_CFG_NOTIFY);//这里是 0x01 writeReq.value[1] = HI_UINT16(GATT_CLIENT_CFG_NOTIFY);//这里是 0x00 writeReq.sig = 0; writeReq.cmd = 0; //GATT_WriteCharValue( simpleBLEConnHandle, &writeReq, simpleBLETaskId ); GATT_WriteCharDesc( simpleBLEConnHandle, &writeReq, simpleBLETaskId );
同样的,你需要想办法获取到writeReq.handle。希望能帮到你。