首页 > 解决方案 > 连接到 LEGO EV3 上的 ev3dev

问题描述

使用 iOS 12.2 Xcode 10.2.1

希望使用 iOS iPad 连接到这个 [基于 Debian 的 UNIX 机器]。我可以在我的笔记本电脑上看到该设备。正如你在这里看到的。

在此处输入图像描述

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

在此处输入图像描述

我可以登录 ev3dev 并在 shell 中使用 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

但是想写一个可以做到的小app。蓝牙新手。我得到了这段代码,它似乎可以看到除了我想要找到的所有内容。

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”。

标签: swiftpython-3.xbluetoothcore-bluetooth

解决方案


推荐阅读