This iot sample application is meant to make it simpler for you to build your own iot application that will synchronize relevant S/4 HANA Cloud Delivery and Material data into your Leonardo IoT environment.
It features the use of SAP Cloud Platform IoT, Leonardo IoT and a NodeJS application for synchronizing relevant data to cloud foundry.
- NodeJS (we used v11.12.0)
- SAP Cloud Platform Account with a cloud foundry sub-account
- SAP Cloud Identity tenant This is a commercial paid product
- A subscription to SAP Leonardo IoT and a service instance of SAP Leonardo IoT for cloud foundry. These are commercial paid products
- A subscription to SAP Cloud Platform Internet of Things This is a commercial paid product
- An instance of SAP Cloud Platform Job Scheduler This is a commercial paid product
- Cloud Foundry Command Line Interface (CLI) installed on your system
Click on the Clone or download
button to download as a zip, or clone the repository on your desktop.
Instructions on how to configure and deploy the sample application will be covered later in the In IoT Integration Application configuration section since it depends on some initial configuration to be performed in SAP Leonardo IoT.
A basic understanding of SAP Cloud Platform Internet of Things device modeling and SAP Leonardo IoT thing modeling is needed to perform the following configuration steps. The following two tutorials on developers.sap.com provide a good overview of device and thing modeling:
Parameter | Description |
---|---|
IoTIntegration > package | Leonardo IoT fully qualified package name that you will create during Leonardo IoT Configuration, e.g. {tenant subdomain}.humaterial . Use the Leonardo IoT Services package API to query the details of your package. |
IoTIntegration > basicPropertySet | Leonardo IoT basic property set name that you will create during Leonardo IoT Configuration, e.g. humaterialbasic . |
IoTIntegration > objectGroup | Leonardo IoT authorization object group, e.g. E2328EA3DFFA45BBA577AF4C2084A904 . Use the Leonardo IoT Services authorization API to query the details of your object group. |
S4 > url | The base url to your S/4 service. This should be an S/4 HANA Cloud Service. E.g. https://myXXXXXX.s4hana.ondemand.com . |
S4 > username | The Basic Authentication user name for your S/4 service. |
S4 > password | The Basic Authentication user password for your S/4 service. |
IoTService | Obtain the instanceId , cockpitUrl , username and password from the SCP Cockpit IoT Service Instance Key. The apiUrl is the cockpitUrl with the /iot/cockpit path removed, e.g. https://{instanceId}.eu10.cp.iot.sap/{instanceId} . |
HANDLING_UNIT_ID | For each Handling Unit Id that will be used in a delivery. Use the S/4 OData service for a handling unit: API_HANDLING_UNIT: HandlingUnit/HandlingUnitExternalID . |
MATERIAL_TYPE | For each Material Type/Group that you want to synchronize to IoT. Use the S/4 OData service for a delivery: API_OUTBOUND_DELIVERY_SRV: A_OutbDeliveryHeader/to_DeliveryDocumentItem/MaterialGroup . |
Make sure Message Processing Configuration has been configured (Configuration and Selector) before creating your device model to ensure device metadata is available in SAP Leonardo IoT.
- Create a
Capability
with the measures of your choice, e.g.Temperature
- Create a
Sensor Type
with the aboveCapability
- Create a
Device
and add aSensor
with naming conventionHUMaterial_{HANDLING_UNIT_ID}
for each handling unit device that will be used for material deliveries
Note: The
Sensor
naming convention must be strictly followed, this is how the delivery with a particular handling unit and sensor is determined
- Create a Leonardo IoT Package, note the package name
- You'll need the fully qualified package name, you can obtain it using the SAP Leonardo IoT Services APIs for reading packages
- Create a
Measured Values
property set in your new package with corresponding properties matching your aboveCapability
, e.g.Temperature
- Create a
Basic Data
property set in your new package with the following properties of typestring
- These are required properties:
- HandlingUnitId
- MaterialType
- MaterialNumber
- These properties can be modified by editing the JavaScript code in s4.js:
- PurchaseOrder
- DeliveryItemText
- SalesOrder
- SalesOrderItem
- PackagingMaterial
- Delivery
- DeliveryItem
- SoldToPartyName
- Quantity
- QuantityUnit
- ContactEmail
- NetAmount
- NetAmountCurrency
Note: The properties must exactly match what is generated by s4.js
- Create a
Thing Type
with naming conventionMaterialT_{MATERIAL_TYPE}
for each S/4 Material Type that you want to be synchronized, add property sets you created earlier
Note: The
Thing Type
naming convention must be strictly followed, this is how the thing type for a particular material type is determined
- Map
Thing Type
to theSensor Type
you created in SAP Cloud Platform Internet of Things through theConnectivity
tab
- In your cloned or downloaded repository configure
{CUSTOMER_TENANT}
placeholder variables in xs-security.json and manifest.yml - Create an XSUAA service instance with
xs-security.json
by running the following commandcf cs xsuaa application {SERVICE_NAME} -c xs-security.json
- Configure all placeholder variables in curly braces, e.g.
{PACKAGE_NAME}
in the manifest.yml before deploying it to SAP Cloud Platform. Refer to the environment variable section underenv
. You'll need to have your S/4 HANA and SAP Cloud Platform Internet of Things service credentials, and service instance names available.
Note: You may need to use the SAP Leonardo IoT Services APIs to obtain some of the configuration values such as package, basicPropertySet and objectGroup. See the SAP Leonardo IoT Services documentation for more information.
- Use
cf
CLI to log into your CF sub account and space where the Leonardo IoT, XSUAA and Job Scheduler service instances have been created - From the root folder of this sample application execute
cf push
- Note the sample integration app urls displayed in the console at the end of the deployment, you'll use this url for testing and to configure the Job Scheduler.
You can use Postman to synchronously invoke the process endpoint via POST
to
{IOT_INTEGRATION_APP_URL}/process?sync=true
, note that you must provide
a client credential based OAuth Bearer token obtained from the XSUAA
credentials
from the application binding, e.g.
POST https://mytenant-iot-integration-svc.cfapps.eu10.hana.ondemand.com/process?sync=true
Make sure the JobScheduler service is created with enable-xsuaa-support parameter, e.g.
cf create-service jobscheduler standard jobscheduler -c '{"enable-xsuaa-support":true}'
- Log into the Job Scheduler Dashboard from the service instance in SAP Cloud Platform
- Create a job with
Target Application
set toiot-integration-svc
,HTTP Method
set toPOST
andAction
set to{IOT_INTEGRATION_APP_URL}/process
, e.g.https://mytenant-iot-integration-svc.cfapps.eu10.hana.ondemand.com/process
- Create a schedule for this job with your desired frequency. The job process will run asynchronously and the schedule log can be checked for the result of the process.
- Sample app only synchronizes Delivery and Material data from S/4 HANA Cloud
- SAP Cloud Platform IoT device model and Leonardo IoT model must be created manually through configuration UI, only Things are automatically created
- S/4 HANA Cloud Deliveries must contain only one Material at a time
- Only Basic Authentication is supported with SAP Cloud Platform IoT and S/4 HANA Cloud connectivity
- In case a delivery is deleted or cancelled, it is expected that the Thing will be deleted manually
- The following S4 OData services will be used to fetch HU/Deliveries
- API_HANLDING_UNIT
- API_OUTBOUND_DELIVERY_SRV
Please check the Leonardo IoT or SAP Cloud Platform IoT topic at http:https://answers.sap.com for answers or to ask a new question relative to this sample application and relative to the products used. You might be referred to other support forums and channels from there.
Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file