private static void TestSaveDeviceProp() { IClientProfile clientProfile = DefaultProfile.GetProfile("<your-region-id>", "<your-access-key-id>", "<your-access-key-secret>"); DefaultAcsClient client = new DefaultAcsClient(clientProfile); SaveDevicePropRequest request = new SaveDevicePropRequest(); request.Props = "{\"isGateWay\":\"no\"}"; request.ProductKey = "<productKey>"; request.DeviceName = "<deviceName>"; try { SaveDevicePropResponse response = client.GetAcsResponse(request); Console.WriteLine("add new property: " + response.Success); Console.WriteLine(response.ErrorMessage); } catch (ServerException e) { Console.WriteLine(e.ErrorCode); Console.WriteLine(e.ErrorMessage); } catch (ClientException e) { Console.WriteLine(e.ErrorCode); Console.WriteLine(e.ErrorMessage); } Console.ReadKey(); }
public static SaveDevicePropResponse Unmarshall(UnmarshallerContext context) { SaveDevicePropResponse saveDevicePropResponse = new SaveDevicePropResponse(); saveDevicePropResponse.HttpResponse = context.HttpResponse; saveDevicePropResponse.RequestId = context.StringValue("SaveDeviceProp.RequestId"); saveDevicePropResponse.Success = context.BooleanValue("SaveDeviceProp.Success"); saveDevicePropResponse.ErrorMessage = context.StringValue("SaveDeviceProp.ErrorMessage"); return(saveDevicePropResponse); }
//根据设备标签获取设备列表 public void TestQueryDeviceByTags() { DefaultAcsClient acsClient = Demo.IotClient.GetClient(); String productKey = "<productKey>"; String deviceTags = "{\"city\":\"hangzhou\", \"region\":\"west\"}"; for (int i = 100; i <= 150; i += 1) { String devicename = "device_0821_" + i; SaveDevicePropRequest request = new SaveDevicePropRequest(); request.ProductKey = productKey; request.DeviceName = devicename; request.Props = deviceTags; SaveDevicePropResponse response1 = acsClient.GetAcsResponse(request); Console.WriteLine("Save Device Tags: " + response1.Success); if (!(bool)response1.Success) { Console.WriteLine(response1.Code + ", " + response1.ErrorMessage); } } QueryDeviceByTagsRequest request2 = new QueryDeviceByTagsRequest(); request2.CurrentPage = 1; request2.PageSize = 50; List <QueryDeviceByTagsRequest.Tag> Tags = new List <QueryDeviceByTagsRequest.Tag>(); QueryDeviceByTagsRequest.Tag tag1 = new QueryDeviceByTagsRequest.Tag(); tag1.TagKey = "city"; tag1.TagValue = "hangzhou"; Tags.Add(tag1); request2.Tags = Tags; QueryDeviceByTagsResponse response2 = acsClient.GetAcsResponse(request2); Console.WriteLine(response2.Success); if (!(bool)response2.Success) { Console.WriteLine(response2.Code + ", " + response2.ErrorMessage); } Console.WriteLine("Page: " + response2.Page); Console.WriteLine("PageSize: " + response2.PageSize); Console.WriteLine("PageCount: " + response2.PageCount); Console.WriteLine("Total: " + response2.Total); }
//设置设备的标签,采用的是无则创建,有则更新的策略 public void TestSaveDeviceProp() { DefaultAcsClient acsClient = Demo.IotClient.GetClient(); String productKey = "<productKey>"; String devicename = "device_0821_147"; SaveDevicePropRequest request1 = new SaveDevicePropRequest(); request1.ProductKey = productKey; request1.DeviceName = devicename; request1.Props = "{\"city\":\"hangzhou\", \"region\":\"west\"}"; SaveDevicePropResponse response1 = acsClient.GetAcsResponse(request1); Console.WriteLine("Save Device Tags: " + response1.Success); if (!(bool)response1.Success) { Console.WriteLine(response1.Code + ", " + response1.ErrorMessage); } QueryDevicePropRequest request2 = new QueryDevicePropRequest(); request2.ProductKey = productKey; request2.DeviceName = devicename; QueryDevicePropResponse response2 = acsClient.GetAcsResponse(request2); Console.WriteLine(response2.Success); if (!(bool)response2.Success) { Console.WriteLine(response2.Code + ", " + response2.ErrorMessage); } Console.WriteLine("Tags: " + response2.Props); }