2017-10-05 10 views
0

私はarduinoフェザーBLEボードを使用しており、BLE経由でボードにデータを送信できるiOSアプリケーションを作成しようとしています。私は接続できますが、私はtxCharacteristiciOS Bluetooth Low Energy(BLE)がTX特性を検出しない

func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) { 
    guard let characteristics = service.characteristics else { 
     return 
    } 

    for characteristic in characteristics { 
     if characteristic.properties.contains(.write) || characteristic.properties.contains(.writeWithoutResponse) { 
      writableCharacteristic = characteristic 
     } 

     //   if(characteristic.uuid == CBUUID(string: "6e400002-b5a3-f393-e0a9-e50e24dcca9e")) 
     //   { 
     //    txCharacteristic = characteristic 
     //   } 

     var txUUID = CBUUID(string: "6e400002-b5a3-f393-e0a9-e50e24dcca9e") 
     let temp = characteristic.uuid.uuidString; 
     switch characteristic.uuid { 
     case txUUID: 
      txCharacteristic = characteristic; 
      break; 
     default: 
      break; 
     } 

     peripheral.setNotifyValue(true, for: characteristic) 
    } 
} 

このコードが動作へのアクセスを取得することはできませんが、唯一、次のUUIDを検出します。

temp String "00001532-1212-EFDE-1523-785FEABCD123" 
temp String "00001531-1212-EFDE-1523-785FEABCD123" 
temp String "00001534-1212-EFDE-1523-785FEABCD123" 

私はこれらのUUID年代はDFUのUUIDであることを考え出しました。代わりにtxCharacteristicをどのように発見できますか?私はこのウェブサイトで情報を読むことによって、これを理解することができた

extension SimpleBluetoothIO: CBPeripheralDelegate { 
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) { 
    guard let services = peripheral.services else { 
     return 
    } 

    targetService = services.first 
    if let service = services.first { 
     targetService = service 
     peripheral.discoverCharacteristics(nil, for: service) 
    } 
} 
+1

あなたは確かのことです適切なデバイスの適切なサービス?あなたは適切な引数で 'discoverServices'と' discoverCharacteristics'を呼び出しましたか? BLEブラウザをダウンロードし、表示される内容を確認してください。 – Kevin

+0

こんにちは、ご協力いただきありがとうございます。すべてのサービスを検出するdiscoverServices(nil)を呼び出しました。上記の質問にdiscoverCharacteristics()を呼び出すコードを追加しました。 – Megan

答えて

0

https://learn.adafruit.com/getting-started-with-the-nrf8001-bluefruit-le-breakout/adding-app-support

特にこの部分、私は)(discoverCharacteristicsを呼び出しています方法の詳細について


を追加しました(UARTはサービスであり、TXとRXはそのサービスの特性であることに注意してください)。

UART Service UUID: 6E400001-B5A3-F393-E0A9-E50E24DCCA9E 
TX Characteristic UUID: 6E400002-B5A3-F393-E0A9-E50E24DCCA9E 
RX Characteristic UUID: 6E400003-B5A3-F393-E0A9-E50E24DCCA9E 

私はUARTサービスIDでperipheral.discoverServices()を呼び出す必要がありました。 self.serviceUUID = "6e400001-b5a3-F393-e0a9-e50e24dcca9e"

func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) { 
    //peripheral.discoverServices(nil) 
    //peripheral.discoverServices([CBUUID(string: "6e400001-b5a3-f393-e0a9-e50e24dcca9e")]) 

    // Disover peripheral with service UUID that was given to us during initialization (self.serviceUUID) 
    peripheral.discoverServices([CBUUID(string: self.serviceUUID)]) 
} 

以下の私の例ではその後didDiscoverCharacteristicsForサービスに私はTX特性IDを探すために必要な:

// Did Discover Characteristics 
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) { 
    guard let characteristics = service.characteristics else { 
     return 
    } 

    for characteristic in characteristics { 
     if characteristic.properties.contains(.write) || characteristic.properties.contains(.writeWithoutResponse) { 
      writableCharacteristic = characteristic 
     } 

     // TX Characteristic UUID: 6E400002-B5A3-F393-E0A9-E50E24DCCA9E 
     // https://learn.adafruit.com/getting-started-with-the-nrf8001-bluefruit-le-breakout/adding-app-support 
     let txUUID = CBUUID(string: "6e400002-b5a3-f393-e0a9-e50e24dcca9e") 
     switch characteristic.uuid { 
     case txUUID: 
      txCharacteristic = characteristic; 
      break; 
     default: 
      break; 
     } 

     peripheral.setNotifyValue(true, for: characteristic) 
    } 
} 
関連する問題