Last Updated on : 2024-06-26 10:09:25download
Commercial Lighting Device Pairing UI BizBundle is used to implement pairing guidance and smart device activation. It applies to multiple types of smart devices, such as Wi-Fi devices, Zigbee devices, Bluetooth devices, and devices that support QR code scanning like GPRS & NB-IoT devices. The UI BizBundle provides the service logic and UI encapsulation to guide pairing and activate smart devices over different protocols.
Wi-Fi smart devices can be paired and connected to cloud services in two modes: Wi-Fi Easy Connect (EZ) mode and access point (AP) or hotspot mode. IP cameras (IPCs) can be paired after QR code scanning.
Term | Description |
---|---|
Wi-Fi Easy Connect | Also known as the EZ mode. This pairing mode is implemented through the following steps:
|
AP mode | Also known as the hotspot mode. A mobile phone acts as a station (STA) and connects to the hotspot of a smart device. Then, both devices are paired to establish a socket connection between them and exchange data through the specified ports. |
IPC pairing in QR code mode | An IPC scans the QR code on the app to get the pairing data. |
Zigbee gateways and sub-devices can be paired.
Term | Description |
---|---|
Zigbee gateway | The device that integrates the coordinator with Wi-Fi features on a Zigbee network. The gateway is responsible to formulate the Zigbee network and store data. |
Zigbee sub-device | A router or an end device on a Zigbee network. Each Zigbee sub-device is responsible to forward data, or respond to control commands. |
Tuya provides the following Bluetooth solutions.
Term | Description |
---|---|
Bluetooth Low Energy (LE) | A peer-to-peer connection is created between a Bluetooth or Bluetooth LE device and a mobile phone. |
Bluetooth mesh | Enable many-to-many (m:m) device communications over a mesh network released by Bluetooth Special Interest Group (SIG). |
Tuya mesh | Tuya’s proprietary technology that enables Bluetooth devices to communicate over a mesh network. |
Combo devices | The devices that support Bluetooth and Wi-Fi combo can be paired over either Bluetooth or Wi-Fi. |
A smart device that supports this pairing mode is connected to Tuya’s cloud services immediately after power on. The app can be used to scan the QR code on the device to implement cloud-based device activation and binding. The QR code must comply with Tuya’s QR code rules. For more information, contact Tuya’s account manager.
Term | Description |
---|---|
GPRS devices | Smart devices that apply GPRS technologies to connect to the network and access cloud services. |
NB-IoT devices | Smart devices that apply NB-IoT technologies. |
Tuya provides efficient pairing features on top of Tuya’s generic pairing technologies for smart devices.
Add the components of the Device Pairing UI BizBundle to the Podfile
and run the command pod update
.
source "https://github.com/TuyaInc/TuyaPublicSpecs.git"
source 'https://cdn.cocoapods.org/'
target 'your_target_name' do
# Adds the Device Pairing UI BizBundle.
pod 'ThingCommercialLightingActivatorBizBundle', '~> 2.8.1.1'
end
To implement pairing Wi-Fi devices, you must get the name of the current Wi-Fi network after location is enabled in your project. To achieve this purpose, add the following permission declaration to info.plist
of your project, create the CLLocationManager
sample, and then call the method requestWhenInUseAuthorization
.
NSLocationAlwaysAndWhenInUseUsageDescription
NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription
To implement QR code scanning, the permissions on access to cameras of mobile phones are required. You can add the following permission declaration in info.plist
:
NSCameraUsageDescription
The Device Pairing UI BizBundle supports device pairing over protocols such as Wi-Fi and Bluetooth. Bluetooth pairing is optional.
If your app does not require Bluetooth pairing, you only need to set the needBle
property in thing_custom_config.json
to false
.
If your app requires Bluetooth pairing, you must first add the following Bluetooth permission declaration to info.plist
of your project, set the needBle
property in thing_custom_config.json
to true
, and then add the following dependencies to your project:
System permissions
NSBluetoothAlwaysUsageDescription
NSBluetoothPeripheralUsageDescription
Configuration items
{
"config": {
"appId": 123,
"thingAppKey": "xxxxxxxxxxxx",
"appScheme": "thingSmart",
"hotspotPrefixs": ["SmartLife"],
"needBle": true // Sets the value to true to support pairing Bluetooth devices.
},
"colors":{
"themeColor": "#FF5A28",
}
}
Dependencies
pod 'ThingBLEInterfaceImpl', '0.3.0-lampbizbundle-1.11.5.1.3'
pod 'ThingBLEMeshInterfaceImpl', ' 0.0.9-lampbizbundle-1.11.5.1.3'
pod 'ThingSmartBLEKit'
pod 'ThingSmartBLEMeshKit'
pod 'ThingBLELampManager', '1.12.0'
By default, the hotspot name of each Tuya-enabled device is prefixed with SmartLife
.
If the hotspot prefix of the current smart device is modified, you must set the hotspotPrefixs
property in thing_custom_config.json
to the current hotspot prefix.
{
"config": {
"appId": 123,
"thingAppKey": "xxxxxxxxxxxx",
"appScheme": "thingSmart",
"hotspotPrefixs": ["SL"], // The supported hotspot prefix is set to SL.
"needBle": true
},
"colors":{
"themeColor": "#FF5A28",
}
}
The UI BizBundle relies on the implementation of the protocol ThingActivatorProtocol
to provide services. You can view the ThingActivatorProtocol.h
file in the ThingModuleServices
component.
#ifndef ThingActivatorProtocol_h
#define ThingActivatorProtocol_h
typedef NS_ENUM(NSUInteger, ThingActivatorCompletionNode) {
ThingActivatorCompletionNodeNormal
};
@class ThingSmartHome;
@protocol ThingActivatorProtocol <NSObject>
/**
* Start config
* Goto device config list view
*/
- (void)gotoCategoryViewController;
/**
* Obtain device information after each device connection
* @param node completion node, default ThingActivatorCompletionNodeNormal
* @param custionJump default false, set true for process not need to jump to de device panel
*/
- (void)activatorCompletion:(ThingActivatorCompletionNode)node customJump:(BOOL)customJump completionBlock:(void (^)(NSArray * _Nullable deviceList))callback;
@end
#endif /* ThingActivatorProtocol_h */
To customize the returned list of categories or products for pairing, implement the protocol methods provided by ThingActivatorExternalExtensionProtocol
.
ThingActivatorExternalExtensionProtocol
/**
* Back action form category View Controller
* Need to implement when additional operations are needed
*/
- (BOOL)categoryViewControllerCustomBackAction;
The UI BizBundle depends on the method provided by the protocol ThingLampProjectDataProtocol
to get the current home details required for pairing. To call the UI BizBundle, you must implement this dependent protocol.
/**
Clears the current project and its cached data.
*/
- (void)clearCurrentProject;
/**
To use this API method to get the current project data, you must use 'updateCurrentProjectId:' API of the protocol when the current project ID is updated.
Returns the current project data. If no project is created, nil is returned.
@return ThingSmartProject
*/
- (ThingLightingProject *)getCurrentProject;
/**
Updates the current project ID and writes it to the cached data of GroupUserDefault.
@param projectId The project ID.
*/
- (void)updateCurrentProjectId:(long long)projectId;
/// Returns the current project ID.
- (long long)currentProjectId;
Before the call of any API method, make sure that the user has logged in to the app.
Before the UI BizBundle is used, the getCurrentProject
and currentProjectId
methods provided by the protocol ThingLampProjectDataProtocol
must be implemented first.
Example for Objective-C
#import <ThingSmartBizCore/ThingSmartBizCore.h>
#import <ThingModuleServices/ThingLampProjectDataProtocol.h>
- (void)initCurrentProject {
// Registers the protocols to be implemented.
[[ThingSmartBizCore sharedInstance] registerService:@protocol(ThingLampProjectDataProtocol) withInstance:self];
}
// Implements the protocol method.
- (ThingLightingProject *)getCurrentProject {
ThingLightingProject *project = [ThingLightingProject projectWithProjectId:@"Current project ID"];
return project;
}
- (long long)currentProjectId {
return 111;
}
Example for Swift:
import ThingCommercialLightingKit
class ThingActivatorTest: NSObject,ThingLampProjectDataProtocol{
func test() {
ThingSmartBizCore.sharedInstance().registerService(ThingLampProjectDataProtocol.self, withInstance: self)
}
func getCurrentProject() -> ThingLightingProject! {
let project = ThingLightingProject.init(projectId: 111)
return project
}
func currentProjectId() -> CLongLong {
return 111
}
}
Example for Objective-C
#import <ThingSmartBizCore/ThingSmartBizCore.h>
#import <ThingModuleServices/ThingActivatorProtocol.h>
- (void)gotoDeviceConfig {
id<ThingActivatorProtocol> impl = [[ThingSmartBizCore sharedInstance] serviceOfProtocol:@protocol(ThingActivatorProtocol)];
[impl gotoCategoryViewController];
// Returns the pairing result.
[impl activatorCompletion:ThingActivatorCompletionNodeNormal customJump:NO completionBlock:^(NSArray * _Nullable deviceList) {
NSLog(@"deviceList: %@",deviceList);
}];
}
Example for Swift:
let impl = ThingSmartBizCore.sharedInstance().service(of: ThingActivatorProtocol.self) as? ThingActivatorProtocol
impl?.gotoCategoryViewController()
impl?.activatorCompletion(ThingActivatorCompletionNodeNormal, customJump: false, completionBlock: { (evIdList:[Any]?) in
print(devIdList ?? [])
})
Example for Objective-C
#import <ThingSmartBizCore/ThingSmartBizCore.h>
#import <ThingModuleServices/ThingActivatorExternalExtensionProtocol.h>
- (void)initCurrentProject {
// Registers the protocols to be implemented.
[[ThingSmartBizCore sharedInstance] registerService:@protocol(ThingActivatorExternalExtensionProtocol) withInstance:self];
}
// Implements the protocol method.
- (BOOL)categoryViewControllerCustomBackAction {
[self.navigationController popToRootViewControllerAnimated:YES];
return YES;
}
Example for Swift:
class ThingActivatorTest: NSObject,ThingActivatorExternalExtensionProtocol{
func test() {
ThingSmartBizCore.sharedInstance().registerService(ThingActivatorExternalExtensionProtocol.self, withInstance: self)
}
func categoryViewControllerCustomBackAction() -> Bool {
self.navigationController?.popToRootViewController(animated: true)
return true;
}
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback