.NET Core Cross-Platform IoT Development: SDK Properties, Methods, Delegates, and Classes (Part 4)

2019年12月15日 42点热度 0人点赞 1条评论
内容目录

Series Tutorial Directory

 (1) Connect to Alibaba Cloud IOT

 (2) Set Delegate Events

 (3) Report Properties

 (4)  SDK Documentation: Properties, Methods, Delegates, Classes

 http://pan.whuanle.cn/index.php?dir=uploads/阿里云IOT/AliIOTXFclient-dll类库&response

Download three libraries, include the headers, and they can be used.

using AliIOTXFClient;

Example download address

http://pan.whuanle.cn/index.php?dir=uploads/阿里云IOT/demo示例

 

The AliIOTXFClient.XFMQTT class is the core functionality.

Generate Topics for Device Properties, Services, and Event Communication

public readonly ThingModel thingModel

There are four main properties used to get or set the Topic addresses of properties, services, and events.

 

Name Description
upTopic

Used to upload device property data, with the following fields:

Device reported property request Topic--pass-through: up_raw 

Device reported property response Topic--pass-through: up_raw_reply

Device reported property request Topic--Alink JSON:  post

Device reported property response Topic--Alink JSON: post_reply

setTopic

 Setting device properties, with the following fields:

Downlink (pass-through) response Topic: down_raw

Downlink (pass-through) response Topic: down_raw_reply

Downlink (Alink JSON) request Topic: set

Downlink (Alink JSON) response Topic: set_reply

eventTopic

 Device event reporting, with the following fields:

Uplink (pass-through) request Topic: up_raw

Uplink (pass-through) response Topic: up_raw_reply

Uplink (Alink JSON) request Topic: post

Uplink (Alink JSON) response Topic: post_reply

serviceTopic

 Device service invocation

Downlink (pass-through) request Topic: down_raw

Downlink (pass-through) response Topic: down_raw_reply

Downlink (Alink JSON) request Topic: identifier

Downlink (Alink JSON) Topic: identifier_reply

 

Related to Connection Setup

Initialize connection settings

public void Init(string DeviceSecret, string RegionId)

 

Generate unique clientId

public string CreateClientId()

 

Create an MQTT connection and communicate with the server, subscribing to the required Topics

public void ConnectMqtt(string[] SubTopic, byte[] QOS = null)

 

Delegates

 Subscription callback - when a message is received from the server

public uPLibrary.Networking.M2Mqtt.MqttClient.MqttMsgPublishEventHandler PubEventHandler;

 

 When QOS=1 or 2, received subscribe trigger

public uPLibrary.Networking.M2Mqtt.MqttClient.MqttMsgPublishedEventHandler PubedEventHandler;

 

 When publishing a Topic to the server

public uPLibrary.Networking.M2Mqtt.MqttClient.MqttMsgSubscribedEventHandler SubedEventHandler;

 

When publishing a Topic to the server fails

public uPLibrary.Networking.M2Mqtt.MqttClient.MqttMsgUnsubscribedEventHandler UnSubedEventHandler;

 

 When disconnected

public uPLibrary.Networking.M2Mqtt.MqttClient.ConnectionClosedEventHandler ConnectionClosedEventHandler;

 

Default Methods

Default_PubEventHandler(object sender, MqttMsgPublishEventArgs e)
public void Default_PubedEventHandler(object sender, MqttMsgPublishedEventArgs e)
public void Default_SubedEventHandler(object sender, MqttMsgSubscribedEventArgs e)
public void Default_UnSubedEventHandler(object sender, MqttMsgUnsubscribedEventArgs e)
public void Default_ConnectionClosedEventHandler(object sender, EventArgs e)

 

Publish Messages

Upload properties or publish Topics

public int Subscribe(string PubTopic, byte[] content)

Upload properties or publish Topics

public int Subscribe(string PubTopic, string content)

Upload properties or publish Topics, the source data will be Base64 encoded before uploading

public int SubscribeToBase(string PubTopic, byte[] betys)

 

Property Upload

Device uploads properties--pass-through

public int Thing_Property_Up_Raw(byte[] bytes)

Customize the device uploading property address, upload properties--pass-through

.

The use of Up_Raw(byte[] bytes) is recommended

public int Thing_Property_Up_Raw(string up_rawTopic, byte[] bytes)

Device attribute upload -- transparent, upload after converting to Base 64 encryption

public int Thing_Property_Up_RawToBase64(byte[] bytes)

Device attribute upload -- transparent, upload after Base 64 encryption -- this method is not recommended

public int Thing_Property_Up_Raw_ToBase64(string up_rawTopic, byte[] bytes)

Upload device attributes -- Alink Json

public int Thing_Property_Post(string json,bool isToLwer=true)

The same as above

public int Thing_Property_Post(byte[] json)

Upload device attributes -- Alink Json

public int Thing_Property_Post<AlinkModel>(AlinkModel model,bool isToLower=true)

 

Set device attributes

Receive server property setting command and return response

public int Thing_Property_set(string content,bool isToLower=true)

The same as above

public int Thing_Property_set(byte[] content)

Device attribute distribution setting

public int Thing_Property_set<SetJson>(SetJson model,bool isToLower=true)

 

Device event reporting

Device event reporting, upload as string content

public int Thing_Event_up_raw(string content)

Device event reporting, upload original message after Base64 encryption

public int Thing_Event_up_raw_Base64(byte[] content)

Device event reporting Alink JSON

public int Thing_Event_Post(string content,bool isToLower=true)

Device event reporting Alink JSON

public int Thing_Event_Post<EventJson>(EventJson model,bool isToLower=true)

 

Device service invocation

Device service invocation -- transparent

public int Thing_Service_Down_Reply(byte[] content)

Device service invocation

public int Thing_Service_Identifier_Reply(string content,bool isToLower=true)

Device service invocation

public int Thing_Service_Identifier_Reply<ServiceJsonModel>(ServiceJsonModel model,bool isToLower=true)

 

It should be noted that in the SDK, whether for ordinary subscriptions, uploading attribute responses, sending setting commands, events, service invocations, etc., any messages “received” from the server will trigger

public uPLibrary.Networking.M2Mqtt.MqttClient.MqttMsgPublishEventHandler PubEventHandler;

If you want to distinguish different received Topics, you need to manually modify the method and bind it to the delegate.

痴者工良

高级程序员劝退师

文章评论