微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CoreBluetooth 可以用作外围设备连接到 Google Home 或 Amazon Echo非蓝牙 LE 设备吗?

如何解决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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?