Connecting a Generic Sensor/App to the Karotz Rabbit

Several users asked us to show a simple way to connect a Generic Sensor, device or application to a Karotz smart rabbit using Paraimpu. In a previous post in this blog we described how to connect your Karotz to Paraimpu and how to test it.
We remind you to that article for basic, preliminary steps.

Now, we want to connect a Generic Sensor, producing text messages, to Karotz in order to make the rabbit read the sent message through its text-to-speech feature.

The simplest way to do it with Paraimpu is the following.

1. Create the Generic Sensor

From the palette click on the generic sensor icon:

and fill the creation form as follows (obviously you can assign to the sensor the name you prefer):

Click the Register Sensor button: in this way you've created a sensor which produces text messages named MySens.

2. Add the Karotz Actuator
Following the steps in the previous blog post, add your Karotz to your Paraimpu workspace, naming it, for example MyKarotz.
At this step, your Karotz should be properly configured and tested.

3. Connect the Generic Sensor to Karotz

In the workspace, connect the Generic Sensor to the rabbit using the connect button on the sensor:

and selecting the rabbit in the pop-up box.

4. Configure the Connection

Go to the created Connection page, clicking on the manage button

Here comes the funny part.
We need to instruct Paraimpu to act as follows:

WHEN a text message comes from MySens, THEN let MyKarotz read it.

To do that we need to create a mapping in the connection configuration page.
Generally, in Paraimpu, a mapping is a boolean condition on data coming from the sensor (the match, expressed using JavaScript) which defines WHEN Paraimpu must apply the mapping,  followed by another JavaScript expression  (the replace, written inside <% %> tags) which defines WHICH data Paraimpu must send to the actuator (in other words, a mapping is the definition of a data transformation, applied to data flowing from a sensor to the connected actuator).

When possible, as in our case, Paraimpu helps you defining the replace expression providing a graphical widget which composes under the scene the JavaScript for us.

Thus, for our scenario, a mapping like the following defines the desired behavior (click to enlarge):

Important: don't forget to activate the connection!

5. Connect the created Paraimpu Sensor to your real object or application
For each sensor added, Paraimpu provides a well-defined API to connect the real physical object or application in order to send data to the system.
In our case, if you open the page for MySens object you will always find the API documentation as follows:

Thus, from your device or software application, making an HTTP POST to /data/new URL and sending a JSON with the right token (as specified in your sensor page) allows you to send data to the corresponding Generic Sensor in Paraimpu.

If all it's OK, then sent data will be automatically transformed and sent to Karotz according to the specified mapping(s).

That's all.

Leave a Reply

© 2014-2015 Paraimpu Srl . Powered by Blogger.