We are back to continue the series on experiencing IoT within HCP. Our first blog focused on getting a sensor connected to send measurement data to HCP and then visualize it in real time. The goal was to get this up and running in just a few steps and we largely succeeded with only a few people having difficulty. To catch up with us, you can find the first blog here: http://scn.sap.com/community/developer-center/cloud-platform/blog/2015/10/26/the-cheapest-and-simplest-way-to-send-sensor-data-to-the-hana-cloud-platform
The UI in the first blog was a very simple web page with some gauges on it, so it is time to focus on improving this. Fortunately, HCP has a very powerful SAP UI5 development environment that we can use to build HTML5 applications – Web IDE. Normally, you will build HTML5 applications which interact to the backend through OData. However, that is not a requirement of all applications within the Web IDE, so we are going to provide you a tile based single page application which can be modified to your heart’s content.
To support easy customizations, we implemented the application using a modified Chain of Responsibility design pattern. Pluggable “handlers” are defined to perform actions on the messages as they are received. Based on the type of sensor, the types of handlers used are very different. The general flow of the HTML5 application is this –
- A websocket connection is made from the HTML5 application to the websocket server running on the Java application running on your SAP trial account.
- When a message is received, each registered handler is asked if they are interested in the message. If so, then a render method is executed on the handler to perform the actions necessary by the handler. These are normally the rendering of charts / gauges, etc.
- After all handlers have had their chance to respond to the message, a final method “afterAllMessageHandlers()” is called to perform one-time actions on the message such as updating a message count or checking against any rules.
Running the Application
- Ensure that you have your sensor up and running as described in part 1.
- To start the Web IDE within your trial account, follow the steps outlined here: https://help.hana.ondemand.com/webide/frameset.htm?51321a804b1a4935b0ab7255447f5f84.html
- Download this zip file: https://drive.google.com/file/d/0Bwdrs4BVb3zkQmdnZVM2STNfZlk/view?usp=sharing
- Right click on “Workspace” and choose “Import -> From File System”. Choose the file downloaded in the step above.
- After it is imported into your workspace, you can run it in test mode by selecting the index.html file and clicking on the “Run” icon.
- To deploy it, right click on the project “simpleUI5dashboard” and choose “Deploy -> Deploy to SAP HANA Cloud Platform”. Login if necessary. If you want to utilize the Git integration, select the checkbox to “Connect to the SAP HANA Cloud Platform Git repository”. Press Deploy.
- On the settings page (from the gear icon on the bottom right), you can change the image used for the orientation. This gives a nice visual of how the sensor is oriented.
- Check the metric box to get the temperature values in celsius.
- device.getLast(‘movement’) > 10 // Detect any real movement
- device.getLast(‘light’) > 50 // Detect a significant amount of light
- device.getAverage(‘movement’,5) > 70 && device.getLast(‘roty’) > -40 && device.getLast(‘roty’) < -20 // The sensor is on its head and the average of the last 5 movement measurements indicates significant movement
- Measurements available – movement, maccelerationx, maccelerationy, maccelerationz, temperature, irTemperature, rotx, roty, rotz, magx, magy, magz, humidity, light, firmware, pressure
- Make sure you “Active Rules Engine” or it won’t actually try to evaluate your defined condition.
- If the rule is found to be true, then an alert box will display. You could have it do any number of actions like sending an email or integrating with a framework like IFTTT.
- Since this is using UI5 and tiles, you can access this page from your tablet, phone, or desktop and it will use responsive design to change how it is rendered.
Stayed tuned for the next installment when we persist the data in HANA and enable some historical analytics. If you have any questions or comments, please add them below.