iOS蓝牙BLE writevaluwrite返回值问题,怎么解决

匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。咨询Bluetopia连接ble设备自动断链的问题,谢谢 - 蓝牙Bluetooth 技术 - 德州仪器在线技术支持社区
咨询Bluetopia连接ble设备自动断链的问题,谢谢
发表于3年前
<input type="hidden" id="hGroupID" value="42"
我用&connectle ...&连接第三方ble设备,然后用&&span>DiscoverHRS&找到了ble设备上的心率服务,之后用&&span>ConfigureRemoteHRS 1&配置通知服务,现在可以正常收到ble设备上的心率数据,但是过两三分钟后,连接就自动断开了,需要重新执行上述流程,如此反复。&/span>&/span>&/p>
&p>请教各位,问题出在哪里呢?是否应该修改某些参数?谢谢。&/p>&div style=&clear:&>&/div>" />
咨询Bluetopia连接ble设备自动断链的问题,谢谢
此问题已被解答
All Replies
我用&connectle ...&连接第三方ble设备,然后用&DiscoverHRS&找到了ble设备上的心率服务,之后用&ConfigureRemoteHRS 1&配置通知服务,现在可以正常收到ble设备上的心率数据,但是过两三分钟后,连接就自动断开了,需要重新执行上述流程,如此反复。
请教各位,问题出在哪里呢?是否应该修改某些参数?谢谢。
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
进士2060分
看看是不是timout断开的
蓝牙4.0BLE外设开发,APP开发(IOS)
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
不是的,断链时提示的错误码是13,看了说明,应该是ble设备因为资源限制而断开了连接。
但是我用手机连接该ble设备很正常,用的是下载的运动软件,能够一直采集心率。
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
仔细观察了一下,大概一分钟多点就自动断链了,每次都如此,请问有啥办法解决吗?
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
探花15181分
可能出现在连接的配置上 建议可以抓包看看连接的参数是否有不同
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
我使用的是TI的MSP-EXP430F5438A开发板,代码是TI网站下载的CC256x_MSP430_Bluetopia_Basic_SPPLEDemo_APP。
连接的心率腕表是迈欧的alpha,支持ble,不是spple。使用iphone5、三星note2等手机可以正常读取心率数据。
但使用SPPLEDemo时,连接建立后,约一分钟多点即断开连接,断开之前,心率上报正常,这个腕表每秒钟上报一次心率。无论是否配置了心率上报,断开连接的时间都一样。
因使用的是原始例子,未修改任何le连接参数。
请各位专家多多指点哦,多谢多谢。
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
查看断开连接的Reason,有时是0x08,(好像是认证不足),多数是0x13(对方关闭连接)和0x3E。
其中0x08很少出现;
前述每隔一分多钟就断开连接时,reason通常是0x13;
有时候连接刚刚建立,我紧跟着发送discover命令,连接立即就断开了,此时reason是0x3E,之后这种情况会持续二三十次,就是不断重复&连接建立-&discover-&连接断开&这个过程,很是奇怪。
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
DiscoverHRS和ConfigureRemoteHRS命令是从HRSDemo里面移植过来的。
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
探花15181分
有几个问题
1. SPPLEDemo 没有DiscoverHRS, ConfigureRemoteHRS命令参数, 请问您是如何连接的
2. 心率腕表应该使用的是HRP的Peripheral协议需要和HRP的Central设备连接
3. SPPLEDemo一般是跑在Peripheral设备上,根据你的描述,cc256x是连接腕表,也就是说cc256x需要做central设备
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
DiscoverHRS和ConfigureRemoteHRS命令是从HRSDemo里面移植过来的。
我需要同时与ble设备和经典蓝牙(spp)连接,因此以SPPLEDemo为主,加进了HRSDemo里面的几个函数。
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
探花15181分
请问您如果用HRPDemo和设备连是否会出现断链的情况?
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
HRPDemo也试过的,也会断链,现象一致。
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
探花15181分
我试过用两个 都跑HRPDemo 相互连接并不会断开,所以有可能跟连接参数有关,如果有抓包工具可以抓包看一下设备和iphone连接的时候的数据包,对比尝试修改如下代码参数
&/* Initialize the connection parameters.&&&&&&&&&&&&&&&&&&& */&&&&&&&&&&& ConnectionParameters.Connection_Interval_Min&&& = 50;&&&&&&&&&&& ConnectionParameters.Connection_Interval_Max&&& = 200;&&&&&&&&&&& ConnectionParameters.Minimum_Connection_Length& = 0;&&&&&&&&&&& ConnectionParameters.Maximum_Connection_Length& = 10000;&&&&&&&&&&& ConnectionParameters.Slave_Latency&&&&&&&&&&&&& = 0;&&&&&&&&&&& ConnectionParameters.Supervision_Timeout&&&&&&& = 20000;
&&&&&&&&&&& /* Everything appears correct, go ahead and attempt to make */&&&&&&&&&&& /* the connection.&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& */&&&&&&&&&&& Result = GAP_LE_Create_Connection(BluetoothStackID, 100, 100, Result?fpNoFilter:fpWhiteList, Address_Type, Result?&BD_ADDR:NULL, latPublic, &ConnectionParameters, GAP_LE_Event_Callback, 0);
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
尝试了很多参数,连接断开的现象还是依旧。
后来想了一个办法:用开发板来模拟心率腕表,让iphone来连接该腕表,这样在开发板上能否看到iphone发过来的参数呢?
如果能,应该跟踪哪个事件中的哪个参数?谢谢。
补充:心率腕表的地址类型是Random类型,不是连接函数使用的Public类型,这个地方已修改为Random,不知是否有关系。
另:TI网站最近下载的SPPLEDemoApp中使用的ble版本怎么看?是1.2.1还是1.3呢?
You have posted to a forum that requires a moderator to approve posts before they are publicly available.iOS 蓝牙使用小结 bluetooth
首先推荐去看官方文档哦
最近做一项目,本来蓝牙通讯这块不是我负责的,但是负责这块的同事要走,只好咬咬牙学习了。呜呜呜。。。。。
现将创建蓝牙工程的要点总结一下,由于工程主要涉及中心模式,所以只总结中心模式的用法
1,引入CoreBluetooth.framework
2,实现蓝牙协议,如:
.h文件如下
@protocol CBCentralManagerD
@protocol CBPeripheralD
@interface ViewController :
UIViewController
.m文件如下
#import "CoreBluetooth/CoreBluetooth.h"
另外还有代理部分请自行添加
3,下面是使蓝牙动起来的过程
3.1创建CBCentralManager实例
self.cbCentralMgr = [[CBCentralManager
alloc] initWithDelegate:self
queue:nil];
设置代理,比如:
self.cbCentralMgr.delegate =
创建数组管理外设
self.peripheralArray = [NSMutableArray
3.2扫描周围的蓝牙
实际上周围的蓝牙如果可被发现,则会一直往外发送广告消息,中心设备就是通过接收这些消息来发现周围的蓝牙的
NSDictionary * dic = [NSDictionary
dictionaryWithObjectsAndKeys:[NSNumber
numberWithBool:false],CBCentralManagerScanOptionAllowDuplicatesKey,
[self.cbCentralMgr
scanForPeripheralsWithServices:nil
options:dic];
3.3发现一个蓝牙设备
也就是收到了一个周围的蓝牙发来的广告信息,这是CBCentralManager会通知代理来处理
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral
*)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
如果周围的蓝牙有多个,则这个方法会被调用多次,你可以通过tableView或其他的控件把这些周围的蓝牙的信息打印出来
3.4连接一个蓝牙
[self.cbCentralMgr
connectPeripheral:peripheral
options:[NSDictionary
dictionaryWithObject:[NSNumber
numberWithBool:YES]
forKey:CBConnectPeripheralOptionNotifyOnDisconnectionKey]];
一个中心设备可以同时连接多个周围的蓝牙设备
当连接上某个蓝牙之后,CBCentralManager会通知代理处理
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral
*)peripheral
因为在后面我们要从外设蓝牙那边再获取一些信息,并与之通讯,这些过程会有一些事件可能要处理,所以要给这个外设设置代理,比如:
peripheral.delegate =
3.5查询蓝牙服务
[peripheral discoverServices:nil];
返回的蓝牙服务通知通过代理实现
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError
for (CBService* service
in peripheral.services){
3.6查询服务所带的特征&#20540;
[peripheral discoverCharacteristics:nil
forService:service];
返回的蓝牙特征&#20540;通知通过代理实现
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService
*)service error:(NSError *)error
for (CBCharacteristic * characteristic
in service.characteristics) {
3.7给蓝牙发数据
[peripheral writeValue:data
forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
这时还会触发一个代理事件
- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic
*)characteristic error:(NSError *)error
3.8处理蓝牙发过来的数据
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic
*)characteristic error:(NSError *)error
3.9 retrievePeripheralsWithIdentifiers
-(IBAction) Retrieve:(id)Sender
[self.tvLog
setText:@""];
NSMutableArray * Identifiers = [NSMutableArray
for (CBPeripheral * peripheral
in self.peripheralArray) {
[Identifiers
addObject:peripheral.identifier];
addLog:@"[self.cbCentralMgr retrievePeripheralsWithIdentifiers:self.PeripheralIdentifiers]"];
self.retrievePeripherals = [self.cbCentralMgr
retrievePeripheralsWithIdentifiers:Identifiers];
for (CBPeripheral* peripheral
in self.retrievePeripherals) {
addLog:[NSString
stringWithFormat:
@"%@ name:%@",peripheral,peripheral.name]];
[self.tableViewPeripheral
reloadData];
3.10 retrieveConnectedPeripheralsWithServices
-(IBAction) Retrieve:(id)Sender
[self.tvLog
setText:@""];
NSMutableArray * services = [NSMutableArray
for (CBPeripheral * peripheral
in self.peripheralArray) {
if (peripheral.isConnected) {
for (CBService *service
in peripheral.services) {
addObject:service.UUID];
addLog:@"[self.cbCentralMgr retrieveConnectedPeripheralsWithServices:peripheral.services]"];
self.retrievePeripherals = [self.cbCentralMgr
retrieveConnectedPeripheralsWithServices:services];
for (CBPeripheral* peripheral
in self.retrievePeripherals) {
addLog:[NSString
stringWithFormat:
@"%@ name:%@",peripheral,peripheral.name]];
[self.tableViewPeripheral
reloadData];
大概就这个个流程,例子中的参数设置,及其其他的一些代理请自己研究,因为我也是刚入门
例子在此,需要的请下载参考。
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467142',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'7152人阅读
低功耗蓝牙开发(9)
Base on the demo projects SimpleBLECentral and SimpleBLEPeripheral.
Backgroud:&/support/low_power_rf/f/538/p/8115.aspx#1108115
()Only 20 Bytes data can be transmitted in a time!&This is just the way BLE is setup.
SimpleBLECentral receive 40 bytes data from the uart. In order to transmit these 40 bytes data from SimpleBLECentral&to&SimpleBLEPeripheral, &I have to break these 40 bytes into two packets(Accroding to&Backgroud&)
. The first packet contain the first 20 bytes data. The second packet contain the last 20 bytes data.
Then call the&GATT_WriteCharValue&twice.
The &SimpleBLECentral &program I had reedit is below:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void serialAppInitTransport( )
halUARTCfg_t uartC
// configure UART
uartConfig.configured = TRUE;
uartConfig.baudRate = SBP_UART_BR;
uartConfig.flowControl = SBP_UART_FC;
uartConfig.flowControlThreshold = SBP_UART_FC_THRESHOLD;
uartConfig.rx.maxBufSize = SBP_UART_RX_BUF_SIZE;
uartConfig.tx.maxBufSize = SBP_UART_TX_BUF_SIZE;
uartConfig.idleTimeout = SBP_UART_IDLE_TIMEOUT;
uartConfig.intEnable = SBP_UART_INT_ENABLE;
uartConfig.callBackFunc =&sbpSerialAppCallback;
// start UART
// Note: Assumes no issue opening UART port.
(void)HalUARTOpen( SBP_UART_PORT, &uartConfig );
uint16 numB
void&sbpSerialAppCallback(uint8 port, uint8 event)
uint8 pktBuffer[SBP_UART_RX_BUF_SIZE];
// un PC-Lint error 715.
& & & (void)
& & & int i=0;
& & & for(i=12000;i&0;i--)
& & & & & asm(&nop&);
if ( (numBytes = Hal_UART_RxBufLen(port)) & 0 ) // &In the example numBytes =&40
(void)HalUARTRead (port, pktBuffer, numBytes);
& & if &(pktBuffer[0]=='A' && pktBuffer[1]=='T')
& & & & CommondHandle(pktBuffer, numBytes);
& & & & &sbpGattWriteString(pktBuffer,numBytes/2); && &&&first &-- tranmit the first 20 bytes data
& & & & & for(i=12000;i&0;i--)
& & & & &{
& & & & & & & asm(&nop&);
& & & & & }
& & & &&sbpGattWriteString(pktBuffer&#43;20,numBytes/2); &second-- tranmit the last 20 bytes data
uint8&sbpGattWriteString(uint8 *pBuffer, uint16 length)
if(length & 20)
attWriteReq_
req.handle = simpleBLECharH
req.sig = 0;
req.cmd = 0;
osal_memcpy(req.value,pBuffer,len);
status =&GATT_WriteCharValue( simpleBLEConnHandle, &req, simpleBLETaskId );
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
I found that the&SimpleBLEPeripheral only receive the first 20 bytes data, and the last 20 bytes data lost.
Is there some thing wrong with the app or the Osal ?
It seem that something wrong with the delay time between the first&sbpGattWriteString&and the second&sbpGattWriteString&.
It seem that there is a watch dog in the Osal, then I cannot extend the “nor” waiting &time easily.
How can I solve this problem?
Thanks you !
Rather than waiting in busy loop, your task needs to return control to OSAL so the various BLE tasks can handle the write request and write response. &Your task will be notified when the write has completed - have a look at simpleBleCentral.c; in particular
, see logic around&simpleBLECentralProcessGATTMsg().
二、 notify
notification类&#20284;主动上报,数据的变化可以直接从server通知给client.你得先搞清楚这两种不同的通讯方式。
1.client -&server
client 发request到server,server 回应response.读写都行。
2.server-&client.
server主动发notification给Client 反映自己的属性变化。这根读写没关系吧。
server- 有数据的. client- 访问数据的。不论是mater还是slaver都可以是server或client,甚至既可以是server同时又是client.
To enable notifications, you must write a value of 0x0001 to the client characteristic configuration descriptor (CCCD). If you know the handle of the client characteristic descriptor, you can enable notifications by using the following code:
& attWriteReq_t writeR
& uint16 connHandle = connectionH& // this will always be 0 if device only ever has one connection at a time
& writeReq.handle = handleOfCCCD; // if you know the value, you can put it
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // otherwise you will need to first discover the value
& writeReq.len = 2;
& writeReq.value[0] = LO_UINT16(GATT_CLIENT_CFG_NOTIFY);
& writeReq.value[1] = HI_UINT16(GATT_CLIENT_CFG_NOTIFY);
& writeReq.sig = 0;
& writeReq.cmd = 1;
& GATT_WriteNoRsp( connHandle, &writeReq, taskId );
Before doing this, you may also need to discover the handle of the CCCD. Some example of this process can be found in the TimeApp project which is included in the SDK. Specifically, look in the file &timeapp_discovery.c&.
三、数据收发
说简单点,先discovery(GAPCentralRole_StartDiscovery),回调中处理simpleBLECentralStartDiscovery(),通过UUID找到对应的handle,handle就是
attribute的地址,然后就可以使用GATT_WriteCharValue()或GATT_ReadCharValue()像指定的handle发送读写操作。最后在simpleBLECentralProcessGATTMsg()处理操作结果。还有另外一种通讯方式是notification,就是server主动向Client发送数据,不同于上面这种request/response模式,附图如下。
四、handle&#20540;的发现
static void simpleBLEGATTDiscoveryEvent( gattMsgEvent_t *pMsg )
& attReadByTypeReq_
& if ( simpleBLEDiscState == BLE_DISC_STATE_SVC )
&&& // Service found, store handles
&&& if ( pMsg-&method == ATT_FIND_BY_TYPE_VALUE_RSP &&
&&&&&&&& pMsg-&msg.findByTypeValueRsp.numInfo & 0 )
&&&&& simpleBLESvcStartHdl = pMsg-&msg.findByTypeValueRsp.handlesInfo[0].
&&&&& simpleBLESvcEndHdl = pMsg-&msg.findByTypeValueRsp.handlesInfo[0].grpEndH
&&& // If procedure complete
&&& if ( ( pMsg-&method == ATT_FIND_BY_TYPE_VALUE_RSP& &&
&&&&&&&&&& pMsg-&hdr.status == bleProcedureComplete ) ||
&&&&&&&& ( pMsg-&method == ATT_ERROR_RSP ) )
&&&&& if ( simpleBLESvcStartHdl != 0 )
&&&&&&& // Discover characteristic
&&&&&&& simpleBLEDiscState = BLE_DISC_STATE_CHAR;
&&&&&&& req.startHandle = simpleBLESvcStartH
&&&&&&& req.endHandle = simpleBLESvcEndH
&&&&&&& req.type.len = ATT_BT_UUID_SIZE;
&&&&&&& //req.type.uuid[0] = LO_UINT16(SIMPLEPROFILE_CHAR1_UUID);
&&&&&&& //req.type.uuid[1] = HI_UINT16(SIMPLEPROFILE_CHAR1_UUID);
&&&&&&& req.type.uuid[0] = LO_UINT16(SIMPLEPROFILE_CHAR4_UUID);
&&&&&&& req.type.uuid[1] = HI_UINT16(SIMPLEPROFILE_CHAR4_UUID);
&&&&&&& GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req, simpleBLETaskId );
& else if ( simpleBLEDiscState == BLE_DISC_STATE_CHAR )
&&& // Characteristic found, store handle
&&& if ( pMsg-&method == ATT_READ_BY_TYPE_RSP &&
&&&&&&&& pMsg-&msg.readByTypeRsp.numPairs & 0 )
&&&&& /*simpleBLECharHdl = BUILD_UINT16( pMsg-&msg.readByTypeRsp.dataList[0],
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& pMsg-&msg.readByTypeRsp.dataList[1] );*/
&&&&& simpleBLECharHd4 = BUILD_UINT16( pMsg-&msg.readByTypeRsp.dataList[0],
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& pMsg-&msg.readByTypeRsp.dataList[1] );
&&&&& LCD_WRITE_STRING( &Simple Svc Found&, HAL_LCD_LINE_1 );
&&&&& simpleBLEProcedureInProgress = FALSE;
&&& simpleBLEDiscState = BLE_DISC_STATE_IDLE;
//注意:如果client刚刚发送了一次请求但是server还未返回,这时候client就不应该再次发送请求信息,如果发送,server会将此丢弃。
Once a client sends a request to a server, that client shall send no other request to the same server until a response PDU has been received.
五、绑定管理
1) simpleperipheral 和 central的例子,他们初始化都是设置的GAPBOND_PAIRING_MODE_WAIT_FOR_REQ等待配对.
那么我的问题是,到底是peripheral发起的配对请求还是central?在什么时候发起的配对请求?
这样两边其实都没有发起配对.
除非其中一个配置成GAPBOND_PAIRING_MODE_INITIATE, 如果是central的话会发起pairing request, 如果是peripheral的话会发起slave security request, 最终会导致central那端收到&GAP_SLAVE_REQUESTED_SECURITY_EVENT, 这个时候你看代码, 如果central也是出于GAPBOND_PAIRING_MODE_WAIT_FOR_REQ, 那么他还是会发起配对.
所以, 只要其中一个设置成GAPBOND_PAIRING_MODE_INITIATE, 两边就会配对, 如果都是GAPBOND_PAIRING_MODE_WAIT_FOR_REQ, 那么就没有配对过程.
你可以修改其中一个看看哈.
2) 只要其中一个设置成GAPBOND_PAIRING_MODE_INITIATE, 两边就会配对”。那么配对的时候,两边是不是互相需要发送密码才行?只有密码对了才算配对成功吗?
必须会有密码.
至于是否要手动输入, 根据设备的IO Capability 设置来的. 就是设备的输入输出能力.
关于绑定我看代码的时候遇到了一些疑问。如下:
例子代码中,每当链接成功事件产生后,会通知绑定管理
&&&&&&&&&& &// Notify the Bond Manager to the connection
&&&&&&&&& VOID GAPBondMgr_LinkEst( pPkt-&devAddrType, pPkt-&devAddr, pPkt-&connectionHandle, GAP_PROFILE_PERIPHERAL );
这个函数的作用是绑定蓝牙吗?
bStatus_t GAPBondMgr_LinkEst( uint8 addrType, uint8 *pDevAddr, uint16 connHandle, uint8 role )
& uint8&&&&&&&&&&&&&&&&&&&&&&&&& // NV Index
& uint8 publicAddr[B_ADDR_LEN]&&&&&&& // Place to put the public address
&&&&& = {0, 0, 0, 0, 0, 0};
& idx = GAPBondMgr_ResolveAddr( addrType, pDevAddr, publicAddr );
& if ( idx & GAP_BONDINGS_MAX )
&&&&&&&&&&&&&&& ……
代码中只有判断 idx & GAP_BONDINGS_MAX ,意思是这个蓝牙地址在绑定列表中?
如果idx & =GAP_BONDINGS_MAX 呢?
GAP_BONDINGS_MAX 是flash 里面允许存储的最多的绑定设备信息的个数.
你不用担心怎么绑定的, 绑定的工作底层自动会把做好的.
你要做的只是在应用层的宏定义里面打开绑定, 设置一下IO capability 就行. 如果你的设备的IO capability 设置成有输入功能, 就会要求输入密码, 如果你是没有输入功能更, 系统会自动产生随机密码.
1、当绑定信息个数达到GAP_BONDINGS_MAX的时候,又来了一个要绑定的设备信息,例程是如何处理的?先删除一个最后再添加?还是按FIFO或者其他存储方式呢?谢谢!
2、我试了一下pairing功能,当使能pairing时,主设备和从设备第一次配对的时候使用回调函数会在LCD屏幕上显示pairing start、pairing success的过程;当断开链接,第二次再链接时,屏幕上才会显示Bonds success。不知道为什么第二次链接时才显示 Bonds success。为什么?
3、当pairing success之后,主设备程序不变,把从设备的程序从新下载之后,主设备和从设备都不再执行pairing回调函数了,即LCD不再显示pairing start、pairing success和Bonds success.但是反过来,将主设备的程序从新下载后,从设备程序不变,又能正常执行pairing回调函数,即能在LCD上显示pairing start、pairing success和Bonds success。为什么?
1. 你可以这样理解, 最多绑定个数理论上, 说的是理论上, 是没有限制的, 无非就是需要一些flash 空间存储些对方设备信息而已. 但是实际中, 你flash 空间毕竟是有限的, 所以只能限定个数. 比如10 个. 如果超出, 代码会去判断前面是否已经有设备 已经解除配对了, 如果有, 就用这个位置存放新的信息. 如果没有, 就不保存了. &实际开发中你可以做个提示, 告诉用户空间已满, 请删除空闲已配对设备, 腾出空间. 你如果仔细想一下的话, 想想手机, 很多手机都是有已配对设备个数限制的(现在的智能手机可能还好点,
空间大, 但肯定也不会放你无限使用), 一旦个数达到极限,肯定会提醒.&
2. 不知道你是在哪里加的打印代码?&
3. 是因为从设备是&GAPBOND_PAIRING_MODE_WAIT_FOR_REQ 模式吧.
关于默认密码, 请看定义:
// Default passcode
#define DEFAULT_PASSCODE 19655
类&#20284;, 密码可以自己设置.
把两边 IO capability 定义都改成如下, 就不需要输入密码, 系统会自动产生密码或者用默认密码, 具体请看一下代码
// Default GAP bonding I/O capabilities
#define DEFAULT_IO_CAPABILITIES GAPBOND_IO_CAP_DISPLAY_ONLY
5)修改蓝牙地址
查看文档5.3.2
Every&/41 device comes pre-programmed with a unique 48-bit IEEE address. This is referred to as
the device’s “primary address”, and cannot be changed. It is also possible to set a “secondary address” on
a device, which will override the primary address upon power-up. Flash Programmer can be used to read
the primary address, as well as to read or write the secondary address.
To read the primary address of a device connected to the CC Debugger, select “Primary” under the
“Location” option, and click the “Read IEEE” button. The primary device address should appear in the box
on the right as shown in Figure 48.
To read the secondary address, select “Secondary” under the “Location” option, and click the “Read IEEE”
button. The secondary device address should appear in the box on the right.
To set a new secondary address, select “Secondary” under the “Location” option, and enter the desired
address in the box on the right. Click the “Write IEEE” button to perform the write. If the secondary
device is set to “FF FF FF FF FF FF”, the device will use the primary address. If the secondary device is set
to anything else, the secondary address will be used.
六、蓝牙断开连接问题
首先要确定是否主从机均已经初始化完毕,如果对方没有初始化,那当然无法连接。
确定好后还有问题,那么一般是因为主机没有更新链路。这个过程为,从机的DEFAULT_ENABLE_UPDATE_REQUEST 设置为TRUE,从机就会发送一个param update的请求,然后主机就会出现一个在simpleBLECentralEventCB中产生一个GAP_LINK_PARAM_UPDATE_EVENT事件,然后主机就会去做这个链路更新。
所以我们要做的就是确定这个DEFAULT_ENABLE_UPDATE_REQUEST 设置成TRUE了。
补充说明:
对于BLE Link Layer层上断开连接的说明。
连接断开可能是由于主机或者从机身上的任何原因。一方断开连接,另外一方必须在退出连接状态之前响应其断开连接的请求。
连接断开也可能是因为超时:
-- 最大超时参数定义了主从机在接收到Link Layer层的包之前的最大时间。
-- 最大超时时间必须大于有效的连接间隔,必须小于32s。
-- 主从机均存有一个超时&#20540;,每当收到一个包被收到时,该超时&#20540;置为零。
-- 如果超时时间超过了最大超时时间,那么设备就应该当成连接已经断开,并且退出连接。&
七、无法搜索到设备的原因
1、这边有一个宏非常关键,DEFAULT_DEV_DISC_BY_SVC_UUID这个宏,默认为TRUE,但是在代码里面:
static void simpleBLECentralEventCB( gapCentralRoleEvent_t *pEvent )
&if ( DEFAULT_DEV_DISC_BY_SVC_UUID == FALSE ) //此处判断
& & & & & // Copy results
& & & & & simpleBLEScanRes = pEvent-&discCmpl.numD
& & & & & osal_memcpy( simpleBLEDevList, pEvent-&discCmpl.pDevList,
& & & & & & & & & & & &(sizeof( gapDevRec_t ) * pEvent-&discCmpl.numDevs) );
看完代码就知道,扫描的&#20540;没有被赋&#20540;,因此一直为0。
2、这几天出现的一个BUG让我调试好久,一直不知道错误在哪里,昨天终于发现了,等下把代码贴出来,然后晚上再把写好的代码贴好。
出现的问题是: Central主机,扫描,然后连接,断开连接,没有问题,再次扫描,调用GAP_DeviceDiscoveryRequest()开始搜索,并且返回为SUCCESS,但是奇怪的是没有任何回应,一般协议栈应该会产生一个GAP_DEVICE_DISCOVERY_EVENT事件,但是结果是明晚在那边打了断点没有进。
查找了N久之后,问题出现在一个变量身上,这个变量是simpleBLEDiscState。
下面贴出产生问题的地方:
static void simpleBLEGATTDiscoveryEvent( gattMsgEvent_t *pMsg )
attReadByTypeReq_
static uint8 Flag = 1;
switch (Flag)
Uuid = UUID_XX1;
Uuid = UUID_XX2;
Uuid = UUID_XX3;
if ( simpleBLEDiscState == BLE_DISC_STATE_SVC )
// Service found, store handles
if ( pMsg-&method == ATT_FIND_BY_TYPE_VALUE_RSP &&
pMsg-&msg.findByTypeValueRsp.numInfo & 0 )
simpleBLESvcStartHdl = pMsg-&msg.findByTypeValueRsp.handlesInfo[0].
simpleBLESvcEndHdl = pMsg-&msg.findByTypeValueRsp.handlesInfo[0].grpEndH
// If procedure complete
if ( ( pMsg-&method == ATT_FIND_BY_TYPE_VALUE_RSP
pMsg-&hdr.status == bleProcedureComplete ) ||
( pMsg-&method == ATT_ERROR_RSP ) )
if ( simpleBLESvcStartHdl != 0 )
// Discover characteristic
simpleBLEDiscState = BLE_DISC_STATE_CHAR;
req.startHandle = simpleBLESvcStartH
req.endHandle = simpleBLESvcEndH
req.type.len = ATT_BT_UUID_SIZE;
req.type.uuid[0] = LO_UINT16(Uuid);
req.type.uuid[1] = HI_UINT16(Uuid);
GATT_ReadUsingCharUUID( ULOCKBLEConnHandle, &req, simpleBLETaskId );
if(Flag == 2 || Flag == 3
simpleBLEDiscState = BLE_DISC_STATE_CHAR;
req.startHandle = simpleBLESvcStartH
req.endHandle = simpleBLESvcEndH
req.type.len = ATT_BT_UUID_SIZE;
req.type.uuid[0] = LO_UINT16(Uuid);
req.type.uuid[1] = HI_UINT16(Uuid);
GATT_ReadUsingCharUUID( ULOCKBLEConnHandle, &req, simpleBLETaskId );
else if ( simpleBLEDiscState == BLE_DISC_STATE_CHAR )
// Characteristic found, store handle
if(pMsg-&method == ATT_READ_BY_TYPE_RSP &&
pMsg-&msg.readByTypeRsp.numPairs & 0 )
if(UUID_XX1== Uuid)
handlexx_1= BUILD_UINT16( pMsg-&msg.readByTypeRsp.dataList[0],
pMsg-&msg.readByTypeRsp.dataList[1] );
SerialPrintValue(&handle found ! value : &,handlexx_1,10);
SerialPrintString(&\r\n&);
else if(UUID_XX2 == Uuid)
handlexx_2= BUILD_UINT16( pMsg-&msg.readByTypeRsp.dataList[0],
pMsg-&msg.readByTypeRsp.dataList[1] );
SerialPrintValue(&handle found! value : &,handlexx_2,10);
SerialPrintString(&\r\n&);
else if(UUID_XX3 == Uuid)
handlexx_3 = BUILD_UINT16( pMsg-&msg.readByTypeRsp.dataList[0],
pMsg-&msg.readByTypeRsp.dataList[1] );
SerialPrintValue(&handle found! value : &,handlexx_3,10);
SerialPrintString(&\r\n&);
simpleBLEDiscState=BLE_DISC_STATE_SVC;
好了,终于把这个BUG完完全全的给弄好了!
下面看代码:
*这里参考的是TI的同时参考两个特征值的代码
*可以看我另一篇文档查看
*http://blog.csdn.net/qaqwe/article/details/
#if defined(MULT_CHAR_DISC)
static void simpleBLEGATTDiscoveryEvent( gattMsgEvent_t *pMsg )
attReadByTypeReq_
if ( simpleBLEDiscState == BLE_DISC_STATE_SVC )
// Service found, store handles
if ( pMsg-&method == ATT_FIND_BY_TYPE_VALUE_RSP &&
pMsg-&msg.findByTypeValueRsp.numInfo & 0 )
simpleBLESvcStartHdl = pMsg-&msg.findByTypeValueRsp.handlesInfo[0].
simpleBLESvcEndHdl = pMsg-&msg.findByTypeValueRsp.handlesInfo[0].grpEndH
// If procedure complete
if ( ( pMsg-&method == ATT_FIND_BY_TYPE_VALUE_RSP
pMsg-&hdr.status == bleProcedureComplete ) ||
( pMsg-&method == ATT_ERROR_RSP ) )
if ( simpleBLESvcStartHdl != 0 )
// Discover characteristic
simpleBLEDiscState = BLE_DISC_STATE_CHAR1;
req.startHandle = simpleBLESvcStartH
req.endHandle = simpleBLESvcEndH
req.type.len = ATT_BT_UUID_SIZE;
req.type.uuid[0] = LO_UINT16(xxUUID_1);
req.type.uuid[1] = HI_UINT16(xxUUID_1);
GATT_ReadUsingCharUUID( simpleBLEConnHandle, &req, simpleBLETaskId );
else if ( simpleBLEDiscState == BLE_DISC_STATE_CHAR1 )
// Characteristic found, store handle
if ( pMsg-&method == ATT_READ_BY_TYPE_RSP &&
pMsg-&msg.readByTypeRsp.numPairs & 0 )
xxhandle_1 = BUILD_UINT16( pMsg-&msg.readByTypeRsp.dataList[0],
pMsg-&msg.readByTypeRsp.dataList[1] );
//ReadAttrNum = ULOCK_STAT;
SerialPrintValue(&ulock state handle : &,xxhandle_1,10);
SerialPrintString(&\r\n&);
simpleBLEProcedureInProgress = TRUE;
else // pMsg-&msg.readByTypeRsp.numPairs is 0.
simpleBLEDiscState = BLE_DISC_STATE_CHAR2;
req.startHandle = simpleBLESvcStartH
req.endHandle = simpleBLESvcEndH
req.type.len = ATT_BT_UUID_SIZE;
req.type.uuid[0] = LO_UINT16(xxUUID_2);
req.type.uuid[1] = HI_UINT16(xxUUID_2);
GATT_DiscCharsByUUID( simpleBLEConnHandle, &req, simpleBLETaskId );
else if (simpleBLEDiscState == BLE_DISC_STATE_CHAR2)
// Characteristic found, store handle
if ( pMsg-&method == ATT_READ_BY_TYPE_RSP &&
pMsg-&msg.readByTypeRsp.numPairs & 0 )
//这边查找到的handle需要加1
//注意GATT_DiscCharsByUUID 查找到的handle非特征值的handle,需要加1
//GATT_ReadUsingCharUUID 查找到的handle为特征值的handle
xxhandle_2 = BUILD_UINT16( pMsg-&msg.readByTypeRsp.dataList[0],
pMsg-&msg.readByTypeRsp.dataList[1] ) + 1;
SerialPrintValue(&ulock control handle : &,xxhandle_2,10);
SerialPrintString(&\r\n&);
simpleBLEProcedureInProgress = FALSE;
//重要,否则将在下次扫描时无法回应扫描结果
simpleBLEDiscState = BLE_DISC_STATE_IDLE;
八、OAD问题
/question_answer/wireless_connectivity/bluetooth/f/103/t/60727.aspx
/question_answer/wireless_connectivity/bluetooth/f/103/t/51134.aspx
/BLOG_ARTICLE_3019402.HTM
九、RSSI换算距离
要知道蓝牙通信节点(如手机和蓝牙设备)之间的距离,最容易实现的方法是通过读取接收()&#20540;来计算。无线通讯中功率与距离的关系如下:
其中可以看作是信号传输米远时接收信号的功率,是传播因子(它受障碍,温度和湿度等影响),是节点之间的距离。当确定了常数与的&#20540;后,距离就可以根据计算出来。
一般比较难算的话可以通过实际测量来确定!
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:47808次
排名:千里之外
原创:40篇
转载:21篇
(1)(1)(1)(1)(1)(2)(2)(3)(1)(7)(18)(4)(5)(12)(1)(3)

我要回帖

更多关于 write down value 的文章

 

随机推荐