This SDK provides an in-app solution for Bluetooth Over-the-Air (OTA) services. You can use this SDK to upgrade the firmware of Bluetooth devices.
Dependent SDKs | Overview |
Bluetooth SDK | Breeze SDK is a mobile Bluetooth SDK that complies with standard specifications. It helps partners quickly integrate Bluetooth features into their mobile apps. Key features of Breeze SDK include device discovery and connection, device communication, encrypted transmission, and large data transmission. |
Log SDK | A basic dependent SDK. It provides unified client-side log printing, log level control, and modular log isolation. |
API Channel SDK | Provides API channel capabilities and basic environment configuration information. |
Initialization
The OTA SDK initialization depends on the API channel initialization. To perform an OTA firmware update for a Bluetooth device, you must connect and attach the device. This requires the initialization, configuration, and attachment procedures of the Bluetooth SDK (Breeze SDK).
Initialize the OTA SDK as follows.
#import
// To obtain self.breeze, see the Initialization section of the Bluetooth SDK documentation.
self.otaBiz = [LKLinkOtaBusiness setupOtaBiz:self.breeze];Instructions
The basic OTA flow is as follows: a user attaches a device, obtains an iotId, reports the current firmware version, and then performs or cancels an OTA update.
To report the firmware version, the developer must call the cloud-provided API to upload the device firmware version number after the Bluetooth device is connected and attached. For more information about uploading the firmware version number, see Report version number.
Start the OTA update flow
Precheck event (LKOTANotificationTypeCheck)
Download upgrade package event (LKOTANotificationTypeDownload)
Transmit upgrade package event (LKOTANotificationTypeTransmit)
Restart and upgrade event (LKOTANotificationTypeReboot)
OTA finish event (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:@"Upgrade precheck failed" detail:descrip]; } else { [self insertMsgWithColor:@"blue" main:@"Upgrade precheck completed" detail:@"Success"]; } } 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:@"Failed to download OTA package" detail:descrip]; } else { int progress = [[subResult valueForKey:@"progress"]intValue]; [self updateProgressLabel:@"Downloading OTA package" 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:@"Failed to transmit OTA package" detail:descrip]; } else { int progress = [[subResult valueForKey:@"progress"]intValue]; [self updateProgressLabel:@"Transmitting OTA package" 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:@"Failed to restart and upgrade the device" detail:descrip]; } else { int progress = [[subResult valueForKey:@"progress"]intValue]; [self updateProgressLabel:@"Restarting and upgrading device" 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:@"Device upgrade failed" detail:descrip]; } else { [self insertMsgWithColor:@"yellow" main:@"Device upgrade successful" detail:nil]; } } }];Stop the OTA flow
After the OTA update is complete, you must call
stopUpgradeto stop the process. This call can also stop an OTA process that is in progress.#import [self.otaBiz stopUpgrade];