蓝牙 OTA SDK

更新时间:2019-07-11 16:18:43

概述

SDK 提供蓝牙 OTA 业务的 APP 端解决方案,提供了蓝牙设备固件升级的能力。

依赖 SDK 概述
蓝牙 Breeze SDK 是按照规范实现的手机端蓝牙 SDK,方便合作厂商在手机端快速接入蓝牙功能。Breeze SDK 包含的主要功能有:设备发现连接,设备通信,加密传输,大数据传输等。
API 通道 提供 API 通道能力,和基础环境配置信息。

初始化

1.先通过 android 蓝牙SDK 连接上设备,获取 IBreezeDevice 实例;
2.通过 IBreezeDevice 实例,BreezeHelper.getDeviceInfo() 获取deviceinfo.

getDeviceInfo(breezeDevice,new IDeviceInfoCallback(){
  void onDeviceInfo(DeviceInfo info){
    mInfo = info;
};

3.通过 DeviceInfo BreezeHelper.bindBreezeDevice() 绑定到当前用户,获得 iotID.

BreezeHelper.bindBreezeDevice(breezeDevice, mInfo, new BindCallback(){
    void onBindResult(BindResult result, int error){
    if (null == error){
      mIotId = result.iotId;
  }
});

使用说明

先在飞燕后台配置好OTA任务,参加如何配置OTA任务

获取OTA 实例

获取OTA 对象实例,并初始化(注意 不再使用的时候务必释放资源),device 是breeze连接对象

mBusiness = Factory.create(device);
        mBusiness.init();

检查有没有可以更新的固件

检查是否有新更新,mIotId在成功绑定时获取会返回。

mBusiness.inquiryNewVersion(mIotId, new ILinkOTABusiness.IInquiryNewVersionCallback() {
                    @Override
                    public void onResult(boolean needUpgrade, String error, String result) {
                        // 提示用户升级
                    }
                });

开始OTA升级

如果有新的OTA固件可以升级,且用户同意升级,调用下列接口开始升级,升级进度通过IOtaListener 回调。

mBusiness.startUpgrade(iotId, false, ILinkOTABusiness.DEVICE_TYPE_BLE, new ILinkOTABusiness.IOtaListener() {
                @Override
                public void onNotification(int type, ILinkOTABusiness.IOtaError error) {
                    Log.d(TAG, "onNotification type:" + type + " error:" + error);

停止OTA升级

但OTA结束后(失败或成功)或者用户向终止OTA,调用下列接口停止升级

mBusiness.stopUpgrade();

释放OTA资源

最后释放OTA资源,注意,当不需要OTA时,务必释放OTA资源

mBusiness.deInit();

results matching ""

    No results matching ""