Bluetooth-assisted network provisioning sends Wi-Fi hot spot information from a mobile app to a device over Bluetooth. It also returns network provisioning error messages to the user to help with troubleshooting. This document describes how to develop this feature for your iOS app to provision your device and enable its voice capabilities.
Prerequisites
You have completed product development in the console and device-side development for Bluetooth-assisted network provisioning. For more information, see Device-side development.
- Create your app. For more information, see Create an app.
- Obtain the SDK using one of the following methods.
- Download and integrate the SDK from the console. You must select the network provisioning package. For more information, see Download and integrate the SDK.
- Update the code in your app project as follows.
# The minimum supported SDK version is iOS 9.0 platform :ios, '9.0' # Official GitHub pod source source 'https://github.com/CocoaPods/Specs.git' # Alibaba Cloud pod source source 'https://github.com/aliyun/aliyun-specs.git' # Replace "IMSDemoApp" with the target name of your app target "IMSDemoApp" do ... # Update the network provisioning SDK dependency to pod 'IMSDeviceCenter', '1.15.0' # Bluetooth SDK dependency pod 'IMSBreezeSDK', '1.8.1' ... end
- Initialize the SDK. Because Bluetooth-assisted network provisioning interacts with the cloud, you must initialize the SDK before you call the network provisioning SDK. For more information, see SDK initialization. For an example of how to use the API Gateway interface, see API Channel SDK.
- (Optional) Develop the device discovery feature.
The device discovery interface lets you discover nearby devices that are waiting to be provisioned using Bluetooth-assisted provisioning, zero-touch provisioning, or device hot spot provisioning. It also discovers devices that are already provisioned on the local area network (LAN). This section describes Bluetooth-assisted network provisioning. The sample code discovers only devices that are waiting for this type of provisioning.
Note ThesubTypebroadcast by the Wi-Fi & BLE Combo Bluetooth module must be set to 2. This value indicates a Bluetooth and Wi-Fi dual-mode device. This ensures the device can be discovered through Bluetooth-assisted network provisioning.// Import the header file #import <IMLDeviceCenter/IMLDeviceCenter.h> // Local discovery entry point [[IMLLocalDeviceMgr sharedMgr] startDiscovery:^(NSArray *devices, NSError *err) { // devices is an array of IMLCandDeviceModel objects. // You can distinguish the network provisioning type of the device based on the devType in IMLCandDeviceModel. // A devType of @"ble_subtype_2" represents a Bluetooth-assisted network provisioning device. }]; - Develop the device provisioning feature.
// Import the header file #import <IMLDeviceCenter/IMLDeviceCenter.h> /** * Step 1: Set the information for the device to be added. * This includes the device's productKey and productId. * You can get the provisioning information from the discovery interface described above, or you can scan a QR code to get the required information and start provisioning. * If you are not using the discovery interface for Bluetooth-assisted provisioning, ensure that a combo device is in provisioning mode and is discoverable. */ // Create the information for the device to be provisioned. IMLCandDeviceModel *model = [[IMLCandDeviceModel alloc] init]; // The productKey registered in the business console. This cannot be empty. model.productKey = @"xxxx"; // The product ID. This is required for Bluetooth-assisted network provisioning. model.productId = @"xxx"; // Set the mode to Bluetooth-assisted network provisioning. model.linkType = ForceAliLinkTypeBLE; // Annotate that the device supports voice capabilities. model.isInside = YES; // model.enableGlobalCloudToken = YES; // Set the basic information for the device to be added. [kLkAddDevBiz setDevice:model]; /** * Step 2: Start network provisioning. * Set the network provisioning information callback. */ // Here, self is the notifier listener callback object (delegate) for the provisioning process. [kLkAddDevBiz startAddDevice:self]; - (void)notifyPrecheck:(BOOL)success withError:(NSError *)err { NSLog(@"notifyPrecheck callback err : %@", err); } // User guide page (One-click provisioning and hot spot provisioning will have related callbacks to guide the user through the required operations). - (void)notifyProvisionPrepare:(LKPUserGuideCode)guideCode { NSLog(@"notifyProvisionPrepare callback guide code : %ld", guideCode); if(guideCode == LKPGuideCodeOnlyInputPwd){ // Guide for entering Wi-Fi and password information. Proceed to Step 3. /** * Step 3: Set the Wi-Fi information. * Set the SSID, password, and provisioning timeout for the Wi-Fi network that the device needs to connect to. */ // The SSID of the Wi-Fi network for the device to connect to, usually the current Wi-Fi network. NSString *ssid = @"example ssid"; // The password of the Wi-Fi network for the device to connect to, usually the current Wi-Fi network. NSString *password = @"1qaz@WSX"; NSInteger timeout = 60; // Unit: seconds (s). The minimum timeout is 60s. [kLkAddDevBiz toggleProvision:ssid pwd:password timeout:timeout]; } } -(void)notifyProvisioning { NSLog(@"notifyProvisioning callback (Provisioning in progress...) "); } /** Notify the upper-layer UI: Callback for the network provisioning result. @param candDeviceModel Returns the device information from the provisioning result. This is nil if provisioning fails. @param provisionError The error message. */ - (void)notifyProvisionResult:(IMLCandDeviceModel *)candDeviceModel withProvisionError:(NSError *)provisionError { NSLog(@"Provisioning result: %@",candDeviceModel); /** * Step 4: Receive the provisioning result. */ if(candDeviceModel != nil){ NSLog(@"Provisioning successful: %@",candDeviceModel); } else{ NSLog(@"Provisioning failed, error message: %@", provisionError); } // Provisioning result: If the successful result includes a token, use that token for binding. }