Mesh Network Management

Last Updated on : 2024-04-03 10:28:26download

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, there may be an area without an associated mesh network. Users must manually bind it with a mesh network.

Example

// Get the corresponding SimpleAreaBean object from the cache by areaId.
SimpleAreaBean areaBean = ThingCommercialLightingArea.newAreaInstance(
                projectId,// Project ID
                areaId // Area ID
        ).getCurrentAreaCache();

// Get the meshId associated with the current area.
String meshId = areaBean.getMeshId();

// If meshId is not empty, get the SigMeshBean object.
if (!TextUtils.isEmpty(meshId)) {
    ILightingMultiMeshPlugin service = PluginManager.service(ILightingMultiMeshPlugin.class);
    SigMeshExtBean sigMeshBean = service.getInstance().getSigMeshBean(projectId, meshId);
}

Get mesh network list

Projects in single mesh network mode have only one mesh network, while projects in multi-mesh network mode may have one or more mesh networks.

API description

ILightingMultiMeshPlugin # getInstance() # getSigMeshBeans(projectId)

Example

ILightingMultiMeshPlugin service = PluginManager.service(ILightingMultiMeshPlugin.class);

List<SigMeshExtBean> sigMeshBeans = service.getInstance().getSigMeshBeans(projectId);

Single mesh network mode

The project has only one automatically created mesh network, with all areas bound with this network.

Initialization

Initialize a Bluetooth mesh network and register a listener for status changes from the cloud. Invoke this method when you switch between or initialize Bluetooth mesh networks.

API description

void initMesh(String meshId);

Example

ThingOSMesh.getThingSigMeshClient().initMesh("meshIdxxxxx");

Connect or disconnect Bluetooth mesh sub-device

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

Example

// Establish connection
ThingOSMesh.getThingSigMeshClient().startClient(mSigMeshBean);
// Establish connection and specify the scan time period.
ThingOSMesh.getThingSigMeshClient().startClient(mSigMeshBean,searchTime);

// Disconnect
ThingOSMesh.getThingSigMeshClient().stopClient();

// Start scanning
ThingOSMesh.getThingSigMeshClient().startSearch()

// Stop scanning
ThingOSMesh.getThingSigMeshClient().stopSearch();

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

  • startClient(mSigMeshBean): After a connection is started, the app will continuously scan for devices in the background until it successfully connects to one.
  • startClient(mSigMeshBean,searchTime): After a connection is started, the app will stop scanning if no device is found within the specified searchTime.
  • If startClient() has not been called, invoking startSearch() and stopSearch() will not work.
  • After a Bluetooth mesh network is connected, invoking startSearch and stopSearch 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

ILightingMultiMeshPlugin # getMultiMeshManager() # createSigMesh(projectId,meshName,callback)

Example

ILightingMultiMeshPlugin service = PluginManager.service(ILightingMultiMeshPlugin.class);
service.getMultiMeshManager().createSigMesh(
        projectId, // Project ID
        meshName, // Mesh name
        new IThingResultCallback<SigMeshExtBean>() {
    @Override
    public void onSuccess(SigMeshExtBean sigMeshExtBean) {

    }

    @Override
    public void onError(String errorCode, String errorMessage) {

    }
});

Delete mesh network

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

API description

ILightingMultiMeshPlugin # getMultiMeshManager() # deleteSigMesh(projectId,meshId,callback)

Example

 ILightingMultiMeshPlugin service = PluginManager.service(ILightingMultiMeshPlugin.class);
service.getMultiMeshManager().deleteSigMesh(
        projectId,// Project ID
        meshId,   // Mesh ID
        new IThingResultCallback<Boolean>() {
            @Override
            public void onSuccess(Boolean aBoolean) {

            }

            @Override
            public void onError(String errorCode, String errorMessage) {

            }
        });

Bind area with mesh network

Bind a mesh network with an unassigned area. Binding with multiple area IDs simultaneously is supported.

