【问题标题】:How to use NATIVE BLE DFU library for IONIC 2?如何为 IONIC 2 使用 NATIVE BLE DFU 库?
【发布时间】:2017-03-10 10:00:48
【问题描述】:

我正在使用 IONIC 2 创建 BLE 应用程序。我需要使用 DFU OTA 库来支持用户的固件更新。 Nordic 提供了很好的示例和源代码。

iOS 的 dfu 库:https://github.com/NordicSemiconductor/IOS-DFU-Library

完整项目(iOS):https://github.com/NordicSemiconductor/IOS-nRF-Toolbox

Android 的 dfu 库:https://github.com/NordicSemiconductor/Android-DFU-Library

问题是如何为 IONIC 应用程序实现相同的功能?有没有相同的插件?或者在 IONIC 2 中实现固件更新 OTA 的任何方式?


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

【问题讨论】:

    标签: android ios ionic2


    【解决方案1】:

    很遗憾,没有任何可用的开源插件。您需要创建一个 cordova 插件来包装 ios 和 android SDK。

    以下是开始编写插件的方法: http://cordova.apache.org/docs/en/6.x/guide/hybrid/plugins/index.html

    然后,您可以将插件添加到您的 ionic 应用中,例如: 离子插件添加 ~/path/to/your/awesome/nordicdfu/plugin

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

    【讨论】:

      【解决方案2】:

      这适用于 iOS 。 1) - 将 iOSDFULibarary 添加到项目中。 pod 'iOSDFULibrary' (使用 pod) 2) - 导入库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”的“didDiscover peripheral”委托方法,将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 芯片组设备的固件。

      【讨论】:

        猜你喜欢
        • 2016-12-15
        • 1970-01-01
        • 2018-11-18
        • 2018-02-17
        • 1970-01-01
        • 2018-08-10
        • 1970-01-01
        • 2014-10-21
        • 2020-12-14
        相关资源
        最近更新 更多