Mesh Network Management

Last Updated on : 2024-04-01 07:35:50download

This topic describes how to manage a mesh network.

Concepts

Mesh network

The mesh network mentioned in the Commercial Lighting App SDK documentation refers to Bluetooth SIG’s mesh network technology. The SDK currently does not support any private mesh protocols.
It is recommended to limit the number of Bluetooth mesh devices in a single mesh network to 300, with no restrictions on the number of non-Bluetooth mesh devices.

Mesh network mode

  • Single mesh network mode

    • When a project is created, a mesh network will automatically be generated and bound with all areas within the project.
    • For projects in this mesh network mode, do not create or delete a mesh network.
  • Multi-mesh network mode

    • Users must manually create and bind a mesh network with the area in the project. Otherwise, they cannot pair a Bluetooth mesh device in an area without an associated mesh network.
    • An area can be bound with only one mesh network. A mesh network can be bound with multiple nodes in an area simultaneously.
    • Mesh devices cannot be transferred between different areas. To transfer devices between areas, bind the target areas with the same mesh network.

Device pairing

Device pairing is not supported at the project root node. Pair a device under the target area node. The homeId passed into the API during pairing should be the gid of the current area.

The Commercial Lighting App SDK v2.8.1 or later supports creating a project in single mesh network mode or multi-mesh network mode. Operations such as pairing, grouping, and scene should be performed in the specific area node.

Management

Get mesh network information

Get information about the mesh network associated with the area.

  • For projects in single mesh network mode, all areas are automatically bound with a mesh network. Theoretically, there should be no area with no associated mesh network.
  • For projects in multi-mesh network mode, the associated mesh network might be empty. In this case, users need to manually bind the mesh network.

Sample code

ThingLightingArea *area = [ThingLightingArea areaWithAreaId:areaId projectId:projectId];
long long meshId = area.areaModel.meshId;

Single mesh network mode

In a project, only one mesh network will automatically be generated and bound with all area nodes within the project.

Initialize

Initializes a Bluetooth mesh network and registers a listener for status changes from the cloud. This API method is called when users switch between or initialize Bluetooth mesh networks.

API description

+ (ThingSmartSIGMeshManager * _Nullable)initSIGMeshManager:(ThingSmartBleMeshModel *)meshModel
                                                      ttl:(NSInteger)ttl
                                                  nodeIds:(NSArray<NSData *> * _Nullable)nodeIds;

Sample code

    ThingSmartBleMeshModel *meshModel = [[ThingLightingCacheService sharedInstance] getMeshModelWithId:meshId];
    ThingSmartSIGMeshManager *manager = [ThingSmartBleMesh initSIGMeshManager:meshModel ttl:0 nodeIds:@[]];

Connect to or disconnect from a Bluetooth mesh sub-device

ThingSmartSIGMeshManager provides API methods to start a connection, close a connection, start scanning, and stop scanning.

Sample code

Scan for and connect to a Bluetooth mesh sub-device.

ThingSmartBleMeshModel *meshModel = [[ThingLightingCacheService sharedInstance] getMeshModelWithId:meshId];
ThingSmartSIGMeshManager *manager = [ThingSmartBleMesh initSIGMeshManager:meshModel ttl:0 nodeIds:@[]];
[manager startSearch];

Disconnect from the Bluetooth mesh sub-device and stop scanning.

ThingSmartBleMeshModel *meshModel = [[ThingLightingCacheService sharedInstance] getMeshModelWithId:meshId];
ThingSmartSIGMeshManager *manager = [ThingSmartBleMesh initSIGMeshManager:meshModel ttl:0 nodeIds:@[]];
[manager offlineSIGMeshNetwork];
[manager stopSerachDevice];

The background scanning will consume resources. You can start and stop scanning to control the background scanning.

  • startSearch: After a connection is started, the app will continuously scan for devices in the background until it successfully connects to one.
  • After a Bluetooth mesh network is connected, invoking startSearch and stopSerachDevice will not work.

Multi-mesh network mode

A project can have one or more mesh networks. A single mesh network can be bound with one or more areas simultaneously.

Create mesh network

Create a mesh network and specify its name.

API description

- (void)createMeshWithName:(NSString *)name
                   success:(nullable ThingSuccessID)success
                   failure:(nullable void(^)(NSError *error))failure;

