NB-IoT Device Pairing

Last Updated on : 2024-06-26 10:09:44download

This topic describes the mode of pairing a narrowband Internet of Things (NB-IoT) device based on the low-power wide-area network (LPWAN) radio technology. NB-IoT connects smart devices more simply and efficiently on already established mobile networks. Smart Life App SDK provides the capabilities to pair NB-IoT devices. Users scan the QR code of a target device to get the device ID used for pairing.

Query the device ID

parseQRCode is a method to parse the device’s QR code. The URL and device UUID can be extracted from the QR code.

Parameter description

  • content: The QR code content.
  • success: The success callback, returning the device token.
  • failure: The failure callback.

Example

Objective-C:

[ThingSmartActivator parseQRCode:@"yourQRCodeContent" success:^(id result) {
    NSDictionary *qrCodeDict = (NSDictionary *)result;
    NSLog(@"Action Name: %@", [qrCodeDict objectForKey:@"actionName"]);
    NSLog(@"Action Data: %@", [qrCodeDict objectForKey:@"actionData"]);
} failure:^(NSError *error) {
    NSLog(@"Error: %@", error.localizedDescription);
}];

Swift:

ThingSmartActivator.parseQRCode("yourQRCodeContent", success: { result in
    guard let qrCodeDict = result as? [String: Any] else {
        return
    }
    print("Action Name: \(qrCodeDict["actionName"] ?? "")")
    print("Action Data: \(qrCodeDict["actionData"] ?? "")")
}) { error in
    print("Error: \(error.localizedDescription)")
}

Device pairing

ThingSmartNBDeviceActivator class

The ThingSmartNBDeviceActivator class is used to bind an NB-IoT device with the cloud service.

Method

- (void)requestNBDeviceBindWithParam:(ThingSmartNBDeviceBindRequestData *)param success:(void(^)(ThingSmartNBDeviceBindResponseData *result))success failure:(ThingFailureError)failure;

This method binds an NB-IoT device with the cloud service.

Parameters

  • param: The ThingSmartNBDeviceBindRequestData object for the binding request parameters.
  • success: The success callback, returning the ThingSmartNBDeviceBindResponseData object.
  • failure: The failure callback, returning the error message.

ThingSmartNBDeviceBindRequestData class

ThingSmartNBDeviceBindRequestData class is used to create the request parameters for device binding.

Property

  • hid: The device token, in string. Its value comes from the method parseQRCode.
  • timeZone: The time zone of the device, in string.
  • gid: The space ID of the device, in long integer.

Example

Objective-C:

ThingSmartNBDeviceBindRequestData *requestData = [[ThingSmartNBDeviceBindRequestData alloc] init];
requestData.hid = @"your_device_token";
requestData.timeZone = @"your_device_time_zone";
requestData.gid = your_space_id;

ThingSmartNBDeviceActivator *activator = [[ThingSmartNBDeviceActivator alloc] init];
[activator requestNBDeviceBindWithParam:requestData success:^(ThingSmartNBDeviceBindResponseData *result) {
    // Handle success
    NSLog(@"Device bind success: %@", result);
} failure:^(NSError *error){
    // Handle failure
    NSLog(@"Device bind failure: %@", error);
}];

Swift:

let requestData = ThingSmartNBDeviceBindRequestData()
requestData.hid = "your_device_token"
requestData.timeZone = "your_device_time_zone"
requestData.gid = your_space_id

let activator = ThingSmartNBDeviceActivator()
activator.requestNBDeviceBind(withParam: requestData, success: { (result) in
    // Handle success
    print("Device bind success: \(result)")
}) { (error) in
    // Handle failure
    print("Device bind failure: \(error)")
}