1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| - (void)deviceGizWifiDevice *)device didReceiveDataNSError *)result dataNSDictionary *)dataMap withSNNSNumber *)sn {
if (result.code == GIZ_SDK_SUCCESS) {
// 已定义的设备数据点,有布尔、数值、枚举、扩展类型
NSDictionary *dataDict = dataMap[@"data"];
// 普通数据点,以布尔类型为例,打印对应的key和value
BOOL onOff = [dataDict[@"LED_OnOff"] boolValue];
NSLog(@"开关值LED_OnOff:%@", @(onOff));
// 扩展类型数据点,key如果是“extData”
NSData *extData = dataMap[@"extdata"];
NSLog(@"扩展数据extData:%@", extData);
// 已定义的设备故障或报警数据点,设备发生故障或报警后该字段有内容,没有发生故障或报警则没内容
NSDictionary *alertsDict = dataMap[@"alerts"];
NSDictionary *faultsDict = dataMap[@"faults"];
NSLog(@"报警:%@, 故障:%@", alertsDict, faultsDict);
// 透传数据,无数据点定义,适合开发者自行定义协议做数据解析
NSData *binary = dataMap[@"binary"];
NSLog(@"透传数据:%@", binary);
} else {
//出错,处理 result 信息
}
}
|