on 04-25-2018 11:26 AM - last edited on 02-04-2024 3:06 AM by postmig_api_4
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
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.
[2] https://answers.sap.com/questions/476460/sap-leonardo-iot-1.html?childToView=479637#comment-479637
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
69 | |
8 | |
8 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.