/wp-content/uploads/2015/10/d_shop_blog_logo_808453.jpg

If you are an SAP Employee, please follow us on Jam.



Node-RED is a visual tool for wiring the Internet of Things.

/wp-content/uploads/2015/10/node_red_808430.png

In other words…it’s NodeJs with a nice visual interface.

In order to make it work, we can do the following.

Download NodeJS version 0.10.X for your corresponding architecture and OS.

Linux Binaries 32Bits or 64Bits.

Mac OS X Installer

Windows Installer 32Bits or 64Bits.

I used Linux and here’s the most practical way to install it…

After downloading the package simply do..


sudo tar C /usr/local stripcomponents 1 xzf nodev0.10.36linuxx86.tar.gz

With that, NodeJS should be up and running…so now it’s time for Node-RED.


sudo npm install -g node-red

As easy as that 🙂 Now, simply run node-red on the terminal and open a browser with http://localhost:1880

NodeRed_Editor.jpg

Well…no example or demonstration would be complete if we didn’t hook it up with SAP HANA, right? So…let’s go and do it 😉

First, we need to create a Calculation View and call it “FLIGHTS_BY_CARRIER”. It will be composed of two tables, SCARR and SFLIGHT.

Next, create a Join object and link the table by MANDT and CARRID. From here select the following fields as output MANDT, CARRID,

CARRNAME, PRICE and CURRENCY.

Then create an Aggregation object selecting the fields CARRNAME, PRICE (As Aggregated Column) and CURRENCY. Filter the CURRENCY field by ‘USD’.

Then create a Projection object and select only PRICE and CARRNAME.


On the Semantics object make sure to select “CROSS CLIENT” as the Default Client.

Calculation_View.jpg

Now, switch to the SAP HANA Development View and create a new repository. Call it “Flights”.

Create a new “XS Engine” project and call it “Flights” as well. Link it to the “Flights” repository.

Create an empty “.xsapp” file.


Create a file called “.xsaccess” with the following code.

.xsaccess

{

“exposed” : true,

“authentication” : [ { “method” : “Basic” } ]

  }

Finally create a file called “flights.xsodata” with the following code


flights.xsodata

service {

          “Blag/FLIGHTS_BY_CARRIER.calculationview” as “FLIGHTS” keys generate local “Id”;

  }


Activate your project and launch it on your browser, you should see something like this…

XSProject.jpg

The SAP HANA part is done…so we can move into the Node-RED part…

First, select the http node and fill in /hana in the url section

/wp-content/uploads/2015/10/http_node_808440.jpg

/wp-content/uploads/2015/10/http_node_attr_808441.jpg

Now, select the http request node and fill in the URL

http://yourserver:8000/Flights/flights.xsodata/FLIGHTS?$format=json

And the rest of the data…

/wp-content/uploads/2015/10/http_request_node_808451.jpg

/wp-content/uploads/2015/10/http_response_node_attr_808447.jpg

Now, select a Function node and fill in the following source code…

/wp-content/uploads/2015/10/function_node_808452.jpg

function

var results = msg.payload.d.results;

var message = “”;

for (i=0;i<results.length;i++){

    var carrname = results[i].CARRNAME;

    var price = results[i].PRICE;

    message += carrname + ‘ : ‘ + price + “\n”;

}

msg.payload = message;

return msg;

/wp-content/uploads/2015/10/function_node_attr_808455.jpg

Select a template node and simply pass this…


/wp-content/uploads/2015/10/template_node_808456.jpg


{{payload}}


/wp-content/uploads/2015/10/template_node_attr_808457.jpg

Finally, select an http response node and name if you want 🙂


/wp-content/uploads/2015/10/http_response_node_808458.jpg

/wp-content/uploads/2015/10/http_request_node_attr_808459.jpg

In the end…you should end up with something like this 😉

NodeRed_Sheet.jpg

We’re done 🙂 And BTW…if you don’t feel like doing anything like this…you can always copy this code and import it back to Node-RED…

Node_Red_HANA.json
[{“id”:”4ae9ba82.b51644″,”type”:”http in”,”name”:””,”url”:”/hana”,”method”:”get”,”x”:155,”y”:91,”z”:”3c0f3fe4.c3f0c”,”wires”:[[“ded8853e.212778”]]},{“id”:”ded8853e.212778″,”type”:”http request”,”name”:”HANA”,”method”:”GET”,”ret”:”obj”,”url”:”http://54.65.196.224:8000/Flights/flights.xsodata/FLIGHTS?$format=json“,”x”:329,”y”:102,”z”:”3c0f3fe4.c3f0c”,”wires”:[[“c177bd31.3e884”]]},{“id”:”c177bd31.3e884″,”type”:”function”,”name”:”GetInfo”,”func”:”var results = msg.payload.d.results;\n//var message = [];\nvar message = \”\”;\nfor (i=0;i<results.length;i++){\n    var carrname = results[i].CARRNAME;\n    var price = results[i].PRICE;\n    //message[i] = carrname + ‘ : ‘ + price + \”\\n\”\n    message += carrname + ‘ : ‘ + price + \”\\n\”;\n}\n\nmsg.payload = message;\nreturn msg;”,”outputs”:1,”valid”:true,”x”:507,”y”:179,”z”:”3c0f3fe4.c3f0c”,”wires”:[[“c59088cb.3a6f78”]]},{“id”:”1995c536.e66a3b”,”type”:”http response”,”name”:”Response”,”x”:653,”y”:359,”z”:”3c0f3fe4.c3f0c”,”wires”:[]},{“id”:”c59088cb.3a6f78″,”type”:”template”,”name”:”Template”,”field”:”payload”,”format”:”handlebars”,”template”:”{{payload}}”,”x”:487,”y”:321,”z”:”3c0f3fe4.c3f0c”,”wires”:[[“1995c536.e66a3b”]]}]

/wp-content/uploads/2015/10/node_red_import_808461.jpg

To run it…simply select “Deploy” and head to http://localhost:1880/hana

NodeRed_Result.jpg

Awesomely easy, huh? 🙂

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

    1. Alvaro Tejada Galindo Post author

      Hello Hendrik:

      It’s been a long time since the last time I saw Gregor 🙂 So thanks for sharing the link…he’s doing some awesome stuff as always 😀

      Mine is for sure more aimed for people who has never used Node-RED before…so I hope you like it and let me know if you run into any problems 😉

      Greetings,

      Blag.

      Development Culture.

      (0) 

Leave a Reply