Creating Network Traffic to SAP Cloud Platform IoT Service with IoTify
In this blog post we are going to learn how to quickly populate your SAP Cloud platform with relevant data when data is still not available and you want to focus on developing your IoT applications with SAP. We will do this by generating data with IoTIFY’s Network Simulator and sending it to the Internet of Things service in SAP Cloud Platform.
This is a first contact post to show the ease of combining IoTIFY’s tools for IoT development and SAP Cloud platform. In subsequent posts we’ll probably dive deeper into more practical applications with SAP Cloud platform and enhanced IoTIFY network simulation templates.
In order to follow this tutorial it is important that you have a IoTIFY account and a SAP Cloud Platform free trial account. Also it’s necessary that you have previously deployed the IoT service in the cloud platform. If you’re not familiar with this procedure you can follow it here:
https://blogs.sap.com/2016/02/01/little-known-ways-to-try-hcp-iot-services-using-simulator-part-2/
So, enter the SAP Cloud Platform homepage and let’s get started…
- In the home page of SAP Cloud Platform it’s important to copy the account name because we’re going to need it later.
- To open the IoT services dashboard we go to the left panel and click services. In the services list we search Internet of Things Services.
- Once inside we need to click Go To Service. This is going to take us to the IoT Service Cockpit
- In the IoT Services Cockpit the first thing that we’re going to do is create a new Message Type. Click the Message Types tile.
- The message is going to have the following attributes::
- Name: NetworkSimulationMessage
- temperature: double
- latitude: float
- longitude: float
- humidity: double
- Then we click on Create. It’s important that we copy the ID of the message because we’re going to use it later. Then we go back to the cockpit
- We click on the Device Types tile and go to the + sign to create a new Device Type. This new Device Type is going to have the following attributes:
- Name: NetworkSimulationDeviceType
- AssignmentName: MFD
- Message Type: NetworkSimulationMessage
- Direction: From Device
- We click on Create. It’s important that we also copy the ID of the message type because we’re going to use it later. Then we go back to the cockpit
- Go to the Devices tile and create a new Device with the following attributes:
- Name: NetworkSimulationDevice
- DeviceType: NetworkSimulationDeviceType
- Once you create the Device a pop up is going to emerge and show you the oAuth access token, it is important that you copy this token because we’re going to use it later.
- Once you copy the token, copy the device ID too and proceed to close the pop up. Then you can go back to the cockpit. Until now what we have done is create the template of the message and the tokens for the device. Now we’re going to use this to send a test message to be sure that we have all up and running.
- Click on the Send and View messages tile
- Go to the Messaging through HTTP tile. In this tile we’ll create the URL to do the POST and create the body of the message that we’ll send.
- In the Data Endpoint section we need to change the last part of the string for the device ID that we copied in step 11.
- In the Message section we need to create the body of the message that we’ll send. It’s important that the order of the body messages attributes follows the same order we created in the message type in step 5. The Message Type string is the ID that we copied in step 8. At this stage, we will content by typing out random values manually.
{
"mode": "sync",
"messageType": "71a6d731a4c62acdfab4",
"messages": [
{
"temperature": 23.5,
"latitude": 10.4709293,
"longitude": 66.8747017,
"humidity": 30
}
]
}
- After you finish the configuration press the send button.
- If all the configuration is OK we should receive a 200 code indicating that the message was received by the platform. In this case we already have the URL to post the message and the body template to send.
- Go back to the previous page and press the Display Stored Messages tile.
- In this list we can see the physical tables generated by our devices. Specifically we’re interested in the table called T_IOT_<Message_ID>. This message ID is the one we configured in step 5, and we should see here all the messages that we generated in the previous point.
- I sent 4 messages using the tool that we previously saw in step 17.
Now that we have setup and configured our service it’s time to go toiotify.io and configure the Network Simulation environment to send random generated messages to our IoT service.
- Open the IoTIFY web page and create or use an existing account. .
- Go to Network tab and create a new template.
- In this page we need to configure the network simulation parameters. To do so fill the blanks as follows:
- Name: NetworkSimulationSAP
- Connection Type: HTTP
- Protocol: Https
- Host: iotmms<HCPuser>.hanatrial.ondemand.com (We copied this user ID in step 1)
- Path: com.sap.iotservices.mms/v1/api/http/data/<device_ID> (we copied this device ID in step 5)
- Method: Post
- Additional Header:
- Content-Type: application/JSON; charset=utf-8
- Authorization: Bearer <Device oAuth> (We copied this token is step 10. It’s important that you leave a blank space between the word Bearer and the token)
- On the Specify Message Contents section we’re going to paste the message that we generated in step 15 with some changes to it. The great advantage of generating Network Traffic with IoTify is that you can put practically any function to generate data inside the body of the message. In this first example we’ll use the following random generation function. In subsequent blog posts we will show how to get the most out of SAP Cloud Platform with simple functions in IoTIFY:
{
var messages = [];
var message = {};
message.temperature = chance.floating({min:0, max:25, fixed:2});
message.latitude = chance.latitude();
message.longitude = chance.longitude();
message.humidity = chance.integer({min: 10, max: 90});
messages.push(message);
return(JSON.stringify({'mode': 'async', 'messagetype': 'bb5b6644d677a6bf6c42',messages}));
}
- When you click save the page is going to send us to the next step of the configuration. In this step we need to configure how many messages we want to send and from how many clients. Use this example at first:
- NetworkTemplate: NetworkSimulation
- Name: NetworkSimulation1
- Number of Clients: 100
- Repeat Message: 20
- Every: 10
- This is going to simulate 100 devices sending information every 10 seconds. This is going to repeat 20 times to a total of 2000 send messages.
- Once the simulation it’s done we can see the stored messages in our IoT service. The table should have 2000 new messages with random information in the attributes:
And that’s all! I hope you enjoyed the tutorial!
Nicolas Araque
SAP Presales Specialist
Great tutorial Nicolas! GJ!!!