簡體   English   中英

如何使用 IONIC 2 的 NATIVE BLE DFU 庫?

[英]How to use NATIVE BLE DFU library for IONIC 2?

我正在使用 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 任何人都可以解釋如何在應用程序中使用它,因為我可以將它添加到我的 ionic 應用程序中,但有關如何導入和使用方法的指南不可用。

不幸的是,沒有任何可用的開源插件。 您需要創建一個cordova 插件來包裝ios 和android SDK。

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

然后,您可以將您的插件添加到您的 ionic 應用程序中,例如: ionic plugin add ~/path/to/your/awesome/nordicdfu/plugin

您可能會發現 Don Coleman 出色的 BLE 插件很有幫助: https : //github.com/don/cordova-plugin-ble-central

這適用於 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' 的“didDiscoverperipheral”委托方法,將 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 芯片組設備的固件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM