In this series of blog, I am going to share my experience using the HANA Cloud Platform’s Internet of Things service and also show how one could leverage the IoT APIs and securely expose them using API Management to complete an E2E business scenario. I was motivated to do a prototype as a result of a discussion with one of our customers who are leaders in rail freight. They were keen to understand how they could use HCP to provide a solution to their partners who could monitor rail wagons in real-time based on the sensor data captured from devices installed in each wagon.

I started the PoC with a Raspberry PI. The Raspberry Pi is a tiny and affordable computer that you can use to learn programming through fun and practical projects. As you can see from the below image, it’s a mini computer and it has most of the basic things.

There are few other devices like Arduino & ESP8266 which are even smaller and very well suit IoT projects. Since this was my first ever attempt, I decided to stick with Raspberry PI as it comes with features like inbuilt wifi/Bluetooth and is recommended for beginners. Next, I purchased the below sensors

1) Basic photocell resistor which changes resistance based on how bright the light is. I followed this tutorial on adafruit to implement the photocell resistor.

2) Digital temperature sensor which measures the current temperature. I followed this tutorial on adafruit to implement the Digital temperature sensor


One of the mistakes I did earlier was to buy an analog sensor TMP36 to only find that Raspberry PI supports only sensors which give digital output. You would need MCP3008 to convert analog to digital inputs for such sensors.

I followed the instructions in the above articles and setup the sensors and configured the connections to my Raspberry PI. The next step was to read the sensor values. There are different choices of programming language – Ruby, Python , Nodejs which can be used in Raspberry PI. There is also an interesting Visual editor called NodeRed which doesn’t require you to code. I used python just because I found lot of sample code which made it easier for me to start and Python software and editors were already available in my Raspberry PI.

In the below video I am going to show how I started this and setup the sensors to be read. It took me about a week to learn how to setup the sensors and connect them to a Raspberry PI which then uses python script to stream the sensor value to an application hosted on HCP.

Once I got my python code to work, I was able to successfully read the temperature and photo sensor readings and print them to the terminal.  I then modified the script to communicate to HCP and publish the sensor data to the IoT services. When it comes to supported protocols for HCP IoT service, there are two at the moment – HTTP and Web Sockets. I have used both of them in my Python program. I used Web Sockets to stream data to a dashboard which is made available as an application on HCP and I also used HTTP to post messages to the HCP persistence layer.

As you have seen in the above video, the IoT dashboard in the HCP App shows values in real time based on the temperature and light sensor reading. I could now take this one step further and even start configuring push notifications to the smart watch of the train driver alerting them when a threshold has exceeded or I could even raise a work order notification in an on-premise SAP system or C4C cloud application.

Part 2 : Configuring SAP HCP IoT Service

Part 3: Configuring & Exposing IoT APIs securely using API Management

To report this post you need to login first.

6 Comments

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

  1. Sandeep Tharwani

    Thanks Murali for a very good step by step explanation. 

    One thing i wanted to understand was as you mentioned in your last comment that we can go a step further and configure threshold for a work order or alert driver, where would you do that configuration of threshold.

    (0) 
    1. Murali Shanmugham Post author

      Thanks Sandeep. The configuration of threshold and other logic would need to be done in the java application which is receiving the sensor message. Since we are using WebSockets, the moment the sensor message arrives, we can define our logic and accordingly invoke OData APIs which will communicate with other systems (on-premise or Cloud) to say, raise a work order or incident.

      (0) 
  2. Rajesh Ranjan

    Hi Murali,

    Thanks Murali, for the nice explanation. Could you please share the python script as well which will post the message from raspberry pi to HCP?

    This will be very useful for me.

    Thanks
    Rajesh

    (0) 

Leave a Reply