Supply Chain Management Blogs by SAP
Expand your SAP SCM knowledge and stay informed about supply chain management technology and solutions with blog posts by SAP. Follow and stay connected.
Showing results for 
Search instead for 
Did you mean: 
Product and Topic Expert
Product and Topic Expert
0 Kudos

Recap –

In Water Purifier as a service with SAP Internet of Things (IoT) –

  • Part 1  – We understood the smart purifier use case and how it will be using SAP  Internet of Things (IoT) service to build the demo.

  • Part 2  – We discovered SAP IoT and its application. We created a thing that is nothing but the digital twin of the water purifier.

  • Part 3   – We created an SAP IoT Instance and respective tenant for this scenario.


Prerequisites –

  1. You should have created an instance of SAP IoT service and a tenant. This tenant will use to create the actual device.

  2. Tools - Visual Studio Code (you can also use one of your choices)

  3. Node Js installed on your machine


Know more about the device creation hierarchy  -

Let's try to understand a device and its attributes with respect to a water purifier with the following diagram -

Note - This Purifier is a smart purifier that contains a controller that has sensors and can send data over the internet,

It's pretty simple to understand. Our water purifier is a device that consists of sensors to measure the volume (liters consumed) and temperature. These measures will be the capability of a sensor type that will be used to create a sensor. Finally, this sensor will be attached to a device.

Let's go step by step to see how it's done using IoT Service cockpit.


Steps to follow for creating a device –

"Note - Create a file to copy ID's of some artifacts which are going to create now. These will be needed later when we will be ingesting the data from the simulator."

Create capability with the following measures literconsumed and temperature. After successful creation of capability please copy the alternate id.

Copy CAPABILITY_ALTERNATE_ID = "Alternate ID after creating the capability"

create a new capability for water purifier

Create Sensor type by selecting the same capability that we created in the previous step.

create a sensor type

Create Device with gateway as MQTT which are going to use and copy the device alternate id.

Copy DEVICE_ALTERNATE_ID = "Alternate ID after creating the Device"

create a device

Create Sensor and attach it with Device and copy the sensor alternate id.

Copy SENSOR_ALTERNATE_ID = "Alternate ID after creating the Sensor"

create a sensor and attach it with the device

Map the device with Thing in SAP IoT application - 

This device needs to be mapped with the thing which we created in Part 2, which means we are actually mapping the digital twin with the device and its sensors.


Thing Creation

Navigate to the connectivity section and select SAP Cloud platform IOT service which will eventually give you an option to select the sensor which we created. This sensor is attached to the device means the owner for a thing in this scenario is the actual device.


Mapping thing with Sensor and the respective device


Data Ingestion

To ingest data from a device its need a device certificate which you can download from the certificate section.

Generate certificate

copy secret key

Configuring the Simulator -

Please download the simulator source code (Node Js application) from github and Open the source code in Visual Studio code and navigate to the following path (DATA_Ingestion->Utlis) and open file PushMQTT.js to change the values of the parameter mentioned in next step.

  • TENAT_ID -

  • DEVICE_ALTERNATE_ID - Copy from the credentials file which we created earlier

  • SENSOR_ALTERNATE_ID - Copy from the credentials file which we created earlier 

  • CAPABILITY_ALTERNATE_ID - Copy from the credentials file which we created earlier

  • Host - You can copy the host url from your IoT Service cockpit url (Exclude https and copy till sap in the cockpit url)


Open files certificates -> client_device.pem and client_key -  

Client_device.pem - > Open the pem file which we downloaded earlier in a textedit application to copy the contents in this file.

client_key - > Its the same key which we copied in the previous step while we downloaded the pem file.

After replacing the values mentioned above we can check the measure which you can modify as part of data ingestion -

async function sendDataViaMQTT() {

await timeout(5000)
var payload = {
sensorAlternateId: SENSOR_ALTERNATE_ID,
capabilityAlternateId: CAPABILITY_ALTERNATE_ID,
measures: [


var topicName = 'measures/' + DEVICE_ALTERNATE_ID;
mqttClient.publish(topicName, JSON.stringify(payload), [], error => {
if(!error) {
console.log("Data successfully sent!");
} else {
console.log("An unecpected error occurred:", error);

As you go through the code literconsumed , temperature is the 2 measures that will be ingesting from the simulator. Temperature can be kept as it sending data randomly from a function and literconsumed can be changed over a period of time. This parameter will be changing later to check the consumption but for now to test the simulator you can give any value of your choice.

Now we are good to start the simulator and validate the data ingestion.

Start the simulator - Change the working directory to this project and run the following command
node ./Utlis/PushMQTT.js

This is a start Data ingestion, and you should see the status code 202 which means data is ingested successfully. Let's also confirm the data ingestion on SAP IoT service cockpit and to do so open the devices section and select the device which we created earlier and navigate to Data Visualization section -


Let's verify the data on the SAP IoT application side. Open the thing in the application to verify the same -


Wow!! This is great, isn't it?  we have our first simulator device ingesting the data, and now we have endless possibilities that can be achieved with this data. The next blog will learn how to embed IoT data into business processes and build or IoT application.


References -




  4. Tutorial -

  5. Device connectivity API -

  6. Onboard devices -