UPDATE: Connecting a Cosm sensor to Paraimpu

NOTE: This tutorial has been UPDATED in order to reflect the changes made by Pachube migrating to Cosm.

Goal: Register on Paraimpu a Sensor data stream from Cosm and then connect it to the Twitter Actuator, then configure the connection to tweet only if a given condition is satisfied. 
Once the Cosm Sensor is registered you can connect it to any Paraimpu Actuator available in your dashboard.

First step
: Please Log-in to Cosm and Paraimpu with the respective credentials. 
If you don’t have credential in one or both systems then create your profiles according to the respective procedures.

Second step:

On Cosm Web site select a feed, for instance: https://cosm.com/feeds/21510

and annotate the chosen datastream number, for example, the "radiation" datastream index for the selected feed is "6", as in the following snapshot:

This particular datastream will produce JSON data like the following:

{"at":"2012-07-17T12:40:20.706831Z","tags":["Radiation","SBM-20"],"unit":{"symbol":"µSv/h","type":"basicSI","label":"microsievert per hour"},"max_value":"0.49583","id":"6","version":"1.0.0","current_value":"0.10249","min_value":"0.00277"}

Third step:
Go to Paraimpu and create a new Cosm Sensor from the palette. Configure it as in the following snapshot:

You’ll find your Cosm API key under Cosm Home, Account section (on the upper-right of the page) -> Keys.
Copy and paste your personal key in the Paraimpu API Key form field.

Then click Register and the Sensor is added and ready. 
After some minutes data will flow. 
At the moment (release 0.8.5) the polling time is fixed in 120 secs. In next releases this value will be fully configurable.

Fourth step:
Create a Twitter Actuator in the Paraimpu workspace, unless you already have one.

Fifth step:
Create a connection between the Pachube datastream and Twitter. 
To do that click the Connect to... button on the just created Radiation Cosm Sensor widget

and select the existing Twitter Actuator in the pop-up list of available Actuators.

Sixth step:
Configure the just created new connection clicking on its manage button:

The connection details page will be showed. Configure the connection as follows:

Filters and mappings are expressed by means of regular Javascript expressions. 
Given the JSON structure of Cosm datastreams (see above), the filter condition:

 Radiation.current_value > 0.11

ensures that only data greater than 0.11 µSv/h are sent from Sensor to the connected Actuator.

Similarly, the mapping is defined by a condition and by a string containing a template (a expression between <% and %>), which is a regular Javascript expression. 

In this case the mapping means:

IF Radiation.current_value > 0.11 THEN send to Twitter the given text.

Finally, don't forget to activate your connection clicking on the Activate button.

As data starts to flow from Cosm, check your Twitter timeline!
That's all!

Leave a Reply

© 2014-2015 Paraimpu Srl . Powered by Blogger.