2

I need to send data from my iPhone 5s to Raspberry Pi (Model B). But the problem is, Raspberry Pi bluetooth not discovering by program, But It is discovered and paired from iPhone default Bluetooth settings(screenshot attached).

Also, my iBeacons(Transmitter only) are programmatically discovered, but Raspberry Pi not.

How can I detect Raspberry Pi (Model B) bluetooth same as iPhone Bluetooth settings in Swift?

Tried Code:

import UIKit
import CoreBluetooth

class ViewController: UIViewController,CBCentralManagerDelegate {

    var centralManager:CBCentralManager!

    override func viewDidLoad() {
        super.viewDidLoad()

        self.centralManager = CBCentralManager(delegate: self, queue: .main)



    }

    func centralManagerDidUpdateState(_ central: CBCentralManager) {

        switch central.state {

        case .poweredOn:

            print("Powerd On State  ")
            let options: [String: Any] = [CBCentralManagerScanOptionAllowDuplicatesKey:
                NSNumber(value: false)]
            self.centralManager.scanForPeripherals(withServices: nil, options: options)

        case .poweredOff:
            print("Power on the Bluetooth")
        default:
            print("Something went wrong!")
            break
        }
    }

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

        print("Peripheral Discovered: ",peripheral.name ?? "Nil")
    }

}

iPhone Bluetooth settings:

enter image description here

Regarding Console Output:

enter image description here

  • 1
    you can try to use MultiPeer Connectivity. I uses the default Bluetooth manager for the pairing https://developer.apple.com/documentation/multipeerconnectivity – Vasilis D. Jun 08 '18 at 14:39
  • @ΒασίληςΔ. Ok thanks for the suggestion –  Jun 08 '18 at 14:43
  • But I think that the issue with your code is that you haven't set the delegate... So in ViewDidLoad add the code self.centralManager.delegate = self – Vasilis D. Jun 08 '18 at 14:50
  • @ΒασίληςΔ. , Thanks, But I already delegated here `self.centralManager = CBCentralManager(delegate: self, queue: .main)` that's why the beacons are discovering –  Jun 08 '18 at 16:20
  • Hi, if solved please share the solution. Thanks! – Harsh Chaurasia Jan 14 '19 at 12:16
  • Please check this : https://stackoverflow.com/questions/37927606/how-do-i-make-raspberry-pi-3-discoverable-for-ios-and-corebluetooth – Amit Feb 25 '23 at 06:55

0 Answers0