Ali cloud Things .NET Core Client | CZGL.AliIoTClient:. 3 and Response Topic Subscribe Topic

Documents directory:


Topic will be divided into five CZGL.AliIoTClient

They are: General Topic, property report, issued property, event reporting, service calls, in addition to ordinary Topic, sent in response to each Topic has a message.

Normal Topic, or send a message, according to the protocol MQTT, the SDK can be strictly guaranteed message reaches the other end.
Push device properties, events, and other data to the server, the server to respond,
the server pushes (issued) data to the device, the device to respond.
Of course, these responses dispensable, no real influence.

Each, each has a specific Topic MQTT mailing address, the address is automatically generated in CZGL.AliIoTClient, you only need to fill in ordinary Topic communications address.


1) Subscribe Topic

Topic subscription before, and the need to set the appropriate Topic aliyun things define  订阅 permissions
ordinary Topic, using string [] contains a list, and then passed as a parameter in the call connection method, also in connection with the server, add the required subscription .
Normal Topic can be dynamically added, belongs to the thermal subscription.

Instructions:

 // 设置要订阅的Topic、运行接收内容的Topic
            string[] topics = new string[] { 
                                client.CombineHeadTopic("get"), "/a1xrkGSkb5R/mire/user/get1" }; client.ConnectIoT(topics,null,60); 

Topic long address, you can record the  .../user/ contents of, use  CombineHeadTopic() can be automatically generated,

client.CombineHeadTopic("get") 

2) response

When you use the properties, events, services, data transmission when the server, the server responds, you can choose to receive a response, or may not receive a response.
CZGL.AliIoTClient default server does not receive the response information. The response information is actually generally require at commissioning.

Response method Explanation
OpenEventPostReply() After receiving the report in response to the event server
Open Property Post Reply () After receiving the response of the server device attributes uploaded
OpenServicePostRaw() Allowing the server to call service The new version has been canceled this setting
Open Property Down Post () Hair setting the device attribute command allows the server

Note that these responses must be set before connecting the client, and the client is already connected, can no longer use the above method, otherwise it will pop up an exception.
Has been fixed, you can open reception at any stage of the proceedings, any cancellation and open.

These functions are open to view:

public CZGL.AliIoTClient.OpenTopic getOpenTopic()

OpenTopic It has eight attributes, or for acquiring the setting to turn certain functions of the receiver.

Attributes Explanation Defaults
CommonTopic Whether to receive ordinary Topic Fixed is true, can not be changed
PropertyUpRawReplyTopic After the device in response to the attribute data upload server passthrough false
PropertyPostReplyTopic After the device in response to the attribute data upload server Alink json false
PropertyDownRaw Hair setting properties in server command, passthrough false
PropertyDownPost Hair setting properties in server command, Alink json false
EventUpRawReply Equipment event reporting, server response is received, the pass-through false
EventPostReply Equipment event reporting, in response to receiving the server, Alink json false
ServiceDownRaw Call service server, pass-through false
ServicePostRaw Server call service, Alink json false

Since the pass-through and Alink json distinguish, if the pass-through, provided the above Alink json entry is invalid, or vice versa.


3) connection with the server


In connection with the server, you can also increase the general Topic to subscribe to:

public void TopicAdd(string[] topics, [byte[] QOS = null]) 

Example:

client.TopicAdd(new string[]{ client.CombineHeadTopic("get") })

Remove already subscribed Topic:

public void TopicRemove(string[] topics) 

In connection with the server, the server can be canceled in response to the information received, but can not re-received.

method Explanation
CloseEventPostReply () After the incident response equipment is no longer receiving server to upload
ClosePropertyPostReply() After the device in response to receiving no upload server attribute
CloseServicePostRaw() Command calls the device does not allow the server service issuedThis setting has been removed
ClosePropertyDownPost() Instruction set device attributes at the server is not allowed

You can connect to the server when the client canceled receive a response. However, the canceled and can not subscribe!
Has been fixed, you can cancel the program before opening reception at any stage.


4) Topic Description

Gets has subscribed Topic list:

public string[] GetSubedList { get; }

Example:

var topicList = client.GetSubedList;

Server set the device properties, call services and other functions, the use of MQTT communications, is to subscribe / push format, so no matter what the data transmission function, nature or Topic. Thus, those reported by device properties, device properties and the like is provided, it can be configured Topic properties.

CZGL.AliIoTClient, the client may need to subscribe to the Topic, the connection to the server, the server can send data to all Topic, but only the client specifies Topic subscription, the client will receive the push, otherwise no matter how the console click send the client is not received.

There is a place to be noted that, for ordinary Topic, is with the configuration when the client connects, the server can decide whether to push messages to the client, dynamic.

And once the configuration properties, events, services, these functions will be saved. When you open

client.OpenPropertyPostReply();

After receiving the response properties uploaded to the server, delete the program

client.OpenPropertyPostReply();

Run again, will still receive a response unless settings

client.ClosePropertyPostReply();

Uploading data to the server, the server responds, of course, the server set the device properties, equipment service when you call, the client can respond. It will be covered in later chapters.

Guess you like

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