我正在使用 HM-10 和 Arduino 将数据从 iOS 应用程序发送到 Arduino,问题是我可以从我的应用程序连接到蓝牙模块,但我找不到设备特征。
问题是缺少配置蓝牙模块以使该服务可用的东西,或者我应该怎么做。
let BLEService = "DFB0"
let BLECharacteristic = "DFB1"
var mainCharacteristic:CBCharacteristic? = nil
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
for service in peripheral.services! {
print("Service found with UUID: " + service.uuid.uuidString)
//device information service
if (service.uuid.uuidString == "180A") {
peripheral.discoverCharacteristics(nil, for: service)
}
//GAP (Generic Access Profile) for Device Name
// This replaces the deprecated CBUUIDGenericAccessProfileString
if (service.uuid.uuidString == "1800") {
peripheral.discoverCharacteristics(nil, for: service)
}
//Bluno Service
if (service.uuid.uuidString == BLEService) {
peripheral.discoverCharacteristics(nil, for: service)
}
}
}
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
//get device name
if (service.uuid.uuidString == "1800") {
for characteristic in service.characteristics! {
if (characteristic.uuid.uuidString == "2A00") {
peripheral.readValue(for: characteristic)
print("Found Device Name Characteristic")
}
}
}
if (service.uuid.uuidString == "180A") {
for characteristic in service.characteristics! {
if (characteristic.uuid.uuidString == "2A29") {
peripheral.readValue(for: characteristic)
print("Found a Device Manufacturer Name Characteristic")
} else if (characteristic.uuid.uuidString == "2A23") {
peripheral.readValue(for: characteristic)
print("Found System ID")
}
}
}
if (service.uuid.uuidString == BLEService) {
for characteristic in service.characteristics! {
if (characteristic.uuid.uuidString == BLECharacteristic) {
//we'll save the reference, we need it to write data
mainCharacteristic = characteristic
//Set Notify is useful to read incoming data async
peripheral.setNotifyValue(true, for: characteristic)
print("Found Bluno Data Characteristic")
}
}
}
}
注意:我使用应用商店中的通用 Android 应用进行了尝试,它可以正常工作