Sunday 7 May 2017

The AWS IoT Button and SAP HANA express edition

I’m a sucker for new toys and tech and when I can take something new and within a short period of playing around actually connect it to SAP I’m on top of the world.

SAP HANA Tutorials and Materials, SAP HANA Certifications, SAP HANA Guide
So that’s what I recently got, the AWS IoT Button. It’s their cloud programmable dash button, I have a dozen of those as well because I always forget to add things to my shopping list.

The AWS IoT Button is a programmable button based on the Amazon Dash Button hardware. This simple Wi-Fi device is easy to configure and designed for developers to get started with AWS IoT, AWS Lambda, Amazon DynamoDB, Amazon SNS, and many other Amazon Web Services without writing device-specific code.

When I got the button I was honestly not sure what I was going to do with it. It’s just a button after all. How much can it do, click it and it places and order… but wait there are 3 events to work with and it sends a basic payload that I can grab and work with.

The events are the SINGLE, DOUBLE and LONG and indicate the interaction with the button and the payload that it generates is quite simple.

{
    "serialNumber": "GXXXXXXXXXXXXXXXXX",
    "batteryVoltage": "mV",
    "clickType": "SINGLE | DOUBLE | LONG"
}

So what I needed to do now was create a Lambda function quite similar to what I did was the Amazon Echo (SAP Cloud Platform and ABAP) and parse the payload and decide what to do.  I also knew I wanted to interact with my SAP HANA express edition (HXE) system and to shake things up I decided I would use the one running in the Google Cloud Platform. At this point I was not sure what I wanted to do but I knew there was something there for me to do. I also checked out what others had done as well to start generating the ideas.

With the beginnings of an ideas I made sure that my Lambda function based off of their tutorial worked and I had a working email subscription so I knew when things were processed. That was so easy and I was able to add anything I wanted to it the content.

SAP HANA Tutorials and Materials, SAP HANA Certifications, SAP HANA Guide

Now though I needed what the email says to actually happen, and therefore in steps my HXE system.

So in my Lambda function I added the following code for the SINGLE click event of the button.

var body = JSON.stringify({
    "MATNR1": 12, 
    "REQUESTED_QTY1" : 5, 
    "MATNR2": 25, 
    "REQUESTED_QTY2" : 3
});
var request = new https.request({
        hostname: hxe_host,
        port: 4300,
        path: "/SmartThings/things.xsodata/createEntry",
        method: "POST",
        headers: {
            'Authorization': authStrHXE,
            'Content-Type': 'application/json; charset=utf-8',
            'Accept': '*/*'
        }
    });
    request.end( body );
    request.on('response', function (response) {
    console.log('STATUS: ' + response.statusCode);
    if( response.statusCode === 201 ){
        console.log("Successfully received response system");
        callback("Processed correctly");
    }
});

and that went right inside of the event handler.

exports.handler = (event, context, callback) => {
    console.log('Received event:', event.clickType);

    if(event.clickType === 'SINGLE' ){
      /** insert here **/
    }
};
It was so simple! I was utterly pleased at how quickly that went! Of course the other part was some simple stored procedures and xs odata on my HXE system to do some database table updates. I won’t dive into those.

Click the button though and not only do you get the mail but you can see in the logs what else is happening.

SAP HANA Tutorials and Materials, SAP HANA Certifications, SAP HANA Guide

In theory and practice I now have a “Dash button” that can generate a purchase order with a supplier system for a real ERP business just like if I wanted to order a household product. Now how cool would it be to have a button like this in my manufacturing plant or office complex that would enable employees to place orders without stopping to find the proper form?

No comments:

Post a Comment