在LEGO EV3上连接到ev3dev

时间:2019-05-06 15:32:37

标签: swift python-3.x bluetooth core-bluetooth discover

使用iOS 12.2 Xcode 10.2.1

希望使用iOS iPad连接到此[基于Debian的UNIX盒子]。我可以在笔记本电脑上看到该设备。如您所见。

enter image description here

我可以在iPhone上看到它。而且我可以将它与iPhone配对。

enter image description here

我可以登录ev3dev并在外壳中使用bluetoothctl命令向我展示服务的详细信息。

[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

但是要编写一个可以做到的小应用程序。蓝牙新手。我得到了这段代码,除了我要查找的内容外,似乎可以看到所有内容。

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")
 }
}
}

我在这里想念什么?

不知道是否有帮助,但是我尝试了此网页中概述的这些python脚本。

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

它们也不起作用,无法在OS X下安装python3蓝牙,尽管它们似乎都在Debian linux机器上运行。客户端无法通过错误消息“ No route to host”连接到服务器。

0 个答案:

没有答案