EDUCAÇÃO E TECNOLOGIA

CAI Challenge Submission : Integrate SAP CAI Chatbot using sensor data from SAP IoT and Google Maps

When I first started using consumer facing AI products like those from Google, Apple and Amazon; I always wondered if a use case could be implemented to address actual business problems without significant development efforts. With SAP CAI, that thought is now a possibility. One such use case is how we can make the already smart CAI chatbot even smarter by extending integration from CAI-to on premise systems to CAI- to cloud hosted IoT solutions.

Our primary use case for this exercise will be to get Truck related metadata from an SAP IoT instance and query its characteristics [or measures in this context] (such as temperature, battery, pressure, location co-ordinates etc.) and eventually propagate and consume it in to the CAI client hosted on Fiori Launchpad.

You’ll need to subscribe to an SAP IoT instance on the CP (now Business Technology Platform). You will need to have basic data loaded into the instance and have sample measures loaded as time-series data. As this blog is focused towards CAI, I won’t go over the details of setting up the IoT Instance from scratch but rather just upload data relevant to this use-case. In the screenshots below I will also be masking some url/ client IDs for data privacy reasons. If you’re new to SAP IoT, check out this blog on how to get started with your own IoT Instance.

You’ll also need to have a CAI chatbot ready and configured to basic skills in the CAI Portal. Check out this tutorial to get things underway.

To insert mock data into the Timeseries DB within IoT, you will need to have an MQTT client installed on your machine. I am using Eclipse Paho MQTT Client for the same.

Setup IoT Cockpit

Open the IoT Cockpit. You will find the hyperlink within the Instances and Subscriptions page under the subscribed tenant. Open Thing Modeler app and click on Thing Type to ensure that basic and measure values are configured.

Thing%20Type%20Configuration

Ensure that sensor type configuration is maintained (we will use this sensor type value [sensor001] to feed mock data into the instance DB below).

Sensor%20Type%20Configuration

Load Mock Data

Now that we have configured Thing Type and Things in the IoT cockpit. We are now ready to feed some test data into the IoT system’s Timeseries Database.

In the MQTT client, you will need to give the Server URL and the Client ID which in our context is the Device ID.

Once you have set up connection to the Instance from the Paho Client, create a publication topic (in my case: measures/device001) and draft a JSON payload to send as message. I am using the below test data in the format it is configured in the Thing Type configuration.

{ "capabilityAlternateId": "condition", "sensorAlternateId": "sensor001", "measures": [{ "batteryPerc":"39", "latitude": "49.293424", "temperature": "-2.6", "speed":"0", "longitude": "8.642058" }]
}

Once you have built the payload, publish the message to the server. You may optionally create a subscription to the service to monitor the response code. In my case the data was saved successfully with a return code ‘202’.

Verify Data

In order to ensure that data is correctly loaded into the time series DB of the IoT Instance, we need to query the URL using Thing ID. But for that, we first need to fetch the Bearer Token. I am using Postman to do this operation.

Fetch%20Bearer%20Token

Fetch Bearer Token

Now that you have the Auth token with you, you can use it to query the time series data from the DB.

Fetch%20Time%20Series%20Data

Fetch Time Series Data

Ensure that the data we published using the MQTT client is same as the data we retrieved from the IoT Service. In the screenshot above, I can verify the same.

However, I also want to the show the Chabot user, which vehicle the time series data belongs to. The assumption here is that the user that has logged onto the Chatbot is assigned a vehicle tagged to their user ID.

Fetch%20Vehicle%20Resource%20name

Fetch Vehicle Resource name

Consume Data in CAI

Great, if you’ve completed configuring the above steps from this article, 80% of the job is done. Now let’s get this data talking to the CAI Client.

Create an Intent

For the purpose of this article, I will keep things simple but as you might have already imagined, the use cases for such an application could be countless. I will create a basic intent to recognize that the user wants to get information related to the vehicle(s) on the road.

Create%20an%20Intent%20on%20CAI%20Platform

Create an Intent on CAI Platform

Create Skill and Action

Next, I create a Skill and set its trigger to the ‘get-vehicle’ intent I just created.

Create%20a%20Skill%20with%20the%20newly%20created%20Intent%20as%20Trigger

Create a Skill with the newly created Intent as Trigger

Here, we want to query data from the IoT instance directly and for that we need to fetch the bearer token again except here (instead of Postman), we directly input the fields in the CAI Platform’s Action Tab under the Message Group for ‘Consume API Service’.

Fetch%20Bearer%20Token%20using%20the%20POST%20method%20and%20set%20the%20Header%20as%20shown%20to%20-%20application/x-www-form-urlencoded

Fetch Bearer Token using the POST method and set the Header as shown to – application/x-www-form-urlencoded

Almost there, now that we have authenticated the bot with IoT, all we need to do is make another API call using the ‘Thing ID’ we configured above.

Call%20the%20API%20and%20save%20measures%20into%20the%20Bot%20memory

Call the API and save measures into the Bot memory

As you might have already noticed I have stored some of the retrieved measures in to the Bot memory. I’m doing to leverage platform provided scripting syntax in order to make my bot display information in a more user-friendly, UX driven manner.

And we are done!! Since the bot is already integrated with SAP TM’s Fiori Launchpad, I only need to login to my account and see the “magic” unfurl.

Here, I click on the Quick Reply ‘Track Vehicle’ to trigger the ‘get-vehicle’ intent.

Map Icon Credits – Google Images

And here we go, we see that bot fetched latest information for resource – ‘Vehicle001’ which last reported an event on Feb 26th, 2021 around 8PM with an onboard cold storage freezer maintained at -2.6 deg Celsius and battery at 39% sitting stationary outside the mentioned GPS co-ordinates.

On clicking the hyperlink, we are re-directed to a Google Maps webpage initialized to co-ordinates: 49.293 LAT and 8.642 LON which also happen to correspond to a location we are all familiar with.

Image Reference – Google Maps

Awesome! We have now enabled our Bot to be able to talk to IoT devices directly and I can only imagine the sheer number of innovative use-cases this integration allows us to accomplish.

Please let me know what you all think of this article. If you like what you just read, please give it a ‘like’ and I will be happy to give you all a Live Demo in the next SAP Community Call. If you are interested to know more about my fixation towards User Experience in a Conversational AI solution, give my other blog – Need for UX Driven Conversational AI a read. Feel to free to also check out my colleague’s blog on Conversational AI’s Use cases within SAP TM.

Thank you !!

– Vaibhav Deorukhkar