物模型开发

设备可以使用物模型功能,实现属性上报(如上报设备状态)、事件上报(上报设备异常或错误)和服务调用(通过云端调用设备提供的服务)。

设备属性

  • 设备属性上报(代码示例)
NSDictionary<NSString *, id> *dict = @{@"WorkMode": @2};
NSString *mid = [self.instance uploadPropertiesWithProperties:dict];

设备事件

  • 设备事件上报
NSDictionary<NSString *, id> *dict = @{@"WorkMode": @2};
NSString *mid = [self.instance uploadEventsWithEvents:dict event: [self.config transormUpload]];

设备服务

  • 设备属性获取(代码示例)
- (NSDictionary<NSString *, id> *)iotGet:(IoTInstance *)iot properties:(NSArray<NSString *> *)properties {

    NSMutableDictionary<NSString *, id> *dict = [NSMutableDictionary dictionary];
    if ([properties containsObject:@"PowerSwitch"]) {
        [dict setObject:@YES forKey:@"PowerSwitch"];
    }
    return dict;
}
  • 设备属性设置(代码示例)
- (NSString *)iotSet:(IoTInstance *)iot properties:(NSDictionary<NSString *, id> *)properties {

    NSLog(@"云端设置属性:%@", properties);
    return @"ios set success";
}
  • 设备自定义服务(代码示例)
- (NSString *)iotCall:(IoTInstance *)iot identifier:(NSString *)identifier services:(NSDictionary<NSString *,id> *)services {
    if ([identifier isEqualToString:@"AdjustTemperature"]) {
        NSLog(@"call services params:%@", services);
    }
    return @"ios call success";
}

results matching ""

    No results matching ""