Now you can find numerous online platforms that offer the service of "device to the cloud," in order to acquire data from remote devices, save and expose them to other devices: one of these is 2lemetry.

It provides a RESTful interface over HTTP and an MQTT interface that we are going to use with the M2Mqtt client library.

First you need to register online :

01_register

At the end of the registration, you can log in to your account page and view some information, including the most important one is the "domain", which will be the root of all topics on which we are going to publish or receive messages via MQTT.

At this point we can move immediately to develop a simple application by choosing between all platforms supported by the M2Mqtt library (.NET Framework, .Net Compact Framework or. Net Micro Framework). In a real case, we use the Netduino Plus board with a temperature sensor (usually the TMP102 already widely used in previous posts and where the driver can be found in uPLibrary) to send the data collected online.

First we define all the parameters necessary to 2lemetry to load the data:

   1: const string M2MIO_DOMAIN = "<domain>";
   2: const string M2MIO_CLIENTID = "device1";
   3: const string M2MIO_STUFF = "temp";
   4: const string M2MIO_BROKER = "q.m2m.io";
   5: const string M2MIO_USERNAME = "<username>";
   6: const string M2MIO_PASSWORD = "<MD5password>";

It needs the address of the broker (which uses the standard port 1883), the client ID, what is called "stuff" which in our case will be the temperature, the domain, and finally the username and MD5 of the password used for registration.

The application is trivially follows:

 

   1: TMP102 tmp102 = new TMP102(A0AddressSelect.GND, 100);
   2:  
   3: MqttClient client = new MqttClient(M2MIO_BROKER);
   4: client.Connect(M2MIO_CLIENTID, M2MIO_USERNAME, M2MIO_PASSWORD);
   5: string topic = M2MIO_DOMAIN + "/" + M2MIO_STUFF + "/" + M2MIO_CLIENTID;
   6:  
   7: while (true)
   8: {
   9:     float value = tmp102.Temperature();
  10:     client.Publish(topic, Encoding.UTF8.GetBytes("{ \"value\" : " + value + " }"));
  11:     Thread.Sleep(5000);
  12: }

In this way, every 5 sec the value of the temperature will be published on the topic <domain>/temp/device1.

To view the data, we can take advantage of the online platform made ​​available by 2lemetry at http://mqtt.io/. First we have to set session options, username and password of our account.

02_options

After you must specify the address of the broker, the port and client Id to be able to connect. Once connected, using the subscriber section, we subscribe to the topic on which our board publishes the data.

03_subscriber

In less than 10 minutes we set up a station for temperature sensing that public data online on a platform that save them for us and with its tools allows you to analyze and publish them maybe via HTTP !