on 10-27-2016 9:35 PM
I have created an HTML5 app that i am running in HCP which shows sensor data coming off my Raspberry PI which works fine. However i would like to enable bi-directional communication and also be able to send messages to it via the Websockets Push functionality. I have defined my ajax request with the following parameters:
type: 'POST'
headers: "Authorization" : "Bearer b6d385552c9c49090ad65c48e896dc4"
url:https://iotmmsd2b412a60.us2.hana.ondemand.com/com.sap.iotservices.mms/v1/api/http/push/af55c60f-13fc-47b0-b09d-00f318da5d1d
data: ("method":"ws", "sender":"Sensor Monitor Application", "messageType":"243dbaf4dcb840dfafbe", "messages":[ { "photo_request": "false", "led_display": "test test"]}
Where the photo_request boolean is for the pi camera to capture an image and the led_display string to display the message on the LED display.
However when i trigger the call i get the following error. I can send the POST via POSTMAN but not through Chrome as i test my app through WebIDE:
Failed to load resource: the server responded with a status of 401 (Unauthorized) https://iotmmsd2b412a60.us2.hana.ondemand.com/com.sap.iotservices.mms/v1/api/http/push/af55c60f-13fc...
XMLHttpRequest cannot load https://iotmmsd2b412a60.us2.hana.ondemand.com/com.sap.iotservices.mms/v1/api/http/push/af55c60f-13fc.... Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://webidetesting0272800-d2b412a60.dispatcher.us2.hana.ondemand.com' is therefore not allowed access. The response had HTTP status code 401.
I have configured Destinations as well which i have read are required to avoid this CORS issue but in my case it does not appear to have any effect. See Destintions below:
Name=IoT_MMS_API Description=IoT MMS API Type=HTTP Authentication=BasicAuthentication CloudConnectorVersion=2 ProxyType=Internet URL=https\://iotmmsd2b412a60.us2.hana.ondemand.com/com.sap.iotservices.mms User=XXXXXX
Name=IOT_RDMS_API Description=IOT_RDMS_API Type=HTTP Authentication=BasicAuthentication CloudConnectorVersion=2 ProxyType=Internet URL=
https\://iotrdmsiotservices-d2b412a60.us2.hana.ondemand.com/com.sap.iotservices.dms
User=XXXX
Does anyone know what's missing in order to push messages to a device from a web interface? I think i've followed the documentation to a T but still appear to be missing something. Thanks in advance for your help!
I'd recommend to have a look on a StarterKit example [1], where messages are pushed from web application to the device via HTTP, WS and MQTT.
[1] https://github.com/SAP/iot-starterkit/tree/master/src/apps/java/consumption
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
75 | |
9 | |
8 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.