我想用我的iPad连接一个OLS426蓝牙低功耗模块,通过蓝牙模块上的串口发送数据。我已成功连接到蓝牙模块。在连接中,iPad作为中央设备,蓝牙模块作为外围设备。
以下是我的问题:
(1)
[peripheral setNotifyValue:YES forCharacteristic:characteristic];我订阅了didDiscoverCharacteristicsForService中的蓝牙模块。
- (void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{
NSLog(@"Subscribed");}
订阅后,在终端上打印“订阅”日志。这是否意味着我已经成功订阅了该设备?
(2)
我还尝试在didDiscoverCharacteristicsForService中为特征写入值。
[peripheral writeValue: data forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];由于我已经将类型设置为CBCharacteristicWriteWithResponse,所以我认为如果写入不成功,就会出现错误。但是,没有错误。
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{
NSLog(@"Hello sent");
}我的问题是,为什么在我为一个特征设置值之后,没有打印出"Hello sent“?
(3)
我想通过蓝牙模块上的串口发送一些数据。我只能从特征中读取数据,例如心率监视器,或者将数据写入特征。在蓝牙模块的服务中,我发现了一个叫做“串口”的模块,在它的下面有一个叫做"FIFO“的特性。因此,我想我应该将数据写入到特征中,以便通过串行端口发送数据。有人能告诉我我的想法是否正确吗?
发布于 2014-07-13 13:29:39
1)可以。
2)当特征值发生变化而与您自己对该特征的写入无关时,将调用didUpdateValueForCharacteristic。
3)读过如何通过先进先出特性读写数据的connectBlue document了吗?
https://stackoverflow.com/questions/24719473
复制相似问题