Temperature sensor regularly posting to Cumulocity - example

Follow

Originally posted by ricardo.marques on 2012-03-21 20:04:23

We have received an email with the following question:

I am trying to do something really simple:

> I want my temperature sensor to regularly post temperature readings to the
> cumulocity site.
>
Now, I believe to create an object "temperature" (whatever you call it in
Cumulocity) on the server-side. In pachube such an object is called stream.
I believe I need a tenant account for that since the offered demo account on
your example does not seem to allow that.

How does the naming of the resources work? In pachube I got a URL when I
created a stream that I then used. For example, it looked like this
http://api.pachube.com/v2/feeds/30381">http://api.pachube.com/v2/feeds/30381

Then, as a next step I want to use CURL to send example sensor readings to
the temperature stream on the cumulocity server.
(I sort of fake the sensor development environment initially.)

Finally, I would like to retrieve all the uploaded data somehow. In pachube
this looks like:

curl –request GET –header "X-PachubeApiKey: *key-goes-in-here*"
http://api.pachube.com/v2/feeds/30381/datastreams/1.json?start=2011-05-20T11">http://api.pachube.com/v2/feeds/30381/d … 1-05-20T11
:01:42Z&end=2011-05-20T11:02:50Z&interval=0

What mechanisms do I have in Cumulocity?

Is it even possible to run upload code to your server to perform the data
analysis (and visualization) already there?

Cumulocity is partially similar to Pachube, but also quite different. Some of the functionality that you use in Pachube is implemented in different way, other functionality may not be present in Cumulocity, some of the functionality in Cumulocity may not be present in Pachube.

Pachube is targeted at end-users directly, so it provides GUI components for creating your objects.

Cumulocity, as you may have already read in our documentation in http://www.cumulocity.com/guides, is targeted at applications, which will use API calls to create and read objects from the system. At this time, Cumulocity does not provide UI components for creating objects. However, we are continuously evolving our system and such components might be made available in the future.

I will start by explaining how this works in Cumulocity and then provide specific example.

The domain model of Cumulocity contains sensors that are part of devices, and it includes a standard representation of temperature sensors, which can be used for achieving this functionality.

In order to create a device with a temperature sensor, one could issue the following command:


curl -X POST -u "«tenant»/«user»:«password»" -h "X-Cumulocity-Application-Key: «application key»" -h "Content-Type: application/vnd.com.nsn.cumulocity.managedObject+json;ver=0.9" -d '{"name" : "A brand new thermometer!", "com_cumulocity_model_environmental_sensor_TemperatureSensor" : {} }' http://developer.cumulocity.com/inventory/managedObjects

That would produce the following example response:


{
  "self" : "«URL of new object»",
  "id"   : "111",
  "name" : "A brand new thermometer!",
  "com_cumulocity_model_environmental_sensor_TemperatureSensor" : {}
}

In order to write measurements for this device, one could use the following command:


curl -X POST -u "«tenant»/«user»:«password»" -h "X-Cumulocity-Application-Key: «application key»" -h "Content-Type: application/vnd.com.nsn.cumulocity.measurement+json;ver=0.9" -d '{"time" : "2012-03-21T12:03:27.845Z",
  "type" : "TemperatureReading",
  "source" : { "id": "111" },"com_cumulocity_model_environmental_measurement_TemperatureMeasurement": { "T": { "value": 23, "unit": "C" } }' http://developer.cumulocity.com/measurement/measurements

Finally, to get measurements for such a device, one could just execute the following command:


curl -X GET -u "«tenant»/«user»:«password»" -h "X-Cumulocity-Application-Key: «application key»" http://developer.cumulocity.com/measurement/measurements?source=111
Have more questions? Submit a request

Comments