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.
cancel
Showing results for 
Search instead for 
Did you mean: 
Jay2
Product and Topic Expert
Product and Topic Expert
0 Kudos
887

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)

    • xyz.eu10.cp.iot.sap






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() {

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

{"literconsumed":litersconsumed_gen,"temperature":temperature_gen()}

]
}
console.log(payload);
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 -

  1. https://help.sap.com/viewer/565d09b96468492aacee0f3f37282053/Cloud/en-US/c4da75750e5b42488cb5874d3fc...

  2. https://help.sap.com/viewer/6040fec3f22e4f9b8bf495f3789d66b5/Cloud/en-US/78d9a1772a0b4396ad8434acc5f...

  3. https://help.sap.com/viewer/9a8cae62b9ab4278af1f39e188b11bc7/Cloud/en-US

  4. Tutorial - https://developers.sap.com/tutorials/iot-express-2-create-device-model.html

  5. Device connectivity API - https://help.sap.com/viewer/3a6d7e0a3904450cae8f842948a6ea67/2102a/en-US/97b88f38fa03454a98116a30a32...

  6. Onboard devices - https://help.sap.com/viewer/9133dbb5799740f8b1e8a1c3f0234776/2101a/en-US/a2352d12ea3c4b4e9b46a347372...