Skip to Content
Author's profile photo Craig Cmehil

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.

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.

 

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.

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?

Assigned Tags

      10 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Impressively simple.

      Author's profile photo Former Member
      Former Member

      Craig, This is a great article and will help many SAP customers. However  the IoT button is still focussed on developer community. That is why Visybl is partnering with AWS IoT team to bring this button to everyone. Please checkout https://bit.ly/gobutton to find more information on how with just frw clicks anyone can integrate the button into their ordering process.

      Author's profile photo Craig Cmehil
      Craig Cmehil
      Blog Post Author

      Very interesting! Something like that could make things easy for a lot of folks out there.

      Author's profile photo Former Member
      Former Member

      interesting.. thanks for sharing!

      Author's profile photo Former Member
      Former Member
      Hello everybody I have recently bought the aws buttons and I succeeded to connect to the sap iot service which is connect to 
      a sapui5 aplication
      
      I do not know if it will help someone but here is my code for the lambda function to execut when the button is pressed
      
      var https = require('https');
      var path;
      var Authorization;
      exports.handler = (event, context, callback) => {
       console.log('Received event:', event.clickType);
      
      if(event.serialNumber === 'G03xxxxxxxxxxL') {
       path = '/com.sap.iotservices.mms/v1/api/http/data/xxxxxxxxxxxxxxx3' ;
       Authorization = 'Bearer 5xxxxxxxxxxxxxxxxx';
      }
      
      if(event.serialNumber === 'G030xxxxxxxxxxxxW') {
       path = '/com.sap.iotservices.mms/v1/api/http/data/d1460b51-c992-4eb8-8ef0-971cb4575592' ;
       Authorization = 'Bearer a7f878ce65c1ad24d7fb9356992e7d0';
      }
      
      if(event.serialNumber === 'G03xxxxxxxxxxxx') {
       path = '/com.sap.iotservices.mms/v1/api/http/data/xxxxxxxxxxxxxxxxxxxx' ;
       Authorization = 'Bearer fxxxxxxxxxxxxxxx0xx4a';
      }
       if(event.clickType === 'SINGLE' ){
       /** action to do if single click **/
       var body = JSON.stringify({"mode":"sync","messageType":"xxxxxxxxxxxxxxx","messages":[{"button":1,"timestamp":1413191650}]});
       var request = new https.request({
       hostname: 'iotmmspxxxxxxtrial.hanatrial.ondemand.com',
       path: path,
       method: "POST",
       headers: {
       'Authorization': Authorization,
       'Content-Type': 'application/json; charset=utf-8',
       }
       });
       request.end( body );
       request.on('response', function (response) {
       console.log('STATUS: ' + response.statusCode);
       if( response.statusCode === 200 ){
       console.log("Successfully received response system");
       callback("Processed correctly");
       }
       });
      }
      
      if(event.clickType === 'DOUBLE' ){
       /** action to do if double click **/
       var body_double = JSON.stringify({"mode":"sync","messageType":"XXXXXXXXXXXXXXX","messages":[{"button":0,"timestamp":1413191650}]});
       var request_double = new https.request({
       hostname: 'iotmmspxxxxxxxxxxtrial.hanatrial.ondemand.com',
       path: path,
       method: "POST",
       headers: {
       'Authorization': Authorization,
       'Content-Type': 'application/json; charset=utf-8',
       }
       });
       request_double.end( body_double );
       request_double.on('response', function (response) {
       console.log('STATUS: ' + response.statusCode);
       if( response.statusCode === 200 ){
       console.log("Successfully received response system");
       callback("Processed correctly");
       }
       });
      }
      
      };
      
      
      
      

       

      Author's profile photo Mohammed zahid
      Mohammed zahid

      Hi experts,

      Could you tell me how to connect the AWS IOT stick with the neo trail account ?

      Till now I have being using the trail account to connect with the sensors and build POC, use case etc.

      AWS is new to me .

      Thanks in advance.

       

      Author's profile photo Craig Cmehil
      Craig Cmehil
      Blog Post Author

      Easiest is to just connect your defined odata service from NEO in the Lambda function.

       

      Author's profile photo Mohammed zahid
      Mohammed zahid

      AWS IOT Button is not available in India 🙁

      Author's profile photo Nizare DAMOUMAT
      Nizare DAMOUMAT

      Hello Craig,

      Thanks for posting such informative blog.

      Could you tell me how can I post an HTTP request to an oData service using AWS Lambda?

      I already created my own index.js, the request succeeded but the response is null…

      Could you please provide us a sample (aws lambda & odata service)?

      Thanks in advance

      Author's profile photo Craig Cmehil
      Craig Cmehil
      Blog Post Author

      This should help, https://blogs.sap.com/2016/12/08/amazon-echo-and-the-sap-hana-cloud-platform/, but also the comment above shows a simple example of a POST  as well.