.NET Core 跨平台物联网开发:SDK 属性、方法、委托、类(四)

系列教程目录

 (一) 连接阿里云IOT

 (二) 设置委托事件

 (三) 上报属性

 (四)  SDK文档 属性、方法、委托、类

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

下载三个库,头部引入 即可使用

using AliIOTXFClient;

示例下载地址

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

AliIOTXFClient.XFMQTT 类是核心功能

生成设备属性、服务、事件通讯的topic

public readonly ThingModel thingModel

有四个主要属性,用来获取或设置属性、服务、事件的Topic地址。

名称

说明

upTopic

用于上传设备属性数据,有以下几个字段

设备上报属性请求Topic--透传:up_raw

设备上报属性响应Topic--透传:up_raw_reply

设备上报属性请求Topic--Alink JSON: post

设备上报属性响应Topic--Alink JSON:post_reply

setTopic

设置设备属性,有以下几个字段

下行(透传)响应Topic:down_raw

下行(透传)响应Topic:down_raw_reply

下行(Alink JSON)请求Topic:set

下行(Alink JSON)响应Topic:set_reply

eventTopic

设备事件上报,有以下几个字段

上行(透传) 请求Topic:up_raw

上行(透传)响应Topic:up_raw_reply

上行(Alink JSON)请求Topic:post

上行(Alink JSON)响应Topic:post_reply

serviceTopic

设备服务调用

下行(透传)请求Topic:down_raw

下行(透传)响应Topic:down_raw_reply

下行(Alink JSON)请求Topic:identifier

下行(Alink JSON)Topic:identifier_reply

与连接前有关

初始化连接设置

public void Init(string DeviceSecret, string RegionId)

生成唯一clientId

public string CreateClientId()

创建MQTT连接并与服务器通讯,订阅需要的Topic

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

委托

 订阅回调 - 当收到服务器消息时

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

 当 QOS=1或2时,收到订阅触发

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

 向服务器发布 Topic 时

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

向服务器发布 Topic 失败时

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

 断开连接时

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

默认的方法

1Default_PubEventHandler(object sender, MqttMsgPublishEventArgs e) 2 3public void Default_PubedEventHandler(object sender, MqttMsgPublishedEventArgs e) 4 5public void Default_SubedEventHandler(object sender, MqttMsgSubscribedEventArgs e) 6 7public void Default_UnSubedEventHandler(object sender, MqttMsgUnsubscribedEventArgs e) 8 9public void Default_ConnectionClosedEventHandler(object sender, EventArgs e)

发布消息

上传属性或发布 Topic

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

上传属性或发布 Topic

public int Subscribe(string PubTopic, string content)

上传属性或发布 Topic,会将源数据进行 Base 64位加密再上传

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

属性上传

设备上传属性--透传

public int Thing_Property_Up_Raw(byte[] bytes)

自定义设备上传属性地址、上传属性--透传。不建议使用,建议使用 Up_Raw(byte[] bytes)

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

设备上传属性--透传,转为 Base 64位加密后上传

public int Thing_Property_Up_RawToBase64(byte[] bytes)

设备上传属性--透传,Base 64 位加密后上传--不建议使用此方法

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

上传设备属性--Alink Json

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

同上

public int Thing_Property_Post(byte[] json)

上传设备属性--Alink Json

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

设置设备属性

收到服务器属性设置命令,返回响应

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

同上

public int Thing_Property_set(byte[] content)

设备属性下发设置

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

设备事件上报

设备事件上报,以字符串内容上传

public int Thing_Event_up_raw(string content)

设备事件上报,把原始报文 Base64 加密后上传

public int Thing_Event_up_raw_Base64(byte[] content)

设备事件上报 Alink JSON

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

设备事件上报 Alink JSON

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

设备服务调用

设备服务调用--透传

public int Thing_Service_Down_Reply(byte[] content)

设备服务调用

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

设备服务调用

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

需要注意的是,SDK中,无论是普通订阅还是上传属性响应、下发设置命令、事件、服务调用等,凡是“收”到服务器的消息,均是触发

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

如果想区别不同的接收到的Topic,需手动修改方法,将其绑定到委托中。

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

mysql设置时区

mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0

.NET Core 跨平台物联网开发:SDK 属性、方法、委托、类(四) - HelloWorld