Skip to Content
0
Apr 25, 2018 at 10:26 AM

Push Message SAPUI5 to IoT

149 Views Last edit Apr 25, 2018 at 12:40 PM 3 rev

Anton Levin

Good morning,

Today's question is how can I make a push message on an SAPUI5 apk and send it to the IoT MMS.

The program consists on 2 button, led on & off. The code shown bellow is when on button is pressed.

I have wrote the following code, but doesn´t work.

What do I have wrong?

var hostIoT = 'https://iotmmsXXXXXXtrial.hanatrial.ondemand.com';
var portIoT = 443;
var pathIoT = '/com.sap.iotservices.mms/v1/api/http/data/';
var authStrIoT = 'Bearer XXXXXXXX'; //my oauth token
var deviceId = 'XXXXXXXXX'; //my device id
var messageTypeID = 'd4aebec191ebeab85f72';
            
            
 var http = require('https');
 var options = {
   host: hostIoT,
   port: portIoT,
   path: pathIoT + deviceId,
   agent: false,
   headers: {
      'Authorization': authStrIoT,
      'Content-Type': 'application/json;charset=utf-8'
   },
       method: 'http'
   };
 options.agent = new http.Agent(options);
 var callback = function (response) {
      var body = '';
      response.on('data', function (data) {
           body += data;
    });
    response.on('end', function () {
    });
    response.on('error', function (e) {
    });
 };
 var req = http.request(options, callback);
 req.on('error', function (e) {
 });
                
 req.shouldKeepAlive = false;
 var jsonData = {
     "mode": "async",
     "messageType": messageTypeID,
     "messages": [{"fecha":"3566485686","estado":"on"}]
 };
 var strData = JSON.stringify(jsonData);
 req.write(strData);
 req.end();

Thanks,

Alvaro