Ali cloud Things .NET Core Client | CZGL.AliIoTClient:. 5 to set unit properties

Documents directory:


 

In the previous chapter, Gree temperature gree_temperature set access rights, because the air conditioning output temperature can be set.
CPU temperature is acquired based on the actual situation, the air-conditioning temperature is set to the remote controller, or the temperature data server may also be provided in this data.
It represents the server has read and write access instruction issued under the authority of the setting device properties.

Note that the only read / write both cases, did not write.


1) allows the server to set the device properties

Communication is to subscribe / push, the upper and lower data transmission itself is not so complicated, both properties, events, services, nature or Topic.
CZGL.AliIoTClient made a detailed classification (soon boast the author), which set a number of parameters, which is more free and easy.

Chapter 3 already comes to how to open and cancel response and other functions, will not be explained here.

The following is the initial code, will be described (see DeviceOptions the modification information) on the basis of:

        static AliIoTClientJson client;
        static void Main(string[] args) { // 创建客户端 client = new AliIoTClientJson(new DeviceOptions { ProductKey = "a1A6VVt72pD", DeviceName = "json", DeviceSecret = "7QrjTptQYCdepjbQvSoqkuygic2051zM", RegionId = "cn-shanghai" }); client.OpenPropertyDownPost(); // 设置要订阅的Topic、运行接收内容的Topic string[] topics = new string[] { client.CombineHeadTopic("get") }; // 使用默认事件 client.UseDefaultEventHandler(); // 连接服务器 client.ConnectIoT(topics, null, 60); Console.ReadKey(); } 

In the  Console.ReadKey() prior add a line, send the attribute set command to run the server:

            client.OpenPropertyDownPost(); 

Run the program.


2) command issued

Open Ali cloud Things console, enter  在线调试 , and then select the already created products and equipment.
You can also directly open:  https://iot.console.aliyun.com/lk/monitor/debug  set as follows:

调试设备:调试真实设备
功能:    格力空调温度(gree_temperature)
方法:    设置

The input value is then changed to 20.0 box, click send instructions

{
  "gree_temperature": 20
}

Then you can see the console program received instructions:

get topic message,Date: 16:52:55 topic: /sys/a1A6VVt72pD/json/thing/service/property/set get messgae : {"method":"thing.service.property.set","id":"666237842","params":{"gree_temperature":20},"version":"1.0.0"} 

The use Alink json, so the instruction is actually delivered by the server is such that:

{"method":"thing.service.property.set","id":"666237842","params":{"gree_temperature":20},"version":"1.0.0"} 

Why would the outputs of other things? This is because a number of default settings CZGL.AliIoTClient kind of event methods,
it will output the contents of the message received (message) and other information, you can customize the way to handle.

After the string format:

{
	"method": "thing.service.property.set",
	"id": "666237842",
	"params": { "gree_temperature": 20 }, "version": "1.0.0" } 

But now only receive commands sent by the server, there is no method for how to handle these write command, which requires you to write the appropriate method to bind to delegate event.
When you receive a message property, it will trigger these methods. How to set, please refer to the following chapters.


3) to respond

When you receive instruction delivered by the server, you can respond to this article Topic.

// 返回消息ID
public int Thing_Property_set(CZGL.AliIoTClient.PropertyDownModel model, [bool isToLower = True]) public int Thing_Property_set(CZGL.AliIoTClient.PropertyDownModel model, [bool isToLower = True], [System.Text.Encoding encoding = null]) public int Thing_Property_set<TModel>(TModel model, [bool isToLower = True]) 


In fact, you do not need to respond. . . If necessary, you can customize the way in which the method plus response, bound to the commission, the automatic response.
How to set, please refer to the following chapters.

Guess you like

Origin www.cnblogs.com/whuanle/p/10994701.html