Intro

I have built a simple door sensor with SAP HANA and Raspberry Pi to monitor the door-opening events. The wireless door sensor is a magnetic gap sensor that will send the RF 433 Mhz signal to the receiver when someone open the door. The Raspberry Pi with the receiver within the range listens for the incoming signal from the sensor. Once the signal is detected, the Raspberry Pi will send the ODATA http post request  to the HANA server. You can monitor the events status from the web app (backend).

If you never heard of Raspberry Pi, you may refer to its website at http://www.raspberrypi.org/ . Building the receiver will not be covered in this blog. Please refer to this blog to build it: Adding 433 to your Raspberry Pi | Ninja Blocks

/wp-content/uploads/2014/07/rpi_493299.jpg

Slide1.JPG

HTTP POST Command: Curl

On the Raspberry Pi, there is a command line tool in Linux to post the http request: curl with the JSON data: body.json.

if (mySwitch.getReceivedValue() == 13981149 ) {

                system(“curl -H ‘Content-Type: application/json’ –data @/home/pi/433Utils/RPi_utils/body.json http://hana2.vm.cld.sr:8000/rpi/sensor/service/RPISensor.xsodata/RpiSensor

          }


The body.json contains the current timestamp, date and STATUS = Open. The timestamp and date will be auto-populated by the insert procedure on the HANA XS side.

{“STIMESTAMP”:”\/Date(0000000000000)\/”,”SDATE”:”\/Date(0000000000000)\/”,”STATUS”:”Open”}


To run the receiver, just type sudo ./RFSniffer on the Raspberry Pi command prompt. This command listens to the incoming signal from the sensor and sends the http post ODATA request to HANA XS. On the HANA XS side, the insert procedure will update the HANA table.

/wp-content/uploads/2014/07/sensor_493395.jpg

Project Structure: Key Components


The structure and explanation is pretty much the same as in my earlier blog here: http://scn.sap.com/community/developer-center/hana/blog/2014/07/07/real-time-gps-tracker-using-sap-hana-xs-sapui5-cordova-geolocation-plugin-and-odata

/wp-content/uploads/2014/07/aa_493535.jpg

Let’s focus here on the key components:

  • The RpiSensor table to store the status of the door events:/wp-content/uploads/2014/07/b_493537.jpg
  • The  XSODATA:
    /wp-content/uploads/2014/07/xsodata_493563.jpg
  • The InsertRowRPISensor procedure:
    /wp-content/uploads/2014/07/c_493538.jpg
  • And also the web app backend SAPUI5 to view the information:
    /wp-content/uploads/2014/07/d_493539.jpg

A complete source code can be found on GitHub: ferrygun/HANADoorSensor · GitHub

Summary

You could make an internet of things by combining the power of SAP HANA and the micro-computer/controller like the Raspberry Pi/Arduino with other sensors (e.g,. GPS, temperature/humidity, contact sensors, etc) and create a dashboard to present the status of the sensors.

Thanks for reading my blog. I hope you enjoy it.

To report this post you need to login first.

6 Comments

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

  1. Carolina Capdevila

    Hi, Ferry! Nice post 🙂 . I am trying to use a Raspberry Pi to measure temperature and send the values to HANA, and I have one question: do I need to install a HANA client in the RPi to connect to the database? Thank you very much in advance.

    (0) 
    1. Ferry Gunawan Post author

      Thanks Caroline

      In the above blog, I did not install the HANA client. I am just using the linux command: Curl to post the ODATA request to the HANA server. The request will be captured by the RPISensor.xsodata. But it depends on your setup, you also can install the HANA client to write a record in the HANA table. I am doing it in my other blog when integrating the IVR with HANA (it’s also using Raspberry Pi).

      Pls let me know if you have any question.

      Regards, Ferry 

      (0) 
      1. Carolina Capdevila

        Hello, Ferry. Many thanks for your answer. I solved my problem using Python and the library ‘requests’ to send HTTP post messages with the data in json format to an OData service inside HANA that manages this petition and inserts this data into my table. It was much easier than I expected at first, because I am new with all this, but OData is simplifying my work so much 🙂 . Thanks again for your great post that was a big help for me. Kind regards,

        Carolina.

        (0) 
        1. Ferry Gunawan Post author

          Hi Carolina,

          It’s great to hear that you finally success in your setup. If you don’t mind, please share your creation in the SCN so everyone can learn too. Thanks

          Regards,

          Ferry

          (0) 
  2. John Astill

    Awesome blog. Can’t believe I did not see this yet. I also have Ninja blocks and Pi setup for home automation, along with Smartthings and Iris.

    I am loving playing with iOT. Last year at TechEd we hooked some wearable sensors to HANA but used a mobile phone as the wifi router.

    Looking forward to seeing your next blogs

    I really should blog the details on our setup from last year.

    JohnA

    (0) 

Leave a Reply