A Simple Door Monitoring System with HANA XS and Raspberry Pi
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
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.
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
Let’s focus here on the key components:
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.
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.
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
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.
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
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
Thanks John
I love to see your setup too. I have just finished my new blog under Hana cloud platform on the Internet of Things with WhatsApp and off course, HANA:
http://scn.sap.com/community/developer-center/cloud-platform/blog/2014/08/15/send-photo-via-whatsapp-and-display-it-from-hana
Best,
Ferry