Query Reported DP Logs

Last Updated on : 2024-04-03 06:17:21download

You can query the recent historical logs of reported data points (DPs). Currently, you can query only the data of the past 7 days.

Query device operation logs

Query the historical logs of reported DPs, helping you understand the operation history of the device within a certain period of time.

Method signature

- (void)queryDeviceOperateLogWithDpIds:(NSArray *)dpIds
                                offset:(NSInteger)offset
                                 limit:(NSInteger)limit
                             startTime:(NSDate *)startTime
                               endTime:(NSDate *)endTime
                                 isASC:(BOOL)isASC
                               success:(ThingSuccessID)success
                               failure:(ThingFailureError)failure;

Parameter description

Parameter Type Description Mandatory
dpIds NSArray The device functions to be queried, i.e., data point (DP), for example, @[@“1”, @“2”]. Yes
offset NSInteger Pagination offset. Yes
limit NSInteger Page size, the number of results to be returned per page. Yes
startTime NSDate The reporting time of the device, the query start time. No
endTime NSDate The reporting time of the device, the query end time. No
isASC BOOL Order by time:
  • YES: ascending order.
  • NO: descending order, default value.
No
success ThingSuccessID block The success callback. Yes
failure ThingFailureError block The failure callback. Yes

The sum of the values of offset and limit cannot exceed 1000.

Example

Objective-C

NSArray *dpIds = @[@"1", @"2"];
NSInteger offset = 0;
NSInteger limit = 10; // The sum of the values of offset and limit cannot exceed 1000.
NSDate *startTime = nil; // Use actual date if available
NSDate *endTime = nil; // Use actual date if available
BOOL isASC = NO;

ThingSmartDevice *device = [[ThingSmartDevice alloc] init];
[device queryDeviceOperateLogWithDpIds:dpIds offset:offset limit:limit startTime:startTime endTime:endTime isASC:isASC success:^(id result) {
    NSLog(@"Success: %@", result);
} failure:^(NSError *error) {
    NSLog(@"Error: %@", error);
}];

Swift

let dpIds: [String] = ["1", "2"]
let offset: Int = 0
let limit: Int = 10 // The sum of the values of offset and limit cannot exceed 1000.
let startTime: Date? = nil // Use actual date if available
let endTime: Date? = nil // Use actual date if available
let isASC: Bool = false

let device = ThingSmartDevice()
device.queryDeviceOperateLog(withDpIds: dpIds, offset: offset, limit: limit, startTime: startTime, endTime: endTime, isASC: isASC, success: { result in
    print("Success: \(result)")
}, failure: { error in
    print("Error: \(error)")
})