Using Analytics Module

In this post we would like to talk about the Analytics Module that we just made public few weeks ago.
The idea behind this module is that any status can be saved in Lhings platform. Once you have save it, you will be able to visualize them in the site or even get different records to visualize them yourself.

If you have developed and app and would like to save the values and use the Analytics Module, you can have a look at the API Reference that stores values and the API Reference for retreiving values

In our example, what we did is we measured the temperature in Barcelona for 1 month and saved this data. We had a Raspberry Pi that would measure the temperature,make an average of the day and then saves this data. We would also save in the server if it was raining that day.

Lets have a look at the graphics we got from our data:

1- First of all we have the Date selector. Here you will be able to adjust the data you want to show between the dates you have saved the values.
post_0

We selected all the days that we have saved the values, that means, for 1 month.

2- After selecting the days, you will see that for each value/status saved, you have its representative chart. The first one we see is the chart of the climate, where we see if in those days the weather was COLD, MEDIUM or HOT. We made this values depending on the temperature of the day.
post_1

3- Next values that we see are the values referred to the Temperature. For each day, we saved the medium temperature of the day.
post_3

4- Finally we see the final chart referring to the rain status.
post_4

So, we saw the charts, but… how do we save this data? In the support documentation, we can see how this data is stored, check this link.
What we did was an application for Raspberry Pi that would save the values every time we specify. We did it in Java using our Java Library (available in GITHUB) and doing some webservice’s calls. Given this example from the Support Page:
Screen Shot 2014-07-07 at 13.55.32
We made:
Screen Shot 2014-07-07 at 13.58.23
Some notes about this code:
- UUID_app : this value is a string that has the UUID from the current device created. To get this UUID, you can call the method uuid() from LhingsDevice (remember, this is JAVA). Here is the JavaDoc
- timeStamp : This is not compulsory, if you don’t put it, it will save it to the current day.
- apikey : this is your api key. You will find your api key in your user profile inside Lhings platform.
- json_s : this is the body you will send to be saved. It’s a string formatted JSON. In our case looks something like:

“{ \”climate\”: \””+this.climate+”\”, \”temperature\”: “+this.temperature+”,\”rainy\”: “+this.rainy+”}”;

We hope this tutorial was helpful for you. If you have any doubts or comments, please drop us a line here. We are looking forward to hear from you and see what your project is about!