SAP Cloud Platform IoT Services, end to end scenario.
One of the most important features of the internet of things is its massive data component (many devices sending and consuming information). The harmonization of all this information, coming from thousands of different places and nodes, is the first step in intelligence a company builds in favor of business.
To demonstrate the fundamental value of the IoT as a generator of new business models, any Proof of concept, demonstration project or first project iteration should utilize value data to get a clear picture of the scenario and IoT ecosystem in play. Sending random information from IoT endpoints would be asking business, back-end and predictive analytic teams too much imagination for a simple concept that should make sense and should be taken care of seemingly.
In this sense, we will carry out a series of blog posts where we will learn how to develop an end-to-end scenario on a real-life application with SAP Leonardo components, in a very efficient way by using smart endpoint simulation provided by iotify.io and utilizing the power of SAP in the field.
We will use IoTIFY to create massive amounts of real-time data for N number of trucks delivering goods from city to city with simple and short lines of code. This real-time data for each simulated truck will include GPS coordinates, temperature, speed, etc.
Integrating it with SAP Leonardo components will allow us to prototype a complete and end-to-end IoT solution very efficiently and with real life expected data and analytics.
Overview & Agenda for this blog post:
- Section 1: Configuring the IoT service with SAP Cloud Platform
- Section 2: Generating smart traffic in real time with IoTIFY Smart Network Traffic Generator
Section 1: Configuring the IoT service with SAP Cloud Platform
Let’s start by fine-tuning the IoT service on the SAP Cloud Platform. For that, we have to go to the main page and carry out the following steps
- Once on the SCP home page, it is important to remember the name of the account we are on. We will be using this a lot in the following steps. In the case of this tutorial, our account id is: i850231trial
- Then, in the taskbar on the left we go to Services. In the list of services, we look for Internet of Things Services
- Once inside, we click on: Go To Service
- Once in the service, we click on Message Type and we create the following message
- The message will have the following attributes
- Name: SmartTruck
- ID string
- Start: string
- End: string
- Loadper: integer
- Latitude: float
- Longitude: float
- Speed: double
- Insidetemp: double
- Outsidetemp: double
- We click on create, we save the ID of the message and we go to the cockpit menu.
- We now select Device Types and we create a new type of device with the following attributes:
- Name: TruckDevice
- AssignmentName: SmartTruck
- Message Type: SmartTruck
- Direction: From Device
- We click on create, we copy the ID of the Device Type and we go back to the Cockpit menu.
- Next step is to create a Device. In order to do that, we click on Devices and we proceed to create a new device with the following attributes:
- Name: DeviceTruck
- DeviceType: TruckDevice
- Once the Device is created, a pop up window will appear with a Token. It is very important to save that token somewhere we can access it later. It will be used later on.
- Close the pop up window, copy the ID of the Device and go back to the Cockpit menu.
- We now go to Send and view messages
- We then go to Messaging through HTTP. In this section we will have to create both the URL and the message to be sent, it’s a validation step.
- In Data Endpoint we will change the last part of the string with what we obtained as Device ID in one of the previous steps.
- https://iotmmsi850231trial.hanatrial.ondemand.com/com.sap.iotservices.mms/v1/api/http/data/<device_ID>
- In Message, we will create a standalone example message to be sent. It should be noted that the attributes of the message should coincide with the attributes of the message type we created on a previous step. The MessageType should be the same MessageType ID we obtained previously too.
{ "mode": "sync", "messageType": "bb5b6644d677a6bf6c42", "messages": [ { "ID": "FROF5QOSOY", "start": "Berlin,DE", "end": "Nuremberg,DE", "loadper": 64, "latitude": 52.519755, "longitude": 13.404025, "speed": 6, "insidetemp": 11.471803869858926, "outsidetemp": 12.408207353298506 } ] }
- Once the configuration of the message and the Data Endpoint are complete, we will click on Send.
- If everything is correct, we should receive a response code 200. This will mean we have correctly configured everything up to now.
Section 2: Generating smart traffic in real time with IoTIFY Smart Network Traffic Generator
- In this step, we will go to iotify.io and create an account if we still don’t have one. The free account offered by IoTIFY is enough to carry out this tutorial.
- Once within IoTIFY, we will go to the Network tab and we will create a new network template.
- We will configure the template as follows:
- Name: SmartTruckSimulation
- Connection Type: HTTP
- Protocol: Https
- Host: iotmms<AccountName>.hanatrial.ondemand.com
- Path: com.sap.iotservices.mms/v1/api/http/data/<device_ID>
- Method: Post
- Aditional Header:
- Content-Type: application/JSON; charset=utf-8
- Authorization: Bearer <Device oAuth> (Note that there is an empty space in between Bearer and the Device oAuth)
- Please note that <AccountName>, <device_ID> and <Device oAuth> must be replaced by the values we obtained in the previous steps. The following image shows how this would look like:
In the specify message contents we will copy the message we generated in the Send and Receive messages over at SAP Cockpit.
The advantage of generating traffic with IoTIFY is that IoTIFY will allow us to create smart traffic based on whatever open source JS functions. This means that the data we send over to the IoT Service will have a meaning.
In our case, we will be simulating GPS positions for Refrigerator Trucks driving around real streets. The formulas used are based on open source JS libraries.
https://iotify.help/ has many examples of data that can be sent and guides to help you create your custom data.
{
if(state.ID === undefined)
{
state.ID = chance.string({length:10 , pool:'1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ' });
state.start = chance.pickone(['Munich,DE', 'Leipzig,DE','Nuremberg,DE','Hanover,DE','Berlin,DE','Dortmund,DE','Stuttgart,DE']);
state.end = chance.pickone(['Munich,DE', 'Leipzig,DE','Nuremberg,DE','Hanover,DE','Berlin,DE','Dortmund,DE','Stuttgart,DE']);
state.loadper = chance.integer({min: 60, max:100});
}
var messages = [];
var message = {};
var path = drive({start: (this.start), end: (this.end), accuracy:50});
message.ID = state.ID;
message.start = state.start;
message.end = state.end;
message.loadper = state.loadper;
message.latitude = path.latitude;
message.longitude = path.longitude;
message.speed = path.speed;
message.insidetemp = chance.normal({mean:10, dev:3});
message.outsidetemp = chance.normal({mean:11, dev:3});
messages.push(message);
return(JSON.stringify({'mode': 'async', 'messagetype': 'bb5b6644d677a6bf6c42',messages}));
}
If we click on preview, it will show us an example of message to be sent. You can see that IoTIFY will send data according to the formulas you put up. It will also inform us if it managed to establish a successful connection with the IoT Service at SAP Cloud Platform.
- Once saved, it will take us to the simulate screen to configure the simulation. We will have to complete it with the following info.
- NetworkTemplate: SmartTruckSimulation
- Name: SmartTruckSimulationV1
- Number of Clients: 20
- Repeat Message: 2000
- Every: 30
- Note that Number of Clients represents the number of endpoints for the simulation. In this case it means that we will be simulating in real time 20 trucks going around from city to city sending information every 30 seconds. These messages will be sent by each client a total of 2000 times, meaning the simulation will end at 30 seconds x 2000 = 1000 minutes = Over 16h. 16h seems like a long simulation, we hope our trucks get to their destination!
Once we click on start generation we can get back to the table that contains the messages over at the SAP IoT Service to see the messages arriving in real time.
From this table, we will need to copy part of the link shown when clicking on OData API (top right). This will allow us to fork to this database in subsequent steps. We should end up with a link similar to:
https://iotmmsi850231trial.hanatrial.ondemand.com/com.sap.iotservices.mms/v1/api/http/app.svc/SYSTEM.T_IOT_BB5B6644D677A6BF6C42
From the previous link we only need to copy until app.svc to get the link to the service. It should look like the following link:
https://iotmmsi850231trial.hanatrial.ondemand.com/com.sap.iotservices.mms/v1/api/http/app.svc
Tks Nicolas. Great example IoT Services, end to end scenario.