系列教程目录

(一) 连接阿里云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,需手动修改方法,将其绑定到委托中。

最新文章

  1. JavaScript String对象
  2. spring session 和 spring security整合
  3. 在 sublime text 3 中添加 Emmet (ZenCoding)
  4. monkey测试(转)
  5. 【Todo】Java Queue Stack Vector ArrayList
  6. 记一个社交APP的开发过程——基础架构选型(转自一位大哥)
  7. 160多个android开源代码汇总
  8. Android EditText中插入图片并响应点击事件
  9. 来杯咖啡看Pecan
  10. 一步步实现滑动验证码,Java图片处理关键代码
  11. Ext JS 6开发实例(一)
  12. Ubuntu16.04安装Qt5.12.2
  13. 如何解决failed to push some refs to git
  14. codeforces478C
  15. tomcat部署-手动启动tomcat部署,添加网页,
  16. Linux学习之RPM包管理-yum管理(十七)
  17. 6个监控linux资源的快速工具
  18. shell 关系运算符
  19. BZOJ4049][CERC2014]Mountainous landscape-[线段树+凸包+二分]
  20. servlet中doGet()和doPost()的区别

热门文章

  1. D. Babaei and Birthday Cake---cf629D(最长上升子序列和+线段树优化)
  2. MongoDB学习day05--MongDB开启权限验证,创建用户
  3. UILable怎样加入单击事件
  4. Storm专题二:Storm Trident API 使用具体解释
  5. ZOJ 3632 Watermelon Full of Water (线段树 区间更新 + dp)
  6. iOS用户体验之-modal上下文
  7. Scrum 时间估算
  8. iOS + Nodejs SSL/Https双向认证
  9. ios开发--NSDate与NSDateFormatter的相关用法【转】
  10. PyTorch 60 分钟入门教程:数据并行处理