Machine 2 Machine with a MQTT .Net Library
- Posted: Jul 19, 2013 at 6:00 AM
- 7,970 Views
Today's Hardware Friday project comes from Paolo Patierno who is helping toward the Internet of Things, Machine to Machine world...
M2Mqtt is a MQTT client available for all .Net platform (.Net Framework, .Net Compact Framework and .Net Micro Framework) for M2M communication.
For all information about MQTT protocol, please visit official site http://mqtt.org/.
MQTT is a machine-to-machine (M2M)/"Internet of Things" connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport. It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium. For example, it has been used in sensors communicating to a broker via satellite link, over occasional dial-up connections with healthcare providers, and in a range of home automation and small device scenarios. It is also ideal for mobile applications because of its small size, low power usage, minimised data packets, and efficient distribution of information to one or many receivers ...
Since I loaded my small MQTT client. Net Framework (Desktop, Compact and Micro) on CodePlex, I have never posted a simple example of the use of time for questions.
In this post, we shall see how it is possible to realize a "simple" alarm system consists of two boards Netduino Plus both connected in the network, through the first board we are able to detect a movement through the use of a PIR (Passive InfraRed) sensor while the second is capable of receiving the notification of the detection (in this case does is to write it on the console Debug). Obviously, the second board may be trivially replaced by a smartphone through which we could be alerted in real time of the intrusion.
Regarding the broker, it is the simple RSMB (Really Small Message Broker) of IBM which can be used in a totally free for non-commercial purposes and downloaded here. You do not need to install it but, in the case of Windows, is a simple executable to be launched in order to have a broker and MQTT listening on the default port (1883). In our example, it is currently running on my PC that acts in a sense as a server.
The trivial application running on the board that serves as part detector is the following:
Pir class is used for the sensor (see uPLibrary on CodePlex), which raises an event at the detection of a movement. Through the class MqttClient connection is made to the broker, and a message is published on the topic "alarm" to report the detection of the sensor.
The application that receives the reports is the following:
It through the MqttClient, does nothing more than to register topic "alarm" through which receives notifications via a message from the sender shot through the broker.
Basically, we have developed a simple Push Notification system that no issue could be exploited through the Internet, perhaps using a Windows Azure Worker Role to perform the broker, since there is no broker written entirely in C#.
Now, no SkyNet building please...