M2Mqtt is a MQTT client available for all .Net platform
Introduction
M2Mqtt is a MQTT client available for all .Net platform (.Net Framework, .Net Compact Framework and .Net Micro Framework) for Internet of Things and M2M communication.
MQTT, short for Message Queue Telemetry Transport, is a light weight messaging protocol that enables embedded devices with limited resources to perform asynchronous communication on a constrained network.
MQTT protocol is based on publish/subscribe pattern so that a client can subscribe to one or more topics and receive messages that other clients publish on these topics.
This sample is a library contains an MQTT client that you can use to connect to any MQTT broker. It is developed in C# language and works on all the following .Net platforms :
- .Net Framework (up to 4.5)
- .Net Compact Framework 3.5 & 3.9 (for Windows Embedded Compact 7 / 2013)
- .Net Micro Framework 4.2 & 4.3
- Mono (for Linux O.S.)
It can be used on Windows O.S, Windows Embedded Compact 7 / 2013 and Linux O.S. (thanks to Mono Project).
Official web site on CodePlex : https://m2mqtt.codeplex.com/
Building the Sample
The library is available for the following solution and project files :
- M2MqttVS2012.sln : solution for Visual Studio 2012 that contains projects file for .Net Framework, .Net Compact Framework 3.9, .Net Micro Framework 4.2 and .Net Micro Framework 4.3;
- M2MqttVS2010.sln : solution for Visual Studio 2010 that contains projects file for .Net Framework and .Net Micro Framework 4.2;
- M2MqttVS2008.sln : solution for Visual Studio 2008 that contains project file for .Net Compact Framework 3.5;
- M2MqttMono.sln : solution for MonoDevelop for building project under Linux O.S. with Mono Project;
In this sample there is only the Visual Studio 2012 solution but on the CodePlex web site https://m2mqtt.codeplex.com/ all other versions are available.
To build sample based on .Net Micro Framework (4.2 and 4.3) you need to download .Net Micro Framework SDK from the official CodePlex web site : https://netmf.codeplex.com/
To build sample based on .Net Compact Framework 3.9 you need to download Application Builder for Windows Embedded Compact 2013 from here : http://www.microsoft.com/en-us/download/details.aspx?id=38819
Description
The M2Mqtt library provides a main class MqttClient that represents the MQTT client to connect to a broker. You can connect to the broker providing its IP address or host name and optionally some parameters related to MQTT protocol.
After connecting to the broker you can use Publish() method to publish a message to a topic and Subscribe() method to subscribe to a topic and receive message published on it. The MqttClient class is events based so that you receive an event when a message is published to a topic you subscribed to. You can receive event when a message publishing is complete, you have subscribed or unsubscribed to a topic.
Following an example of client subscriber to a topic :
...
// create client instance
MqttClient client = new MqttClient(IPAddress.Parse(MQTT_BROKER_ADDRESS));
// register to message received
client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
string clientId = Guid.NewGuid().ToString();
client.Connect(clientId);
// subscribe to the topic "/home/temperature" with QoS 2
client.Subscribe(new string[] { "/home/temperature" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
...
static void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
{
// handle message received
}
Following an example of client publisher to a topic :
...
// create client instance
MqttClient client = new MqttClient(IPAddress.Parse(MQTT_BROKER_ADDRESS));
string clientId = Guid.NewGuid().ToString();
client.Connect(clientId);
string strValue = Convert.ToString(value);
// publish a message on "/home/temperature" topic with QoS 2
client.Publish("/home/temperature", Encoding.UTF8.GetBytes(strValue), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE);
M2Mqtt is a MQTT client available for all .Net platform的更多相关文章
- python mqtt client publish操作
使用Python库paho.mqtt.client 模拟mqtt client 连接broker,publish topic. #-*-coding:utf-8-*- import paho.mqtt ...
- mqtt client python example
This is a simple example showing how to use the [Paho MQTT Python client](https://eclipse.org/paho/c ...
- go ---MQTT client
Paho GO Client 语言 GO 协议 EPL AND EDL 官网地址 http://www.eclipse.org/paho/ API类型 Asynchronous 描述 Paho ...
- mqtt client api: 阻塞API
fusesource版本:mqtt-client-1.11.jar下载地址:https://github.com/fusesource/mqtt-client fusesource提供三种mqtt c ...
- MQTT Client library for C (MQTT客户端C语言库-paho)
原文:http://www.eclipse.org/paho/files/mqttdoc/MQTTClient/html/index.html 来自我的CSDN博客 最近在使用Paho的MQTT客 ...
- MQTT Server搭建(apache-apollo)和MQtt Client搭建
目标 本文就MQTT server和client搭建做以下总结,方便测试及开发使用,能基于MQTT软件发送和接收消息. 介绍 MQTT是基于tcp的消息发送,目前JAVA方面有两种实现,分别是mqtt ...
- php mqtt client
<?php /* phpMQTT */ class phpMQTT { private $socket; /* holds the socket */ private $msgid = 1; / ...
- Asynchronous MQTT client library for C (MQTT异步客户端C语言库-paho)
原文:http://www.eclipse.org/paho/files/mqttdoc/MQTTAsync/html/index.html MQTT异步客户端C语言库 用于C的异步 MQTT 客 ...
- 一套权威的 MQTT Client 库
主流的语言都支持,可链接到 github ,亲测golang client 简单好用 http://www.eclipse.org/paho/downloads.php
随机推荐
- ZJOI2018 day2游记
省选讲课:还不错吧 ZJOI RP++ Day2: 题出的好!覆盖知识点广,题目又着切合实际的背景,解法比较自然. 给出题人点赞 ! 意识模糊地点开了题(考前不熬夜似乎还是很困qaq) T1:前一个小 ...
- php <a href></a>链接地址中是php变量,链接文本也是php变量的代码处理方法
1.所用php变量名为$recent_tests,是一个二维数组,示例如下: $recent_tests[0]["test_url"] = www.baidu.com $recen ...
- Codeforces Round #298 (Div. 2) E. Berland Local Positioning System 构造
E. Berland Local Positioning System Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.c ...
- HOWTO: Get the command line of a process(转)
How would you get the command line of a process? Some people have suggested that you use remote thre ...
- VB.NET章鱼哥出品—怎样解决MDI子窗口被父窗口中的控件覆盖的问题
近期有个网友问我这个问题,我就上网搜了下,结果非常失望.有几个在CSDN上发的求助帖.看到最后都没有找到明白的答案. 这里笔者在网上找到了API函数SetParent(),并对网上的错误进行了改动,并 ...
- Bootstrap 3之美01-下载并引入页面
本篇主要包括: ■ 下载Bootstrap 3■ Bootstrap 3引入页面 下载Bootstrap 3 →打开网站:http://getbootstrap.com/→点击屏幕中央位置的Down ...
- msgpack配合FIREDAC传输多表数据
msgpack配合FIREDAC传输多表数据 procedure TForm1.Button1Click(Sender: TObject);var ms, ms2: TMemoryStream; pa ...
- 值得借鉴的Objective-C编程规范
Daniel's Objective-C Coding Style Guidelines http://google-styleguide.googlecode.com/svn/trunk/objcg ...
- chromium对网页获取favicon
每一个网页都有一个favicon,在历史记录的保存中须要用到.在content文件夹下,这个没有实现. 以下说一下我的实现过程: web_contents_impl.cc文件里有方法:WebConte ...
- 跟我学AngularJs:AngularJs入门及第一个实例
林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:主要给大家介绍了AngularJs及其特性,并以3个实例来做说明. 本教程使用Angul ...