如何将本机BLE DFU库用于离子2



我正在使用离子2创建ble应用。我需要使用dfu ota库来支持用户的固件更新。北欧提供了很好的示例和源代码。

dfu lib for iOS:https://github.com/nordicspeamonductor/ios-dfu-library

完整项目(ios):https://github.com/nordicsemicdonductor/ios-nrf-toolbox

dfu lib for Android:https://github.com/nordicsemicdonductor/android-dfu-library

问题是如何为离子应用实现相同的问题?是否有相同的插件?或在Ionic 2中实现固件更新OTA的任何方法?


更新问题:我找到了这个库:https://www.npmjs.com/package/cordova-plugin-nordic-dfu。任何人都可以解释如何在应用程序中使用它,因为我能够在我的离子应用中添加它,但是有关如何导入和使用方法的指南。

不幸的是,没有任何开源插件可用。您将需要创建一个Cordova插件来包装iOS和Android SDK。

这是您可以开始编写插件的方式:http://cordova.apache.org/docs/en/6.x/guide/hhybrid/plugins/index.html

然后,您将插件添加到您的离子应用中,例如:离子插件添加〜/path/to/your/avesome/nordicdfu/plugin

您可能会发现Don Coleman的出色BLE插件有帮助:https://github.com/don/cordova-plugin-ble-central

为iOS。 1) - 将iosdfulibarary添加到项目中。 吊舱" iosdfulrary"(使用POD) 2) - 导入Libarary import iOSDFULibrary

3) - 声明以下常数。

  static var legacyDfuServiceUUID  = CBUUID(string: "00001530-1212-EFDE-1523-785FEABCD123")
  static var secureDfuServiceUUID  = CBUUID(string: "FE59")
  static var deviceInfoServiceUUID = CBUUID(string: "180A")

4) - 扫描具有特定服务的蓝牙设备。然后设备将进入DFU模式。

 func startDiscovery() {
       if !scanningStarted {
           scanningStarted = true
           print("Start discovery")
           // By default the scanner shows only devices advertising with one of those Service UUIDs:
           centralManager!.delegate = self
           centralManager!.scanForPeripherals(
               withServices: [
                   ImpulseUpdateFirmwareVC.legacyDfuServiceUUID,
                   ImpulseUpdateFirmwareVC.secureDfuServiceUUID,
                   ImpulseUpdateFirmwareVC.deviceInfoServiceUUID
                   /*, customServiceUUID*/],
               options: [CBCentralManagerScanOptionAllowDuplicatesKey: true])
       }
   }
func centralManagerDidUpdateState(_ central: CBCentralManager) {
    switch central.state {
    case .unsupported:
        print("BLe Unsupported")
        break
    case .unauthorized:
        print("BLe unauthorized")
        break
    case .poweredOff:
        let alertMessgesInst = AlertMessages.sharedInstance
        let alert = UIAlertController(title: alertMessgesInst.actofit_Title, message: alertMessgesInst.trun_On_blueTooth, preferredStyle: UIAlertController.Style.alert)
        let okAction = UIAlertAction(title: Constants.General.OK, style: .cancel, handler: nil)
        alert.addAction(okAction)
        self.present(alert, animated: true, completion: nil)
        DispatchQueue.main.async {
            self.activityIndicator.stopAnimating()
        }
        break
    case .poweredOn:
        startDiscovery()
        break
    case .unknown:
        print("BLe unknown")
        break
    default:
        break
    }

}

5-进入'cbcentralmanager'的" diddisdiscover"代表方法,将DFU库称为。

func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
    let name = advertisementData[CBAdvertisementDataLocalNameKey] as! String?
    // Ignore dupliactes.
    // They will not be reported in a single scan, as we scan without CBCentralManagerScanOptionAllowDuplicatesKey flag,
    // but after returning from DFU view another scan will be started.
    centralManager.stopScan()
   let selectedFirmware = DFUFirmware(urlToZipFile: zipFilePathULR!, type: .application)
           let initiator = DFUServiceInitiator().with(firmware: selectedFirmware!)
           initiator.logger = self // - to get log info
           initiator.delegate = self // - to be informed about current state and errors
           initiator.progressDelegate = self // - to show progress bar
           // initiator.peripheralSelector = ... // the default selector is used
           let controller = initiator.start(target: peripheral)

}

这将更新RNF52芯片组设备的固件。

相关内容

  • 没有找到相关文章

最新更新