Sample code

    ThingLightingProject *project = [ThingLightingProject projectWithProjectId:projectId];
    [project createMeshWithName:self.meshNameTextField.text success:^(id result) {
    } failure:^(NSError * _Nonnull error) {
    }];

Delete mesh network

A mesh network can be deleted only when it has no associated Bluetooth mesh device and area.

API description

- (void)deleteMeshWithMeshId:(NSString *)meshId
                     success:(nullable ThingSuccessID)success
                     failure:(nullable void(^)(NSError *error))failure;

Sample code

[currentProject deleteMeshWithMeshId:self.meshModel.meshId success:^(id result) {

} failure:^(NSError * _Nonnull error) {

}];

Bind area with mesh network

Bind one or more areas with one mesh network.

API description

- (void)bindMeshAndAreaWithMeshId:(NSString *)meshId
                           areaId:(long long)areaId
                          success:(nullable ThingSuccessID)success
                          failure:(nullable void(^)(NSError *error))failure

Sample code

[currentProject bindMeshAndAreaWithMeshId:self.meshModel.meshId
                                            areaId:areaModel.areaId
                                            success:^(id result) {

} failure:^(NSError * _Nonnull error) {

}];

Unbind area from mesh network

Unbind one or more areas from a mesh network.

API description

- (void)unbindMeshAndAreaWithMeshId:(NSString *)meshId
                             areaId:(long long)areaId
                            success:(nullable ThingSuccessID)success
                            failure:(nullable void(^)(NSError *error))failure;

Sample code

[currentProject unbindMeshAndAreaWithMeshId:self.meshModel.meshId
                                                areaId:areaModel.areaId
                                            success:^(id result) {

} failure:^(NSError * _Nonnull error) {

}];

Initialize a mesh network

Initialize a specified Bluetooth mesh network.

API description

+ (ThingSmartSIGMeshManager * _Nullable)initSIGMeshManager:(ThingSmartBleMeshModel *)meshModel
                                                      ttl:(NSInteger)ttl
                                                  nodeIds:(NSArray<NSData *> * _Nullable)nodeIds;

Sample code

ThingSmartBleMeshModel *meshModel = [[ThingLightingCacheService sharedInstance] getMeshModelWithId:meshId];
ThingSmartSIGMeshManager *manager = [ThingSmartBleMesh initSIGMeshManager:meshModel ttl:0 nodeIds:@[]];

Connect to mesh network

No more than three mesh networks can be connected at the same time.

API description

- (void)startSearch;

Sample code

ThingSmartBleMeshModel *meshModel = [[ThingLightingCacheService sharedInstance] getMeshModelWithId:meshId];
ThingSmartSIGMeshManager *manager = [ThingSmartBleMesh initSIGMeshManager:meshModel ttl:0 nodeIds:@[]];
[manager startSearch];

Disconnect from mesh network

Disconnect from a specified mesh network.

API description

- (void)offlineSIGMeshNetwork;

Sample code

ThingSmartSIGMeshManager *manager = [[impl getCurrentProject] currentSigMeshManager];
[manager offlineSIGMeshNetwork];

Query a list of areas bound with mesh network

Based on meshId, get a list of all areas associated with this mesh network.

API description

- (void)fetchMeshBindAreasWithMeshId:(NSString *)meshId
                       includeStatic:(BOOL)includeStatic
                             success:(nullable void(^)(NSArray<ThingLightingAreaModel *> *areaList))success
                             failure:(nullable void(^)(NSError *error))failure

Sample code

[currentProject fetchMeshBindAreasWithMeshId:self.meshModel.meshId
                                    includeStatic:NO
                                          success:^(NSArray<ThingLightingAreaModel *> * _Nonnull areaList) {

} failure:^(NSError * _Nonnull error) {

}];

Get connected mesh networks

Due to the Bluetooth performance of mobile phones, one mobile phone can currently connect to three mesh networks simultaneously. This method can be used to determine whether a mesh network is connected.

API description

@property (nonatomic, assign, readonly) BOOL isLogin;

Sample code

ThingSmartBleMeshModel *meshModel = [[ThingLightingCacheService sharedInstance] getMeshModelWithId:meshId];
    ThingSmartSIGMeshManager *manager = [ThingSmartBleMesh initSIGMeshManager:meshModel ttl:0 nodeIds:@[]];
BOOL isLogin = [manager isLogin];