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

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

初始化

OTA SDK的初始化依赖API通道的初始化。在进行蓝牙设备OTA固件升级时,依赖蓝牙设备的连接绑定,需要使用到蓝牙 SDK(即BreezeSDK)初始化配置和绑定流程。

OTA SDK初始化如下。

#import 
//self.breeze如何得到请参见[蓝牙 SDK]的初始化部分
self.otaBiz = [LKLinkOtaBusiness setupOtaBiz:self.breeze];

使用说明

OTA基本流程是:用户绑定设备,得到一个iotId后上报版本,再进行OTA升级或取消。

其中上报固件版本:开发者在上述蓝牙设备连接、绑定后调用云端提供的上传设备固件版本号即可,上传固件版本号请参见:固件升级服务

  • 开始OTA升级流程
    1. 预检查事件(LKOTANotificationTypeCheck)
    2. 下载升级包事件(LKOTANotificationTypeDownload)
    3. 传输升级包事件(LKOTANotificationTypeTransmit)
    4. 重启升级事(LKOTANotificationTypeReboot)
    5. OTA 结束(LKOTANotificationTypeFinish)
    #import 
    [self.otaBiz startUpgrade:self.iotId alcsOTA:NO  type:LKOTADeviceTypeBle lisener:^(LKOTANotificationType type, NSDictionary *result) {
        if (type == LKOTANotificationTypeCheck) {
            NSError * err = [result objectForKey:@"error"];
            if (err != nil) {
                NSString * descrip = err.localizedDescription;
                [self insertMsgWithColor:@"red" main:@"升级时预检查失败" detail:descrip];
            } else {
                [self insertMsgWithColor:@"blue" main:@"升级时预检查完成" detail:@"成功"];
            }
        } else if (type == LKOTANotificationTypeDownload) {
            NSDictionary * subResult = [result objectForKey:@"result"];
            NSError * err = [result objectForKey:@"error"];
            if (err != nil) {
                NSString * descrip = err.localizedDescription;
                 [self insertMsgWithColor:@"red" main:@"下载OTA包失败" detail:descrip];
            } else {
                int progress = [[subResult valueForKey:@"progress"]intValue];
                [self updateProgressLabel:@"下载OTA包" withProgress:progress];
            }
        } else if (type == LKOTANotificationTypeTransmit) {
            NSDictionary * subResult = [result objectForKey:@"result"];
            NSError * err = [result objectForKey:@"error"];
            if (err != nil) {
                NSString * descrip = err.localizedDescription;
                [self insertMsgWithColor:@"red" main:@"传输OTA包失败" detail:descrip];
            } else {
                int progress = [[subResult valueForKey:@"progress"]intValue];
                [self updateProgressLabel:@"传输OTA包" withProgress:progress];
            }
        } else if (type == LKOTANotificationTypeReboot) {
            NSDictionary * subResult = [result objectForKey:@"result"];
            NSError * err = [result objectForKey:@"error"];
            if (err != nil) {
                NSString * descrip = err.localizedDescription;
                [self insertMsgWithColor:@"red" main:@"重启设备升级失败" detail:descrip];
            } else {
                int progress = [[subResult valueForKey:@"progress"]intValue];
                [self updateProgressLabel:@"重启设备升级" withProgress:progress];
            }
        } else if (type == LKOTANotificationTypeFinish) {
            //NSDictionary * subResult = [result objectForKey:@"result"];
            NSError * err = [result objectForKey:@"error"];
            if (err != nil) {
                NSString * descrip = err.localizedDescription;
                [self insertMsgWithColor:@"red" main:@"设备升级失败" detail:descrip];
            } else {
                [self insertMsgWithColor:@"yellow" main:@"设备升级成功" detail:nil];
            }
        }
    }];
    					
  • 终止 OTA流程

    OTA完成后,必须要通过stopUpgrade停止掉,可以停止正在进行中的OTA过程。

    #import 
    [self.otaBiz stopUpgrade];