swift - 连接到 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”。
解决方案
推荐阅读
- google-apps-script - 在整个工作表中查找具有特定值的单元格的功能
- flutter - 更新到 Flutter 1.12.13 后,TextField 提示/输入文本没有居中且没有 prefixIcon
- reactjs - 在反应测验中设置子组件的数组状态并将其传递回父组件时遇到问题
- sql - SQL 问题:重复键值违反唯一约束
- web - 配置 apache2 以使 web2py 特定应用程序响应辅助主机名
- c - 核简单示例中未显示窗口
- python-3.x - 如何从python字典中的键中删除字母
- redis - Redis 快速填满内存,运行 --bigkeys 释放它
- azure - Cosmos DB 分区设计
- regex - 具有可选开头和结尾的 Python 正则表达式