使用iOS SDK中的BLE从外部设备发送和接收数据

使用iOS SDK中的BLE从外部设备发送和接收数据,ios,objective-c,swift,bluetooth,Ios,Objective C,Swift,Bluetooth,我必须使用BLE从外部设备(数据记录器温度计)获取数据。请参阅此设备的下图 此设备仅在发送一个命令时发送数据。我的意思是,我们必须先向设备发送静态字节数据,然后它将返回T1、T2、T3和T4值的数据,这些数据显示在图像中 我可以使用BLE将数据发送到一个iOS设备到另一个iOS设备。但是,我不能用这种方式向这个外部设备发送和接收数据 正如本演示中提到的,我使用cbperipheraldmanager和CBCentralManager使用BLE发送和接收数据。此外,我还可以使用EAAccessor

我必须使用BLE从外部设备(数据记录器温度计)获取数据。请参阅此设备的下图

此设备仅在发送一个命令时发送数据。我的意思是,我们必须先向设备发送静态字节数据,然后它将返回T1、T2、T3和T4值的数据,这些数据显示在图像中

我可以使用BLE将数据发送到一个iOS设备到另一个iOS设备。但是,我不能用这种方式向这个外部设备发送和接收数据

正如本演示中提到的,我使用
cbperipheraldmanager
CBCentralManager
使用BLE发送和接收数据。此外,我还可以使用
EAAccessoryManager
显示所有附近的BLE连接的列表。所以,当用户单击列表中的任意设备时,我将获取该设备的UUID,并尝试使用该UUID发送和接收数据

是否有其他方法使用蓝牙将数据发送到iOS设备并接收到任何外部设备。

我想和大家分享一下,Android开发者已经用SSP而不是BLE在Android中实现了这一点。在iOS中使用BLE可以做到这一点吗


任何帮助都将不胜感激。

我始终使用CoreBluetooth实现此协议(CBCentralManagerDelegate、CBPeripherDelegate)并覆盖此方法:

func centralManagerDidUpdateState(_ central: CBCentralManager)

func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber)

func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral)

func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?)

func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?)

// Check if the service discovered is a valid Service
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?)

func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?)

// And for getting the value changes in the BLE Device...
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?)

func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic, error: Error?)

我希望它能有所帮助

我总是使用CoreBluetooth实现此协议(CBCentralManagerDelegate、CBPeripherDelegate)并覆盖此方法:

func centralManagerDidUpdateState(_ central: CBCentralManager)

func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber)

func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral)

func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?)

func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?)

// Check if the service discovered is a valid Service
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?)

func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?)

// And for getting the value changes in the BLE Device...
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?)

func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic, error: Error?)

我希望它有帮助

在您写入或读取值之前,您需要知道哪些特征是可读的,哪些是可写的,而不是您可以读取或写入的。简单地说,BTLE的过程是:

扫描外围设备->连接->查找服务->发现特征->…您需要的操作

如果您想将值写入可写特征,则需要确认外围设备将响应此写入请求,否则您将在回调中收到错误:
peripal(\uU2DidWriteValueFor:error)
可能是“未知错误”。

其他当您尝试读取您需要调用的特征值时:
readValue(for:)
setNotifyValue(:for:)
,外围设备的更新结果将在
外围设备(:didUpdateValueFor:error:)


以上是我对BTLE数据传输的理解。希望对您有所帮助。

在您写入或读取值之前,您需要知道哪些特征是可读的,哪些是可写的,而不是您可以读取或写入的。简单地说,BTLE的过程是:

扫描外围设备->连接->查找服务->发现特征->…您需要的操作

如果您想将值写入可写特征,则需要确认外围设备将响应此写入请求,否则您将在回调中收到错误:
peripal(\uU2DidWriteValueFor:error)
可能是“未知错误”。

其他当您尝试读取您需要调用的特征值时:
readValue(for:)
setNotifyValue(:for:)
,外围设备的更新结果将在
外围设备(:didUpdateValueFor:error:)


以上是我对BTLE数据传输的理解。希望能帮助您。

您确定该设备确实支持BLE吗?经典蓝牙和BLE是两种不同的协议/栈。通过EAAccessoryManager可见的设备是典型的蓝牙设备,而不是可扩展设备。要扫描BLE设备,您应该使用
CBCentralManager ScanFor PeripheralsWithServices:选项:
。您确定该设备实际支持BLE吗?经典蓝牙和BLE是两种不同的协议/栈。通过EAAccessoryManager可见的设备是典型的蓝牙设备,而不是可扩展设备。要扫描可扩展设备,您应该使用
CBCentralManager scanforperipheranswithservices:options: