http://pan.whuanle.cn/index.php?dir=uploads/阿里云IOT/AliIOTXFclient-dll类库&responsephp
下载三个库,头部引入 便可使用html
using AliIOTXFClient;
示例下载地址json
http://pan.whuanle.cn/index.php?dir=uploads/阿里云IOT/demo示例服务器
AliIOTXFClient.XFMQTT 类是核心功能ide
public readonly ThingModel thingModel
有四个主要属性,用来获取或设置属性、服务、事件的Topic地址。post
名称 | 说明 |
upTopic | 用于上传设备属性数据,有如下几个字段阿里云 设备上报属性请求Topic--透传:up_raw 加密 设备上报属性响应Topic--透传:up_raw_replyspa 设备上报属性请求Topic--Alink JSON: postcode 设备上报属性响应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,需手动修改方法,将其绑定到委托中。