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

Wesley13
• 阅读 514

系列教程目录

(一) 连接阿里云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;

默认的方法

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)

发布消息

上传属性或发布 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,需手动修改方法,将其绑定到委托中。

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
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
Jacquelyn38 Jacquelyn38
2年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Wesley13 Wesley13
2年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
2年前
1. 容器化部署一套云服务 第一讲 Jenkins(Docker + Jenkins + Yii2 + 云服务器))
容器化部署一套云服务系列1\.容器化部署一套云服务之Jenkins(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fwww.cnblogs.com%2Fjackson0714%2Fp%2Fdeploy1.html)一、购买服务器服务器!caeef00
Wesley13 Wesley13
2年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
2年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Stella981 Stella981
2年前
Google地球出现“无法连接到登录服务器(错误代码:c00a0194)”解决方法
Google地球出现“无法连接到登录服务器(错误代码:c00a0194)”解决方法参考文章:(1)Google地球出现“无法连接到登录服务器(错误代码:c00a0194)”解决方法(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fwww.codeprj.com%2Fblo
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
3个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这