Skip to Content

Push Message SAPUI5 to IoT

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Apr 25 at 12:55 PM

    Hello Alvaro,

    you are using the wrong API (endpoint URL - ../http/data/{deviceId} is wrong). Please, check with online documentation [1] for "Push Service". A URL to "push" messages to the device should be ../http/push/{deviceId}

    And, as already suggests in another thread [2], I encourage you to have a look at the StarterKit examples. For instance, [3]

    Regards, Anton

    P.S. It also helps (for the potential readers of your question) if you raise it in a more precise manner - saying not just "my code doesn't work" but giving console output, debug infos etc.

    [1] https://help.sap.com/viewer/7436c3125dd5491f939689f18954b1e9/Cloud/en-US/9da1c18f6ab947c58052f4d07498a654.html

    [2] https://answers.sap.com/questions/476460/sap-leonardo-iot-1.html?childToView=479637#comment-479637

    [3] https://github.com/SAP/iot-starterkit/blob/master/neo/apps/java/consumption/com.sap.iot.starterkit.ui/src/main/webapp/js/controller/inbound.controller.js#L91-L110

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 26 at 11:12 AM

    When I make the request, nothing insert on the push table.

    No message sended.

    I cant find the error.

    var oData = {
    				"sender": "My IoT application",
    				"messageType": "d4aebec191ebeab85f72",
    				"method": "http",
    				"messages":[{"fecha":"234454345","estado":"on"}]
    			};
    			
    			var sUrl = "https://iotmmsXXXXXXXtrial.hanatrial.ondemand.com/com.sap.iotservices.mms/v1/api/http/push/XXXXXdeviceIdXXXXXXX";
    			
    			this.doPost( sUrl, oData );
    
    Add comment
    10|10000 characters needed characters exceeded