Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
craigcmehil
Community Administrator
Community Administrator

So the other week in Las Vegas we had the Hackers' Lounge for the first time at the event and inside the lounge we had our IoT Lab where you could come by and "try it for yourself"!

We had hardware setup and quick and easy exercises there so you could try connecting a Beagle Bone all the way to SAP HANA and SAP HANA Cloud Platform! So I took the infos with me and I decided to take a Raspberry Pi, a temperature sensor and a HANA server and see what I could put together. After all Berlin is in just a few days and I wanted to share what you can do too!

I used the following link to help get the hardware all connected, and lots of talking to ian.thain.

After the hardware was connected it was just a matter of modifying the Python code on the same website to add in the "HTTP POST" to my HANA Server. I'm using actually a SAP HANA Dev Edition but you should be able to use SAP HANA Cloud Platform as well.

Now on my server I created a XS application.

I also set the XS app to an anonymous connection - it is just a demo after all.

First step was to create a table for the data to go into.


namespace iot.data;
@Schema: 'IOT'
context iotsensor {
  type SString : String(40);
  type LString : String(100);
  type SDate : UTCTimestamp;
    type tt_error {
         HTTP_STATUS_CODE: Integer;
         ERROR_MESSAGE: String(100);
         DETAIL: String(200);
    };
  @Catalog.tableType : #COLUMN
  Entity Details {
  key ID: Integer;
  TDATE: SDate;
  SENTEMP: Decimal(9,3);
  SENNAME: LString;
    };
};

Throw in a sequence to auto increment the ID field and a procedure to handle the insert.


PROCEDURE "SYSTEM"."iot.procedures::newSensorData" ( IN row IOT."iot.data::iotsensor.Details", OUT error IOT."iot.data::iotsensor.tt_error" )
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER
DEFAULT SCHEMA IOT
AS
BEGIN
/*****************************
  Write your procedure logic
*****************************/
declare lv_date timestamp;
declare lv_sentemp decimal(9,3);
declare lv_name string;
select TDATE, SENTEMP, SENNAME into lv_date, lv_sentemp, lv_name from :row;
if :lv_date = ' ' then
error = select 400 as http_status_code,
  'invalid date' as error_message,
  'Invalid response from sensor' as detail from dummy;
else
insert into "iot.data::iotsensor.Details" values ("iot.data::id_seq".NEXTVAL, now(), lv_sentemp, lv_name); 
end if;
END;

Round it off with the XSODATA service and voila we have the data ready to go.


service namespace "iot" {
"IOT"."iot.data::iotsensor.Details" as "SENSOR"
  create using "iot.procedures::newSensorData";
}

From this point on the data was flying in, so I asked Ian to throw his on as well and we could see if the data from two remote locations were able to go into the server.

Every second Ian and I were both pushing data to the server and were able to see it live on a website! In Ian's line there you an even see where he brought his "typical" cup of tea in and sat it down next to his sensor. You can even see when he picked it up to drink. I on the other hand had to put my finger on the sensor to get it to heat up above his but apparently London is warmer than Germany.

Find this interesting then be sure to come by the Hackers' Lounge on the show floor this coming week in Berlin and try this all for yourself!

Many thanks to thomas.jung for helping me with some of the coding!

2 Comments