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 and a new project file which I loaded on CodePlex, so that now the library is perfectly compilable with all versions of the .Net Framework (Desktop, Compact and Micro) with Mono in that environment Linux.

To run the tests, I decided not to use the usual RSMB of IBM (under Windows), but the Mosquitto broker, which is also available in the Ubuntu repositories and then easily installed from Synaptic or through:

sudo apt-get install mosquitto

sudo apt-get install mosquitto-clients


The package installs the broker mosquitto while mosquitto-clients installs two sample client (mosquitto_pub and mosquitto_sub) for publishing and subscribing to the message broker. Once installed, no configuration is necessary, because the broker is automatically started and is now listening on port MQTT by default, ie 1883.

   1: using System;
   2: using uPLibrary.Networking.M2Mqtt;
   3: using System.Net;
   4: using System.Text;
   6: namespace M2MqttTest
   7: {
   8:     class MainClass
   9:     {
  10:         public static void Main (string args)
  11:         {
  12:             MqttClient client = new MqttClient(IPAddress.Parse(""));
  13:             client.Connect("testmono");
  15:             client.MqttMsgPublishReceived += HandleClientMqttMsgPublishReceived;            
  16:             client.Subscribe(new string { "sensors/temp" }, new byte { 1 });
  18:             //client.Publish("sensors/temp", Encoding.UTF8.GetBytes("35"), 1);
  20:             Console.ReadLine();
  22:         }
  24:         static void HandleClientMqttMsgPublishReceived (object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e)
  25:         {
  26:             Console.WriteLine(Encoding.UTF8.GetString(e.Message));
  27:         }
  28:     }
  29: }

The console application, created with MonoDevelop, is rather trivial, since it connects to the broker (mosquitto in this case) and subscribes to the topic "sensors / temp", wanting to simulate that is "listening" to a sensor that publishes temperature values​​. The publisher is simulated through the use of client mosquitto_pub with the simple command line:

mosquitto_pub –t sensors/temp –q 1 –m 32

Where the parameter "t" identifies the topic, "q" indicates the QoS according to the MQTT protocol and "m" is the message to be transmitted (in this case a temperature value, ie. 32 °C).

From the image below, we can see that the result is properly captured and displayed on the console by the test application that uses my library.


Similarly, you can use the test application as a publisher and the client mosquitto_sub to receive messages through the following command:

mosquitto_sub –t sensors/temp –q 1


In conclusion, although there are excellent MQTT clients on Internet that can be used without problems on Linux (the same Mosquitto client libraries or many others written in C++, Java or Python), for those who wish can continue to use my library thanks to the support Mono. The next step may be to use this library on an embedded system based on Raspberry Pi!