Skip to Content

Inspired by Thierry BRUNET’s excellent blog series HANA Cloud Platform predictive services – Starter Kit, I got HCPps working on my HCP trial account.

In terms of what data to analyse, I decided for I2C temperature information from my Raspberry Pi, inspired by Murali Shanmugham’s excellent blog series Capture event streams from IoT devices and perform predictive analytics using HCP (but without the need for SDS) and similar to Verify your HANA Cloud Platform Internet of Things latency.

To make this work, there are 10 main steps:

  1. Fit an I2C sensor to your Raspberry PI. I chose a combination of a MCP9801 temperature sensor with a DS1337 real time clock module:
  2. Enable I2C on your Raspberry PI:
  3. Find the I2C address of your sensor. In my case the temperature sensor is at 0x4f and the real time clock module at 0x68:
  1. Send your sensor data to your HANA Cloud Platform, IoT service:
    import com.pi4j.io.i2c.I2CBus;
    import com.pi4j.io.i2c.I2CFactory;
    import com.pi4j.io.i2c.I2CDevice;
    import java.net.URL;
    import java.net.HttpURLConnection;
    import java.io.DataOutputStream;
    import java.io.InputStream;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    public class C4PA {
    	public static void main(String[] args) {
    		try {
    		  	I2CBus i2cBus = I2CFactory.getInstance(I2CBus.BUS_1);
    	    	I2CDevice mcp9801 = i2cBus.getDevice(/*YourI2CSensorAddress*/);
    		    byte[] buffer = new byte[2];
    		    HttpURLConnection con = null;
    		    URL url = new URL("https://iotmms/*YourHCPID*/.hanatrial.ondemand.com/com.sap.iotservices.mms/v1/api/http/data//*YourDeviceID*/");
    		    con = (HttpURLConnection)url.openConnection();
    		    con.setRequestMethod("POST");
    		    con.setRequestProperty("authorization", "Bearer /*YourAuthCode*/");
    		    con.setRequestProperty("content-type", "application/json;charset=utf-8");
    		    con.setUseCaches(false);
    		    con.setDoOutput(true);
    		    DataOutputStream wr = new DataOutputStream (con.getOutputStream());
    		    int bytes = mcp9801.read(0, buffer, 0, 2);
    		    System.out.println("Temp: " + ((double) buffer[0] - (double) buffer[1] / 256));
    		    wr.writeBytes("{\"mode\":\"sync\",\"messageType\":\"/*YourMessageType*/\",\"messages\":[{\"temperature\":\"" + ((double) buffer[0] - (double) buffer[1] / 256) + "\"}]}");
    		    wr.close();
    		    InputStream is = con.getInputStream();
    		    BufferedReader rd = new BufferedReader(new InputStreamReader(is));
    		    StringBuilder response = new StringBuilder();
    		    String line;
    		    while((line = rd.readLine()) != null) {
    				response.append(line);
    				response.append('\r');
    		    }
    		    rd.close();
    		    System.out.println(response);
    		} catch (Exception e) {
    		    e.printStackTrace();
    		}
    	}
    }​

    I schedule a respective cron job:

    java -classpath .:classes:/opt/pi4j/lib/'*' C4PA

  1. Bind your iotmms Java application to the same HCP HANA MDC Data Source as your aac4paservices Java Application:

  2. Configure a sql Processing Service Mapping to store your IoT data in the schema that you set up for HCPps:

  3. Check that your IoT data is in fact stored in the schema that you set up for HCPps:

  4. Register your IoT data table with HCPps via the API Console:

  5. Run a query like that for the two most prominent temperature outliers:

  6. Examine the result, i.e. temperature 13 outliers of which 27.5 and 30.5 are the 2 most prominent ones:

To report this post you need to login first.

Be the first to leave a comment

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

Leave a Reply