如何解决CoreBluetooth 可以用作外围设备连接到 Google Home 或 Amazon Echo非蓝牙 LE 设备吗?
我使用 iPhone 作为我的中心。是否可以使用 CoreBluetooth 连接到 Google Home、Amazon Echo 或任何非蓝牙 LE 设备作为外围设备以读取所述外围设备的 RSSI?我不需要连接来访问任何服务;我正在做一个研究项目,只需要能够使用 iPhone 作为 RSSI 值的传感器,可以这么说。现在我有这个代码,它扫描并发现不分青红皂白地做广告的外围设备。
//
// BLEManager.swift
// RSSIappSwiftUI
//
// Created by bee-mcc on 3/30/21.
//
import Foundation
import CoreBluetooth
//will hold the information needed about Our peripherals
struct Peripheral: Identifiable {
let id: Int
let name: String
let RSSi: Int
}
class BLEManager: NSObject,ObservableObject,CBCentralManagerDelegate{
//the object that represents the Bluetooth controls of the iphone
var myCentral: CBCentralManager!
@Published var peripherals = [Peripheral]()
//var letting us kNow if myCentral has bluetooth switched on
@Published var isSwitchedOn = false
override init() {
super.init()
myCentral = CBCentralManager(delegate: self,queue: nil)
myCentral.delegate = self
}
//this is called whenever the central manager updates its state
func centralManagerDidUpdateState(_ central: CBCentralManager) {
if central.state == .poweredOn {
isSwitchedOn = true
}
else {
isSwitchedOn = false
}
}
//this is called any time a central manager discovers any peripherals
func centralManager(_ central: CBCentralManager,diddiscover peripheral: CBPeripheral,advertisementData: [String : Any],RSSi RSSI: NSNumber) {
var peripheralName: String!
if let name = advertisementData[CBAdvertisementDataLocalNameKey] as? String {
peripheralName = name
}
else {
peripheralName = "UnkNown"
}
let newPeripheral = Peripheral(id: peripherals.count,name: peripheralName,RSSi: RSSI.intValue)
print(newPeripheral)
peripherals.append(newPeripheral)
}
//buttons to start and stop scanning
func startScanning() {
print("startScanning")
myCentral.scanForperipherals(withServices: nil,options: nil)
}
func stopScanning() {
print("stopScanning")
myCentral.stopScan()
}
}
我希望能够通过在某处代码中指定蓝牙设备的 MAC 地址来以某种方式连接到蓝牙设备,然后使用该 MAC 地址的 RSSI 收集设备与 iPhone 相关的信息。
提前致谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。