BlueFruit BLE SPIモジュールを使用しているArduinoプロジェクトに接続しようとしています。 iOSアプリを使用して接続しようとすると問題が発生します。私はデバイスに接続しようとしたが、状態は接続状態= 1になっている。これは、サービスの検索から私を防ぎ、このような「接続」状態が...。ここ を達成したコードスニップがあるされていないため、Bluetooth周辺機器が「接続中」状態でiOSに接続しています
//check state of the bluetooth on phone
func centralManagerDidUpdateState(_ central: CBCentralManager) {
if central.state == .poweredOff{
//TODO: ADD SAVE DATA TO REALM BEFORE DISSMISSING
errorView.isHidden = false
}
if central.state == .poweredOn{
errorView.isHidden = true
//scan for peripherals with the service i created
central.scanForPeripherals(withServices: nil, options: nil)
}
}
//devices found(should only be ours because we will create Unique serviceID)
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
// get advertisement data and check to make sure the name is matching. set it as the peripheral then make connection
if let peripheralName = advertisementData[CBAdvertisementDataLocalNameKey] as? String {
print("NEXT PERIPHERAL NAME: \(peripheralName)")
print("NEXT PERIPHERAL UUID: \(peripheral.identifier.uuidString)")
if peripheralName == nameID{
manager.stopScan()
self.peripheralHalo = peripheral
peripheralHalo!.delegate = self
manager.connect(peripheral, options: nil)
while(peripheralHalo?.state.rawValue == 1)
{
if(manager.retrieveConnectedPeripherals(withServices: [serviceID]).count > 0){
print("\(manager.retrieveConnectedPeripherals(withServices: [serviceID]))")
}
}
}
print("Connected!!")
}
私は呼んでmanager.connect(周辺機器、オプション:ゼロ)、ペリフェラルは接続しようとします。テストのために以下のwhileループを追加し、常に状態を「接続」として表示します。 LightBlue iOSアプリを試してみましたが、特性値の変更の通知を適切に接続して受け取ることができるので、Arduinoのファームウェアはすごくいいはずです。ご参考までに!
ありがとうございました。私はwhileループなしでそれを試していますし、「didconnect」も「didfailconnect」も呼び出されません。 – StoNeD510
ありがとうポールそれをした!私はすべてを試したと思って、何時間も時間を費やしてそれを見つめていました。私があなたの投稿したコードから切り替えたのは、周辺機器への私のハードリファレンスであり、代理人はdidDiscoverで作られなければなりませんでした。そうでなければ接続を落としていた – StoNeD510
ええ、私はそれについてはわからなかった。私はちょうどテストするためのコードを書いていました。 – Paulw11