文档

蓝牙 Mesh 本地定时 SDK

更新时间:
一键部署

蓝牙 Mesh 本地定时 SDK 提供了通过 App 设置Mesh设备本地定时,以及自动对时的功能。

概述

依赖 SDK

概述

物模型SDK

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

蓝牙 Mesh SDK

提供蓝牙mesh基础能力

使用说明

获取蓝牙Mesh网络是否有连接

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

BOOL isConnect = [ALBBluetoothMesh sharedInstance].isConnect;

本地定时操作

获取 MeshTimerTransaction 对象

在添加/删除/更新某个mesh节点的本地定时前,需要获取 MeshTimerTransaction 对象。

// 入参为mesh设备的iotId
[[IMSMeshTimerTransaction alloc] initWithIotID:@"xxx"];
  • 定时对象模型 IMSMeshTimerModel

    #import <TBJSONModel/TBJSONModel.h>
    
    NS_ASSUME_NONNULL_BEGIN
    
    
    typedef NS_ENUM(NSUInteger, IMSEnableType) {
        IMSDisable = 0,         /// 未启用
        IMSEnable,              /// 启用
        IMSInFlight             /// 指令下发
    };
    
    typedef NS_ENUM(NSUInteger, IMSMeshTimerType) {
        IMSMeshTimerNone = 0,
        IMSMeshTimerCountDown,      /// 倒计时
        IMSMeshTimerNormal,         /// 普通定时
        IMSMeshTimerCirculation     /// 循环定时
    };
    
    @interface IMSMeshTimerModel : TBJSONModel
    
    /*
     定时器ID
     */
    @property (nonatomic, assign, readonly) NSInteger timerID;
    
    /*
     定时器类型
     */
    @property (nonatomic, assign, readonly) IMSMeshTimerType timerType;
    
    /*
     是否启用   enableType
     */
    @property (nonatomic, assign, readonly) IMSEnableType enableType;
    
    
    /*
     时间
     倒计时 举例:如当前时间是2022-05-25 17:00,倒计时1个小时 入参:2022-05-25 18:00
     普通定时 开始时间,举例: 每天12:40  入参:12:40   (week入参@"1,2,3,4,5,6,7")
     循环定时 开始时间,举例: 每天12:00  入参:12:00   (week入参@"1,2,3,4,5,6,7")
     */
    @property (nonatomic, strong) NSString *dateString;
    
    /*
     循环定时普通定时必填
     格式:@"1,2,3,4,5,6,7"    (1表示星期天,2表示星期一)
     */
    @property (nonatomic, strong, nullable) NSString *week;
    
    /*
     控制多个属性及属性值,每对属性之间使用,分割  targets
     示例:@"PowerSwitch:1,mode:2"
     */
    @property (nonatomic, strong) NSString *attributes;
    
    /*
     时区,东八区  TimeZone  28800
     表示本地事件与UTC时间的差值
     单位:秒
     取值范围为:-43200到50400
     步长:3600
     */
    @property (nonatomic, assign) NSInteger timeZone;
    
    /*
     结束时间,周期循环定时的类型用到  endTime
     示例:HH:mm
     */
    @property (nonatomic, strong) NSString *endTime;
    
    /*
     运行的时长,如打开30分钟,周期循环定时的类型用到   单位分   runTime
     */
    @property (nonatomic, assign) NSInteger runTime;
    
    /*
     睡眠的时长,如打开30分钟,周期循环定时的类型用到   单位分  sleepTime
     */
    @property (nonatomic, assign) NSInteger sleepTime;
    
    /**
     倒计时定时器
     必填参数:dateString,attributes,timeZone
     */
    - (instancetype)initWithCountDownTimer;
    
    /**
     普通定时器
     必填参数:dateString,week,attributes,timeZone
     */
    - (instancetype)initWithNormalTimer;
    
    /**
     循环定时器
     必填参数:dateString,week,attributes,timeZone,endTime,runTime,sleepTime
     */
    - (instancetype)initWithCirculationTimer;
    
    @end
    
    NS_ASSUME_NONNULL_END
                        
  • 获取定时器任务列表

    获取当前设备列表中的定时任务列表。在更新/删除/增加本地定时功能前,必须调用该接口。

    // 入参为mesh设备的iotId
    IMSMeshTimerTransaction *meshTimerTransaction = [[IMSMeshTimerTransaction alloc] initWithIotID:@"xxx"];
    
    [meshTimerTransaction getDeviceTimerListhandler:^(NSArray<IMSMeshTimerModel *> * _Nullable timerList, NSError * _Nullable error) {
            if (error) {
    
            } else {
                // timerList 已经存在的定时器列表
            }
        }];

定时器操作

SDK提供添加/删除/更新某个定时器的功能。修改完成以后调用保存接口进行保存,保存函数成功后会返回最新的定时器列表。

添加本地定时任务

添加定时器需要新建一个IMSMeshTimerModel,使用对应的构造函数。

@interface IMSMeshTimerModel : TBJSONModel

/**
 倒计时定时器
 必填参数:dateString,attributes,timeZone
 */
- (instancetype)initWithCountDownTimer;

/**
 普通定时器
 必填参数:dateString,week,attributes,timeZone
 */
- (instancetype)initWithNormalTimer;

/**
 循环定时器
 必填参数:dateString,week,attributes,timeZone,endTime,runTime,sleepTime
 */
- (instancetype)initWithCirculationTimer;

@end


// 添加定时器

@interface IMSMeshTimerTransaction : NSObject

/**
 新增一个定时任务

 @param timerModel 定时任务对象
 */
- (NSError *)addTimerWithTimerModel:(IMSMeshTimerModel *)timerModel;

/**
 操作完成以后调用save方法进行保存
 */
- (void)save:(IMSMeshTimerListHandler)handler;

@end

删除某个本地定时

删除定时器,需要使用 getDeviceTimerListhandler 函数返回的model。

// 添加定时器

@interface IMSMeshTimerTransaction : NSObject

/**
 新增一个定时任务

 @param timerModel 定时任务对象
 */
- (NSError *)deleteTimerWithTimerModel:(IMSMeshTimerModel *)timerModel;

/**
 操作完成以后调用save方法进行保存
 */
- (void)save:(IMSMeshTimerListHandler)handler;

@end

编辑某个本地定时

编辑定时器,需要使用getDeviceTimerListhandler函数返回的model。

// 添加定时器

@interface IMSMeshTimerTransaction : NSObject

/**
 新增一个定时任务

 @param timerModel 定时任务对象
 */
- (NSError *)editTimerWithTimerModel:(IMSMeshTimerModel *)timerModel;

/**
 操作完成以后调用save方法进行保存
 */
- (void)save:(IMSMeshTimerListHandler)handler;

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