0

Using iOS 12.2 Xcode 10.2.1

Looking to connect to this [a Debian based UNIX box] using iOS iPad.I can see the device on my laptop. As you can see here.

enter image description here

And I can see it on my iPhone. And I can pair it with my iPhone.

enter image description here

I can log into ev3dev and use the bluetoothctl command in the shell to show me the details of the service.

[bluetooth]# show 
Controller 40:BD:32:3E:56:97
  Name: ev3dev
  Alias: ev3dev
  Class: 0x020100
  Powered: yes
  Discoverable: yes
  Pairable: yes
  UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
  UUID: NAP                       (00001116-0000-1000-8000-00805f9b34fb)
  UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
  UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
  UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
  UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
  Modalias: usb:v0694p0005d0316
  Discovering: no
 [CHG] Controller 40:BD:32:3E:56:97 Discoverable: no

But want to write a small app that can do so. New to bluetooth. I got this code, which seems to see everything except what I want to find.

import UIKit
import CoreBluetooth

class ViewController: UIViewController {

var manager:CBCentralManager!
var peripheral:CBPeripheral!

let X_NAME = "ev3dev"
let options: [String: Any] = [CBCentralManagerScanOptionAllowDuplicatesKey:
                          false]

 override func viewDidLoad() {
 super.viewDidLoad()
 manager = CBCentralManager(delegate: self, queue: nil)
 }
 }

extension ViewController: CBCentralManagerDelegate,
CBPeripheralDelegate {

  func centralManagerDidUpdateState(_ central: CBCentralManager) {

  if central.state == CBManagerState.poweredOn {
   central.scanForPeripherals(withServices: nil, options: options)
  } else {
   print("Bluetooth not available.")
 }
}

  func centralManager(_ central: CBCentralManager, didDiscover peripheral:     CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
  let device = (advertisementData as NSDictionary)
  .object(forKey: CBAdvertisementDataLocalNameKey)
as? NSString

  print("Discovered \(peripheral.name ?? "")")

  if device?.contains(X_NAME) == true {
    self.manager.stopScan()
    self.peripheral = peripheral
    self.peripheral.delegate = self
    manager.connect(peripheral, options: nil)
    print("here")
 }
}
}

What am I missing here?

Don't know if it helps, but I tried these python scripts outlined in this webpage.

http://blog.kevindoran.co/bluetooth-programming-with-python-3/

They didn't work either, couldn't get python3 bluetooth installed under OS X and although both appeared to run on the Debian linux box. The client fails to connect to the server with the error message "No route to host".

Zoe
  • 27,060
  • 21
  • 118
  • 148
user3069232
  • 8,587
  • 7
  • 46
  • 87
  • 1
    Your device doesn't seem to be advertising any GATT services. See https://stackoverflow.com/questions/25427768/bluez-how-to-set-up-a-gatt-server-from-the-command-line – Paulw11 May 06 '19 at 20:42
  • Sadly tried all the suggestions on the other thread, nothing worked. Odd too that my Mac see this thing? Not on the right track me thinks... – user3069232 May 08 '19 at 18:52
  • So you mean a program using Core Bluetooth on your Mac can see the device? or you can "see" it in Bluetooth settings on the Mac? – Paulw11 May 08 '19 at 21:23
  • Yes, I can see it on my Mac and an iPad. And indeed I am connected too it thru my Mac. – user3069232 May 11 '19 at 08:27
  • How are you connected to it on your Mac? Using the code you have shown here? Or through some other program or method? – Paulw11 May 11 '19 at 08:50
  • I simply used pair on the Mac and/or iOS device. The code I show here doesn't even see, let alone give me a chance to pair with anything... – user3069232 May 11 '19 at 13:07
  • I printed the identity of all the blue tooth devices I see with this code, the address of the ev3dev unit 40-BD-32-3E-56-97 as given by my laptop simply doesn't appear in the "Discovered" list in the console output. – user3069232 May 11 '19 at 18:49
  • 1
    As I said, your device isn't advertising any GATT services, so you won't discover it with the code shown. Core Bluetooth doesn't give you the device MAC address, so even if it was discovered you wouldn't see that value. You don't pair BLE GATT devices through settings to use them with Core Bluetooth. – Paulw11 May 11 '19 at 20:18

0 Answers0