Hi Colleagues,
I am trying to call post method in xsjs file from beaglebone .XSJS file is created on hanatrial account.
I am able to call the XSJS file from browser and postman and it works fine
Please find the beaglebone code which is giving HTTP 303 code.
var b = require('bonescript'); // Imports the BoneScript library
var uuid = require("node-uuid");
var http = require('https');
b.pinMode('P8_19', b.INPUT);
var last_value;
var flag;
setInterval(checkPIR, 10000); // Checks the Sensor Every 2.5 Seconds
function checkPIR()
{
b.digitalRead('P8_19', printStatus);
}
function printStatus(x) {
if(x.value === 0){
console.log("No Motion Detected");
flag = "T";
}
else{
console.log("Motion Detected");
flag = "F";
}
// if(last_value !== x.value)
writeToHana(flag);
last_value = x.value;
}
function writeToHana(value) {
var http = require('https'); //change to https to connect via internet
var fs = require('fs');
//var appRoot = process.cwd();
//var cer = fs.readFileSync(appRoot +'/hanatrial.cer','utf8');
var options = {
host: 's11hanaxs.hanatrial.ondemand.com',
port: 443,
path: '/i309839trial/dev/HuddleRoom/services/postdata.xsjs',
agent: false,
headers: {
'Authorization': 'Basic ' + new Buffer('username' + ':' + 'password').toString('base64'),
'Content-Type':'application/json; charset=utf-8'
},
method: 'POST',
//cert: cer
cert: fs.readFileSync('/var/lib/cloud9/HuddleRom/hanatrial.ondemand.cer')
};
options.agent = new http.Agent(options);
// Define callback responses
callback = function(response) {
console.log("statusCode:", response.statusCode);
response.on('data', function (data) {
});
response.on('end', function (data) {
console.log('Requested Ended at:');
});
response.on('error', function(e) {
console.log('get error');
console.error(e);
});
}
var req = http.request(options, callback);
req.on('error', function(e) {
console.error(e);
});
req.shouldKeepAlive = false;
var strData = JSON.stringify({
"Available": "F",
"roomNumber": "BLR25.B4.R10"
});
req.write(strData);
console.log(strData);
req.end();
}
Attached is the screenshot of error.
Please help me in resolving this error.
Thanks & Regards,
Pushkar