API description

ILightingMultiMeshPlugin # getMultiMeshManager() # bindSigMeshAreas(projectId,meshId,areaIds,callback)

Example

List<String> areaIds = new ArrayList<>();
areaIds.add("areaId1");
areaIds.add("areaId2");
areaIds.add("areaId3");

ILightingMultiMeshPlugin service = PluginManager.service(ILightingMultiMeshPlugin.class);
service.getMultiMeshManager().bindSigMeshAreas(
        projectId,
        meshId,
        areaIds,
        new IThingResultCallback<Boolean>() {
            @Override
            public void onSuccess(Boolean aBoolean) {

            }

            @Override
            public void onError(String errorCode, String errorMessage) {

            }
        });

Unbind area from mesh network

Unbind a mesh network from an area. Unbinding from multiple area IDs simultaneously is supported.

API description

ILightingMultiMeshPlugin # getMultiMeshManager() # unbindSigMeshAreas(projectId,meshId,areaIds,callback)

Example

List<String> areaIds = new ArrayList<>();
areaIds.add("areaId1");
areaIds.add("areaId2");
areaIds.add("areaId3");

ILightingMultiMeshPlugin service = PluginManager.service(ILightingMultiMeshPlugin.class);
service.getMultiMeshManager().unbindSigMeshAreas(
        projectId,
        meshId,
        areaIds,
        new IThingResultCallback<Boolean>() {
            @Override
            public void onSuccess(Boolean aBoolean) {

            }

            @Override
            public void onError(String errorCode, String errorMessage) {

            }
        });

Initialize mesh network

Initialize the specified mesh network.

API description

  ThingOSMesh.getMeshManager().initSigMesh(meshId)

Example

  ThingOSMesh.getMeshManager().initSigMesh("meshIdxxxxx");

Connect to mesh network

Up to three mesh networks can be connected simultaneously.

API description

ThingOSMesh.getMeshManager().connectMesh(builderList);

Example

List<MeshConnectBuilder> builderList = new ArrayList<>();
builderList.add(new MeshConnectBuilder.Builder()
        .setSigMeshBean(sigmeshBean1)
        .setScanTimeout(30*1000)
        .setConnectStatusListener(listener1)
        .build());
ThingOSMesh.getMeshManager().connectMesh(builderList);

Disconnect from mesh network

Disconnect from a mesh network.

API description

ThingOSMesh.getMeshManager().disconnectMesh(meshId);

Example

ThingOSMesh.getMeshManager().disconnectMesh("meshIdxxxxx");

Get the list of associated areas

Get the list of areas bound with a mesh network based on meshId.

Example

ILightingMultiMeshPlugin service = PluginManager.service(ILightingMultiMeshPlugin.class);
service.getMultiMeshManager().getSigMeshAreas(projectId, meshId, true,
        new IThingResultCallback<List<AreaBean>>() {
            @Override
            public void onSuccess(List<AreaBean> simpleAreaBeans) {

            }

            @Override
            public void onError(String errorCode, String errorMessage) {

            }
        });

Get connected mesh network

A mobile phone can connect to up to three mesh networks simultaneously. This method returns the list of meshId that the phone is currently connected to.

API description

List<String> connectedMeshIds = ThingOSMesh.getMeshManager().getConnectedMeshIds();

Example

List<String> connectedMeshIds = ThingOSMesh.getMeshManager().getConnectedMeshIds();
List<SigMeshExtBean> sigMeshExtBeans = new ArrayList<>();
ILightingMultiMeshPlugin service = PluginManager.service(ILightingMultiMeshPlugin.class);
for (String meshId : connectedMeshIds) {
    SigMeshExtBean sigMeshBean = service.getInstance().getSigMeshBean(projectId, meshId);
    if (sigMeshBean != null) {
        sigMeshExtBeans.add(sigMeshBean);
    }
}