'Connecting to ev3dev on a LEGO EV3
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.
And I can see it on my iPhone. And I can pair it with my iPhone.
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".
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


