cancel
Showing results for 
Search instead for 
Did you mean: 

IoT destinations in mobile Apps not working

marcus_schiffer
Active Participant
0 Kudos
157

Hi,

after building an App which uses the IoT services from the HANATRIAL platform (using the IoT.js methods) , we want  to convert this web-app into a mobile hybrid app. The App sends IoT data using the oAuth token of a certain device configuartion to simulate a IoT device and works well as deployed on the HANAtrial.

The corresponding  app was build by use of the HAT (1.17.2) and successfully registered to the mobile services via Kapsel logon plugin.

Unfortunately the services are not working, i.e. there seems to be no connection to the HANA trial IoT services.

We were trying different approaches to configure the backend destination in the app customizing on the trial landscape mobile services ( e.g. user http://iotmms/http/api where iotmms is the destination from HANA cloud trial platform which works with the deployed WebApp).

However every setting resulted in either "not found" or "403 no authorization" when trying to ping the destination.

What might be the destination setting working for this scenario ? Or do we need to change the WebApp to make the oAuth connection ?

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Marcus,

Actually you do NOT need configure any backend connections. When you inject the IOT.js, it already injected the direct service URL in.

Pls check and make sure you have some lines in your IOT.js like below:


if(location.protocol !== "https:") {

  setServiceUrl(

    "https://iotrdmsx36737db5-XXXX.neo.ondemand.com/com.sap.iotservices.dms/api/",

    "https://iotmmsXXXX.neo.ondemand.com/com.sap.iotservices.mms/v1/api/http/");

}

And if you want to invoke any API on the device, you have to provide Authorization header, either Basic or OAuth. like below example:


IOT.getDeviceTypes(function(res){

    console.log(JSON.stringify(res, null, 4));

}, function() {

    MessageToast.show("Error");

}, {

    headers: {

        "Authorization": "Basic " + btoa("<username>:<password>")

    }

});

or


//...

    headers: {

        "Authorization": "Bearer " + oAuthToken

    }

//...

marcus_schiffer
Active Participant
0 Kudos

Hi Sheng,

thanks for the hint. Is the "xxx" representing the user ID on HANA TRIAL like eg. s123456trial ?

That I would then use in the IOT.js file included in my app. Then the app could be build with HAT and connect to the IOT Service ?

0 Kudos

yes, the XXXX should be the actual HANA account name.

you don't need change anything manually. It will replace the 2 URLs automatically, before inject iot.js into your project,

you just need make sure correct Authorization header is supplied. Then the app could be build awith HAT and connect to the IOT service.

Regards,

YaoSheng

marcus_schiffer
Active Participant
0 Kudos

then seems like it is a bug of "inject IOT library"

could you try replacing these 2 URLs with the correct service url which configured in your destination?

Regards,

YaoSheng

Answers (1)

Answers (1)

thomas_zang
Product and Topic Expert
Product and Topic Expert
0 Kudos

HI,

To consume IoT feature in Web IDE, the following configurations need to done:

  1. Enable Internet of Things Services in SAP HANA Cloud Platform Cockpit.
  2. Assign roles for Internet of Things Services.
  3. Configure the destinations for Internet of Things Services Message Management Service and Internet of Things Services Device Management Service.
  4. Configure OAuth authentication.

Please find the details  in the following doc link.

SAP Web IDE Hybrid App Toolkit Add-on

regards,

thomas

marcus_schiffer
Active Participant
0 Kudos

Hi Thomas,

thanks for the hint.

The app is working properly when called as web App (that is when choosing run as->Web APP from IDE)

So all the IoT services seem to work, since the data is injected into th eIoT database and can be viewed in the IoT service.

Now when I deploy the App to the HAT on my local computer, the app is also created and can be viewed in the android simulator.

The problem is, that I think I have to configure the backend connections. As I understand in these connections I need to insert the URL to the hIoT services. However, I tried a lot of configuratiuions like onPremise with the destination names or even the full URL to the IoT data service and type internet. But nothing made the app send data to the IoT services. I also see no way of monitoring the request, and I am stuck here.