Senior Software Engineer, Microsoft MVP on Windows Embedded and IoT. Devices to cloud, IoT, M2M and embedded systems.
The development of this project began in April of this year with the objective of filling the absence of a good MQTT client for all .Net platforms. After 6 months I did not expect an interest so strong against him, probably due to the wave of the Internet of Things that is coming (or is already among us ? ) .
Many people are using the library for projects of varying complexity , they send me mails ( with reports but also with compliments ) and open the "issue" on the CodePlex site , which I promptly resolve .
This can push me to get better and better the quality of the project , now arrived at version 2.3.0 with some bug fixes but also with an interesting new feature : all the events raised by the MqttClient class ( published message , the received message , ...) are executed in a separate thread , so the user no longer has to worry about launch "long" processing in his event handler through a new thread.
With this update, I hope to have made further improvements of great interest for those who ...
I made a bug fix on my Library M2Mqtt (MQTT client) that allows you to better manage the case where the client does not transmit anything for a time equal to the "keep alive period " and the keep alive thread, whose task is to ping the broker to keep the connection alive, does not receive anything within the timeout period (ex. broker shutdown, network disconnection, ...).
The update is already available on CodePlex and Nuget !
Today I have opened Visual Studio 2012 and I have clicked on "New Project" and magically have discovered that .... it freezes and does not show me the templates list!
The problem is typically due to the templates list which is "polluted" by all SDKs that we install. To solve it, I made sure that Visual Studio regenerate the templates cache, as follows:
When you restart Visual Studio ... everything worked again!
I have just updated on CodePlex and Nuget my uPLibrary library (version 220.127.116.11), adding automatic detection of any IPv6 address to the HTTP client (HttpClient class) .
To determine the address class (AddressFamily), I implemented the '"Extension Method" GetAddressFamily () for the IPAddress class through the static class IPAddressUtility, needed only because the. NET Micro Framework does not itself provide the property AddressFamily in the IPAddress class.
1: public static AddressFamily GetAddressFamily(this IPAddress ipAddress)
3: return (ipAddress.ToString().IndexOf(':') != -1) ?
4: AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork;
In this way, at the time of the creation of the socket, it is automatically set to the correct address family from the address to connect to.
1: // create socket and connect
2: this.socket = new Socket(
4: Sock ...
After releasing the new version of my M2Mqtt library with support for SSL / TLS with server-side authentication, the time has come to show you an example of use.
Choose and install the broker: Mosquitto
First we have to choose an MQTT broker among those available but unfortunately no one is developed using the .Net Framework . Discarding more complex solutions , especially with regard to the installation and configuration , such as IBM Websphere , we can take into account to brokers like RabbitMQ , HiveMQ or Mosquitto. In this case , my choice was Mosquitto that we can download from the official web site for various operating systems based on Linux , as well as there is a convenient installer for the Windows environment . In fact, for Windows there are two installation modes: the first uses an installer in which the broker is compiled natively while in the second case is based on the Cygwin provides a Linux-like environment for Windows. It 'obvious that the first mode is the most simple and immediate . Afte ...
I just updated only on CodePlex (for now) M2Mqtt library (version 18.104.22.168), adding the automatic detection of any IPv6 address to connect.
To determine the address class (AddressFamily), I implemented the '"Extension Method" GetAddressFamily() for the IPAddress class through the static class IPAddressUtility, necessary only because the. NET Micro Framework does not itself provide the property AddressFamily the IPAddress class. In fact, in the case of full / compact. Net Framework is returned that property while in the case of. NET Micro Framework is done by a simple search of the ":" character (separator in IPv6 addresses).
1: public static AddressFamily GetAddressFamily(this IPAddress ipAddress)
3: #if (!MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3)
4: return ipAddress.AddressFamily;
6: return (ipAddress.ToString().IndexOf(':') != -1) ?
7: AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork;
I finally got what I wanted to add some time to my Library M2Mqtt : support for the SSL / TLS protocol !
With this new feature , you can now connect to a MQTT broker also using SSL / TLS (for .NET Micro Framework only up to TLS1.0 ) to take advantage of its key features: data encryption and server authentication through an X509 certificate (client authentication is not supported) .
To leave free choice to the developer wanted to or not to include this feature in his project ,I tied everything to the compilation symbol "SSL" which must be defined to add such support. In this way, for some platforms with less memory (see Netduino or FEZ Cerberus in the case of .NET Micro Framework ), you can exclude it , remembering to remove all references to assemblies that run the SSL / TLS.
Of course , as well as on CodePlex, the update is also available on Nuget !
As soon as possible, I will write a new post in which I describe an example of using secure connection with an MQTT broker like Mosquitto !
Today I published my M2Mqtt library on Nuget, besides being already available for some time on CodePlex.
I've included the compiled assemblies for the. Net Framework 4.0 and 4.5 and for the. NET Micro Framework 4.2 and 4.3.
I hope I have done something pleasing for those who until now have used it by downloading the source files directly from CodePlex.
Despite my M2Mqtt is written in C #, so it is guaranteed to work on .Net Framework versions in a Microsoft Windows environment, it is absolutely possible to use it on Linux through the Mono Project.
First, I prepared the environment with a Linux distribution using the most famous and widely used in desktop environment: Ubuntu (12.04 LTS). The operating system does not provide native support for Mono, which you need to download and install through the Synaptic package manager or through the terminal using the following command:
sudo apt-get install mono-complete
The package mono-complete installs pretty much everything, both the runtime libraries for developing applications based on that framework.
Next, I chose the MonoDevelop IDE to compile the M2Mqtt library with the Mono compiler and to be able to create a simple console application to test. Even in this case, we can make use of Synaptic or the command:
sudo apt-get install monodevelop
Taking advantage of this IDE, I created a new solution an ...
I have made a "small" update on my MQTT client (now at version 22.214.171.124), adding an additional constructor on MqttClient class which has the host name of the broker as parameter (adding to the constructor that provides only the address IP). Such a constructor may be useful in all those cases in which you use a MQTT public broker , such as the Mosquitto test server that is at test.mosquitto.org.
1: public static void Main()
3: MqttClient client = new MqttClient("test.mosquitto.org");
View this page in another language: