Last Updated on : 2024-04-03 10:28:34download
This topic describes how to manage a 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.
Single mesh network mode
Multi-mesh network mode
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.
Get information about the mesh network associated with the area.
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);
}
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);
The project has only one automatically created mesh network, with all areas bound with this network.
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");
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
.startClient()
has not been called, invoking startSearch()
and stopSearch()
will not work.startSearch
and stopSearch
will not work.A project can have one or more mesh networks. A single mesh network can be bound with one or more areas simultaneously.
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) {
}
});
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 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 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 the specified mesh network.
API description
ThingOSMesh.getMeshManager().initSigMesh(meshId)
Example
ThingOSMesh.getMeshManager().initSigMesh("meshIdxxxxx");
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 a mesh network.
API description
ThingOSMesh.getMeshManager().disconnectMesh(meshId);
Example
ThingOSMesh.getMeshManager().disconnectMesh("meshIdxxxxx");
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) {
}
});
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);
}
}
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback