文档目录: <>

* 说明 <https://www.cnblogs.com/whuanle/p/10994645.html>
* 1. 连接阿里云物联网 <https://www.cnblogs.com/whuanle/p/10994663.html>
* 2. IoT 客户端 <https://www.cnblogs.com/whuanle/p/10994673.html>
* 3. 订阅Topic与响应Topic <https://www.cnblogs.com/whuanle/p/10994686.html>
* 4. 设备上报属性 <https://www.cnblogs.com/whuanle/p/10994694.html>
* 4.1 上报位置信息 <https://www.cnblogs.com/whuanle/p/10994696.html>
* 5. 设置设备属性 <https://www.cnblogs.com/whuanle/p/10994701.html>
* 6. 设备事件上报 <https://www.cnblogs.com/whuanle/p/10994707.html>
* 7. 服务调用 <https://www.cnblogs.com/whuanle/p/10994708.html>
* 8. 委托事件 <https://www.cnblogs.com/whuanle/p/10994713.html>
* 9. 自定义委托事件方法
<https://www.cnblogs.com/whuanle/p/10994720.html>
 

CZGL.AliIoTClient 有7个委托事件,设置了默认的方法。 你可以通过下面的方法使用默认的方法绑定到委托事件中。
public void UseDefaultEventHandler()

<https://gitee.com/whuanle/CZGL.AliIoTClient/wikis/9.%20%E8%87%AA%E5%AE%9A%E4%B9%89%E5%A7%94%E6%89%98%E4%BA%8B%E4%BB%B6%E6%96%B9%E6%B3%95?sort_id=1479199#1%E9%BB%98%E8%AE%A4%E7%9A%84%E6%96%B9%E6%B3%95>
1)默认的方法

收到服务器下发属性设置时:
public void Default_PubPropertyEventHandler(object sender,
MqttMsgPublishEventArgs e)
收到服务器调用服务命令时:
public void Default_PubServiceEventHandler(object sender,
MqttMsgPublishEventArgs e)
收到普通Topic、上传数据的响应等其它情况:
public void Default_PubCommonEventHandler(object sender,
MqttMsgPublishEventArgs e)
收到服务器QOS为1的推送
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, System
.EventArgs e)

<https://gitee.com/whuanle/CZGL.AliIoTClient/wikis/9.%20%E8%87%AA%E5%AE%9A%E4%B9%89%E5%A7%94%E6%89%98%E4%BA%8B%E4%BB%B6%E6%96%B9%E6%B3%95?sort_id=1479199#2%E6%96%B9%E6%B3%95%E7%9A%84%E5%86%99%E6%B3%95>
2)方法的写法

不同的委托参数不同,有好几种类型,参考笔者的方法使用参数。
/// 一般的推送 /// </summary> /// <param name="sender"></param> /// <param name="e">
</param>public void Default_PubCommonEventHandler(object sender,
MqttMsgPublishEventArgs e) {// handle message received string topic = e.Topic;
string message = Encoding.ASCII.GetString(e.Message); Console.WriteLine("- - -
- - - - - - - "); Console.WriteLine("get topic message,Date: " +
DateTime.Now.ToLongTimeString()); Console.WriteLine("topic: " + topic);
Console.WriteLine("get messgae :\n" + message); } /// <summary> /// 收到属性设置 ///
</summary>/// <param name="sender"></param> /// <param name="e"></param> public
voidDefault_PubPropertyEventHandler(object sender, MqttMsgPublishEventArgs e) {
// handle message receivedstring topic = e.Topic; string message =
Encoding.ASCII.GetString(e.Message); Console.WriteLine("- - - - - - - - - - ");
Console.WriteLine("get topic message,Date: " +
DateTime.Now.ToLongTimeString()); Console.WriteLine("topic: " + topic);
Console.WriteLine("get messgae :\n" + message); } /// <summary> /// 收到服务调用 ///
</summary>/// <param name="sender"></param> /// <param name="e"></param> public
voidDefault_PubServiceEventHandler(object sender, MqttMsgPublishEventArgs e) {
// handle message receivedstring topic = e.Topic; string message =
Encoding.ASCII.GetString(e.Message); Console.WriteLine("- - - - - - - - - - ");
Console.WriteLine("get topic message,Date: " +
DateTime.Now.ToLongTimeString()); Console.WriteLine("topic: " + topic);
Console.WriteLine("get messgae :\n" + message); } /// <summary> ///
收到服务器QOS为1的推送/// </summary> /// <param name="sender"></param> /// <param
name="e"></param> public void Default_PubedEventHandler(object sender,
MqttMsgPublishedEventArgs e) { Console.WriteLine("- - - - - - - - - - ");
Console.WriteLine("published,Date: " + DateTime.Now.ToLongTimeString());
Console.WriteLine("MessageId: " + e.MessageId + " Is Published: " +
e.IsPublished); }/// <summary> /// 向服务器推送成功 /// </summary> /// <param
name="sender"></param> /// <param name="e"></param> public void
Default_SubedEventHandler(object sender, MqttMsgSubscribedEventArgs e) {
Console.WriteLine("- - - - - - - - - - "); Console.WriteLine("Sub topic,Date: "
+ DateTime.Now.ToLongTimeString()); Console.WriteLine("MessageId: " +
e.MessageId); Console.WriteLine("List of granted QOS Levels: " +
Encoding.UTF8.GetString(e.GrantedQoSLevels)); }/// <summary> /// 推送失败 ///
</summary>/// <param name="sender"></param> /// <param name="e"></param> public
voidDefault_UnSubedEventHandler(object sender, MqttMsgUnsubscribedEventArgs e)
{ Console.WriteLine("- - - - - - - - - - "); Console.WriteLine("Sub topic
error,Date: " + DateTime.Now.ToLongTimeString()); Console.WriteLine("MessageId:
" + e.MessageId); }/// <summary> /// 连接发生异常,断网等 /// </summary> /// <param
name="sender"></param> /// <param name="e"></param> public void
Default_ConnectionClosedEventHandler(object sender, EventArgs e) {
Console.WriteLine("- - - - - - - - - - "); Console.WriteLine("Connect Closed
error,Date: " + DateTime.Now.ToLongTimeString()); }

友情链接
ioDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:637538335
关注微信