Skip to Content

Introduction

SAP IoT Application Enablement is part of the SAP Leonardo Portfolio enabling companies to develop their own IoT applications using a powerful set of business services (application services, Big Data and analytics, developer experience) – in a quick, secure and scalable way [1]. The solution helps you to model digital twins of your real-world object to monitor, track and analyze. One of the main features is the extensive REST-based API providing services to store and retrieve data efficiently for a thing, company and service personel [2].

To make the life of application developers easier, a SDK for SAP IoT Application Enablement is available on GitHub. The SDK provides a NodeJS package that acts a thin wrapper over the API of SAP IoT Application Enablement. The Wrapper abstracts the consumption of the API to fasten your application development for Cloud Foundry [3] providing the following features for now:

  • Abstraction of request handling
  • Performance optimized update of expired OAuth-Tokens [4]
  • Simplify resource-paths definition by setting microservices as base URIs
  • Streaming the API response

The SDK is available open source, free for everyone!

This blog post helps you jump start the application development with the new SDK!

 

Hands on

In the following hands-on session, we will implement a simple node-application running locally accessing data stored in the Big Data storage of SAP IoT Application Enablement.

Prerequisites

  • Node.js development environment [5]
  • A tenant for SAP IoT Application Enablement
  • The OAuth Client Credentials for your tenant (you have received them while onboarding your Application Enablement tenant)

Development

1. Generate a node.js application:

Create a new folder called sdk-demo. Open the command prompt in this folder, execute npm init -f. This initializes your node application. Finally, you should find a file called package.json in your folder.

2. Install the SDK:

Next, we install the SDK for SAP IoT Application Enablement as a dependency of our application. The SDK is published via the public GitHub organization of SAP [6]. You can set the SDK as a dependency to our project by adding the following section to your package.json:

{
  ...
  "dependencies": {
    "iot-application-services-sdk-nodejs": "git+ssh://git@github.com:SAP/iot-application-services-sdk-nodejs.git"
  },
  ...
}

Afterwards, re-open your command prompt and execute npm install. This will install all the dependencies specified in the package.json.

3. Configuration

In next step, we must configure the SDK to access your tenant of SAP IoT Application Enablement. There are three options to configure the SDK:

  1. You can set the necessary variables in your cloud foundry environment,
  2. You can create a file called .env which includes the variable definition in the root of your project and
  3. You can pass a JSON-object to the constructor of the SDK, which includes the variable definitions.

In this tutorial, we will use option 2.) and specify all environment variables in the .env file. So, please create a file called .env and add the following content to the file:

AE_OAUTH_CLIENT_ID = <your client-id goes here>
AE_OAUTH_CLIENT_SECRET = <your client-secret goes here>
AE_TENANT = <your tenant, e.g. ‘sap-iotaeexplore’>
AE_LANDSCAPE = eu10
AE_HOST = hana.ondemand.com

Please make sure, to replace the placeholders (<…>) with the information of your tenant.

4. Usage of the SDK

Now we create the main part of our application, which calls the API of SAP IoT Application Enablement. For this demo purpose, we will request a list of all Things created in our tenant and log the response to the console. The list of all things can be requested via the API endpoint documented in [7].

To access the endpoint, create a file called index.js in the root of your project. Next, copy and paste the following code to this file:

const NodeAE = require('iot-application-services-sdk-nodejs')
const nodeAE = new NodeAE()</code>

// set the base URI for the NodeWrapper
nodeAE.setBaseURI('appiot-mds') // 'appiot-mds' = the app of the API we will use in the following

// now we can use plain http methods to send requests (post, get, put, delete)
const loadingThings = nodeAE.get('/Things')
loadingThings.then(
  function success (oResponse) {
    console.log(JSON.parse(oResponse.body)) // will print all Things on the console
  },
  function error (oError) {
    throw oError
  }
)

Now you can start the application. Cheers!

 

Conclusion

This blog post introduced the SDK of SAP IoT Application Enablement and demonstrated the consumption of the API services offered by SAP IoT Application Enablement. But, this is just a starting point! The API offers a broad range of functionalities to consume your data. You can find further documentation about the SDK and some examples here [8].

 

 

Resources:

[1] https://www.sap.com/developer/topics/iot-application-enablement.html

[2] https://help.sap.com/viewer/350cb3262cb8496b9f5e9e8b039b52db/1.42.0.0/en-US

[3] https://cloudfoundry.org/

[4] https://auth0.com/docs/tokens/access-token

[5] https://nodejs.org/en/download/

[6] https://github.com/SAP

[7] https://help.sap.com/viewer/350cb3262cb8496b9f5e9e8b039b52db/1.42.0.0/en-US/075566a948d54a9e822f21fea493df8e.html

[8] https://github.com/SAP/iot-application-services-sdk-nodejs

To report this post you need to login first.

5 Comments

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

  1. Venu Ravipati

    Hi Lukas,

    Thank you for the blog.

    I am trying to use the SDK. In Step2, i used below package.json file and did a “npm install”. But the dependent module is not getting downloaded.


    {
    “name”: “sdk-demo”,
    “version”: “1.0.0”,
    “description”: “”,
    “main”: “index.js”,
    “scripts”: {
    “test”: “echo \”Error: no test specified\” && exit 1″
    },
    “dependencies”: {
    “iot-application-services-sdk-nodejs”: “git+ssh://git@github.com:SAP/iot-application-services-sdk-nodejs.git”
    },
    “keywords”: [],
    “author”: “”,
    “license”: “ISC”
    }

    —————————————————

    i am not getting any error as well. just warnings. Below is the log

    —————————————————-

    >npm install
    npm notice created a lockfile as package-lock.json. You should commit this file.

    npm WARN sdk-demo@1.0.0 No description
    npm WARN sdk-demo@1.0.0 No repository field.

    up to date in 1.821s

    ———————————————————–

    Could you please suggest if i missed anything.

    Thank you in advance,

    Venu

    (0) 
    1. Lukas Brinkmann Post author

      Hi Venu,

      thanks for reporting this issue. I fixed an issue in our package.json file. Your `package.json`-file is working now for me. Could you please try again?

      Best regards,
      Lukas

      (0) 
  2. Marcus Behrens

    Hi all, I also followed this blog. Any of you starting now might want to rather follow what is in github as those instructions are updated and corrected. Regards, Marcus

    (1) 

Leave a Reply