Bluetooth Mesh local timer SDK

更新时间:
复制 MD 格式

The Bluetooth Mesh local timer SDK lets you set local timers for Mesh devices and automatically synchronize time using an app.

Overview

Dependent SDKs

Overview

TSL model SDK

The TSL model SDK provides the Thing Specification Language (TSL) model for the app.

Bluetooth Mesh SDK

Provides basic Bluetooth Mesh capabilities.

Instructions

Check the Bluetooth Mesh network connection

Use the following code to determine whether the device is connected to the Mesh network.

BOOL isConnect = [ALBBluetoothMesh sharedInstance].isConnect;

Local timer operations

Obtain the MeshTimerTransaction object

Before adding, deleting, or updating a local timer for a Mesh node, obtain the MeshTimerTransaction object.

// The input parameter is the iotId of the Mesh device.
[[IMSMeshTimerTransaction alloc] initWithIotID:@"xxx"];
  • Timer object model: IMSMeshTimerModel

    #import <TBJSONModel/TBJSONModel.h>
    
    NS_ASSUME_NONNULL_BEGIN
    
    
    typedef NS_ENUM(NSUInteger, IMSEnableType) {
        IMSDisable = 0,         /// Disabled
        IMSEnable,              /// Enabled
        IMSInFlight             /// Instruction sent
    };
    
    typedef NS_ENUM(NSUInteger, IMSMeshTimerType) {
        IMSMeshTimerNone = 0,
        IMSMeshTimerCountDown,      /// Countdown
        IMSMeshTimerNormal,         /// Normal timer
        IMSMeshTimerCirculation     /// Periodic timer
    };
    
    @interface IMSMeshTimerModel : TBJSONModel
    
    /*
     Timer ID
     */
    @property (nonatomic, assign, readonly) NSInteger timerID;
    
    /*
     Timer type
     */
    @property (nonatomic, assign, readonly) IMSMeshTimerType timerType;
    
    /*
     Specifies whether to enable the timer. enableType
     */
    @property (nonatomic, assign, readonly) IMSEnableType enableType;
    
    
    /*
     Time
     Countdown timer. Example: If the current time is 17:00 on May 25, 2022, and you want to set a one-hour countdown, the input parameter is 2022-05-25 18:00.
     Normal timer. Start time. Example: To run daily at 12:40, the input parameter is 12:40. The week input parameter is @"1,2,3,4,5,6,7".
     Periodic timer. Start time. Example: To run daily at 12:00, the input parameter is 12:00. The week input parameter is @"1,2,3,4,5,6,7".
     */
    @property (nonatomic, strong) NSString *dateString;
    
    /*
     Required for periodic and normal timers.
     Format: @"1,2,3,4,5,6,7". 1 indicates Sunday, and 2 indicates Monday.
     */
    @property (nonatomic, strong, nullable) NSString *week;
    
    /*
     Controls multiple properties and their values. Use commas (,) to separate property pairs. targets
     Example: @"PowerSwitch:1,mode:2"
     */
    @property (nonatomic, strong) NSString *attributes;
    
    /*
     Time zone. For example, UTC+8 is 28800. TimeZone
     This parameter specifies the offset between the local time and UTC in seconds.
     Value range: -43200 to 50400.
     Step size: 3600.
     */
    @property (nonatomic, assign) NSInteger timeZone;
    
    /*
     End time. Used for periodic timers. endTime
     Example: HH:mm
     */
    @property (nonatomic, strong) NSString *endTime;
    
    /*
     The run duration. For example, run for 30 minutes. Used for periodic timers. Unit: minutes. runTime
     */
    @property (nonatomic, assign) NSInteger runTime;
    
    /*
     The sleep duration. For example, sleep for 30 minutes. Used for periodic timers. Unit: minutes. sleepTime
     */
    @property (nonatomic, assign) NSInteger sleepTime;
    
    /**
     Countdown timer.
     Required parameters: dateString, attributes, timeZone.
     */
    - (instancetype)initWithCountDownTimer;
    
    /**
     Normal timer.
     Required parameters: dateString, week, attributes, timeZone.
     */
    - (instancetype)initWithNormalTimer;
    
    /**
     Periodic timer.
     Required parameters: dateString, week, attributes, timeZone, endTime, runTime, sleepTime.
     */
    - (instancetype)initWithCirculationTimer;
    
    @end
    
    NS_ASSUME_NONNULL_END
                        
  • Retrieve the list of timer tasks

    Retrieve the list of scheduled tasks for the current device. Call this API before updating, deleting, or adding a local timer.

    // The input parameter is the iotId of the Mesh device.
    IMSMeshTimerTransaction *meshTimerTransaction = [[IMSMeshTimerTransaction alloc] initWithIotID:@"xxx"];
    
    [meshTimerTransaction getDeviceTimerListhandler:^(NSArray<IMSMeshTimerModel *> * _Nullable timerList, NSError * _Nullable error) {
            if (error) {
    
            } else {
                // timerList: The list of existing timers.
            }
        }];

Timer operations

The SDK lets you add, delete, or update a timer. After making changes, call the save API. If the operation is successful, the API returns the latest list of timers.

Add a local scheduled task

To add a timer, create a new IMSMeshTimerModel object using the corresponding constructor.

@interface IMSMeshTimerModel : TBJSONModel

/**
 Countdown timer.
 Required parameters: dateString, attributes, timeZone.
 */
- (instancetype)initWithCountDownTimer;

/**
 Normal timer.
 Required parameters: dateString, week, attributes, timeZone.
 */
- (instancetype)initWithNormalTimer;

/**
 Periodic timer.
 Required parameters: dateString, week, attributes, timeZone, endTime, runTime, sleepTime.
 */
- (instancetype)initWithCirculationTimer;

@end


// Add a timer.

@interface IMSMeshTimerTransaction : NSObject

/**
 Adds a scheduled task.

 @param timerModel The scheduled task object.
 */
- (NSError *)addTimerWithTimerModel:(IMSMeshTimerModel *)timerModel;

/**
 After the operation is complete, call the save method to save the changes.
 */
- (void)save:(IMSMeshTimerListHandler)handler;

@end

Delete a local timer

To delete a timer, you can use the model returned by the getDeviceTimerListhandler function.

// Delete a timer.

@interface IMSMeshTimerTransaction : NSObject

/**
 Deletes a scheduled task.

 @param timerModel The scheduled task object.
 */
- (NSError *)deleteTimerWithTimerModel:(IMSMeshTimerModel *)timerModel;

/**
 After the operation is complete, call the save method to save the changes.
 */
- (void)save:(IMSMeshTimerListHandler)handler;

@end

Edit a local timer

To edit the timer, use the model returned by the getDeviceTimerListhandler function.

// Edit a timer.

@interface IMSMeshTimerTransaction : NSObject

/**
 Edits a scheduled task.

 @param timerModel The scheduled task object.
 */
- (NSError *)editTimerWithTimerModel:(IMSMeshTimerModel *)timerModel;

/**
 After the operation is complete, call the save method to save the changes.
 */
- (void)save:(IMSMeshTimerListHandler)handler;

@end