文档

蓝牙 Mesh 组控 SDK

更新时间:
一键部署

SDK提供蓝牙Mesh组控业务的App端解决方案,提供了蓝牙Mesh添加分组、删除分组以及组控的能力。

概述

单控使用 物模型 SDK 即可。

依赖 SDK

概述

物模型SDK

物模型SDK提供了App端的物模型。

使用说明

连接到Mesh网络

在单控或组控设备前,需要保证当前APP连接到Mesh网络。

///依赖头文件
#import <ALBBluetoothMesh/ALBBluetoothMesh.h>

///使用下列方法可以连接到Mesh网络,其中iotId可以是自己名下任意一个设备的iotId
[[ALBBluetoothMesh sharedInstance] connectWithDeviceInfo:@{@"iotId": iotId}];

获取Mesh网络是否连接

可以使用下面的方式判断当前是否已经连接到了Mesh网络。

///依赖头文件
#import <ALBBluetoothMesh/ALBBluetoothMesh.h>

////其中iotId可以是自己名下任意一个设备的iotId
[[ALBBluetoothMesh sharedInstance] isConnectWithIotId:@{@"iotId": iotId}]

给设备配置组播地址

组控设备前,需要给设备添加组播地址。方法入参需要依赖控制分组相关API,详见API创建设备组预先获取mesh设备组播地址配置获取设备组的设备列表批量删除设备组删除设备组

///依赖头文件
#import <ALBBluetoothMesh/ALBBluetoothMesh.h>

///入参的取值依赖云端api的返回值
NSString * deviceKey = @""; // 待添加组播地址设备的deviceKey
int primaryAddress = ; // 主节点的单播地址
int elementAddress = ; // 待删除配置节点的单播地址
int subscriptionAddress = ; //需要删除的组播地址
int modelIdentifier = ; // SIG Model ID or Vendor Model ID

[[ALBBluetoothMesh sharedInstance] configModelSubscriptionAdd:deviceKey
                                   primaryAddress:primaryAddress
                                   elementAddress:elementAddress
                                   subscriptionAddress:subscriptionAddress
                                   modelIdentifier:modelIdentifier
complete:^(ALBDeviceSubscribeInfo *subInfo, NSError * _Nullable error) {
                        if (error) {
                            IMSIMSControlGroupLogDebug(@"configModelSubscriptionAdd error:%@", error);
                        }
                        if (complete) {
                            ////error = nil ,则表示向设备写入组播地址成功
                            complete(error, iotId, YES);
                        }
                    }];
                                               

参数说明

名称

类型

必填

默认值

描述

deviceKey

NSString *

待配置节点的deviceKey。不同设备的deviceKey不一样。

primaryAddress

Integer

和elementAddress一致。

elementAddress

Integer

待配置节点的单播地址。

subscriptionAddress

Integer

需要订阅的组播地址。

modelIdentifier

Integer

SIG Model ID or Vendor Model ID,用于标识节点内的模型。

complete

IActionListener<Boolean>

配置结果回调。

如上参数在调用云端API的时候会全部返回。

删除设备配置的组播地址

///入参的取值依赖云端api的返回值
NSString * deviceKey = @""; // 待添加组播地址设备的deviceKey
int primaryAddress = ; // 主节点的单播地址
int elementAddress = ; // 待删除配置节点的单播地址
int subscriptionAddress = ; //需要删除的组播地址
int modelIdentifier = ; // SIG Model ID or Vendor Model ID

[[ALBBluetoothMesh sharedInstance] configModelSubscriptionDelete:deviceKey
              primaryAddress:primaryAddress
              elementAddress:elementAddress
              subscriptionAddress:subscriptionAddress
              modelIdentifier:modelIdentifier
              complete:^(ALBDeviceSubscribeInfo *subInfo, NSError * _Nullable error) {
                        if (error) {
                            IMSIMSControlGroupLogDebug(@"configModelSubscriptionDelete error:%@", error);
                        }
                        if (complete) {
                            complete(error, iotId, NO);
                        }
                    }];

参数说明

名称

类型

必填

默认值

描述

deviceKey

NSString *

待配置节点的deviceKey。不同设备的deviceKey不一样。

primaryAddress

Integer

和elementAddress一致。

elementAddress

Integer

待配置节点的单播地址。

subscriptionAddress

Integer

需要删除的已订阅的组播地址。

modelIdentifier

Integer

SIG Model ID or Vendor Model ID,用于标识节点内的模型。

deviceControlListener

IActionListener<Boolean>

配置结果回调。

如上参数在调用云端API的时候会全部返回。

组控调用

设备组控是基于物的模型对设备定义的属性进行操作。关于属性的描述,请参见基本概念

// ///设置群组开关属性为例,isOpen取值1表示打开设备,0表示关闭设备
- (void)setControlGroupPowerProperty:(NSString *)groupId devices:NSArray<NSString *> *deviceIotIds 
isOpen:(BOOL)isOpen {
    IMSHomeLogDebug(@"setControlGroupPwoerProperty:%@ isOpen:%@",  groupId, @(isOpen));
    if (groupId) {
        NSNumber *channel =  @(GroupPolicyLocalPrefer);
        __weak typeof(self) weakSelf = self;
        NSDictionary* extra = @{@"controlGroupId":groupId,
                                @"QosLevel":@"Qos_CON",
                                @"Channel":channel,
                                @"iotId": deviceIotIds.firstObject ? : @"",
                                @"isNative": @(YES),
                                @"deviceIotIds": deviceIotIds};
         ///powerstate为设备开关属性,其他属性取值请参见物模型TSL
        [[IMSGroupManager sharedManager] setGroupProps:@{@"items":@{@"powerstate": isOpen ? @(1) : @(0)}}
              extraData:extra
        responseHandler:^(IMSGroupActionsResponse * _Nullable response) {
            if (response.responseError) {
                IMSHomeLogVerbose(@"ims cycle HomeVC : Control 控制组设置属性失败!groupId = %@ error = %@", controlgroup.groupModel.groupId,  response.responseError.localizedDescription);
                ///[IMSToast showToast:response.responseError.localizedDescription withShowTime:1 inVC:[weakSelf currentViewController]];
                
            }
            // 这个回调只决定消息是否发出,不能决定是否正确设置成功,通过dalegate获取属性变更
        }];
    }
}

参数说明

名称

类型

必填

默认值

描述

groupId

NSString *

待控制组的ID。

deviceIotIds

NSArray<NSString *> *

群组内所有设备的iotId。

组控调用后,设备状态变更消息跟单控的一样。请参见物模型 SDK即可。

  • 本页导读 (0)
文档反馈