我正在尝试使用函数节点中的此函数将 JSOn 数据发布到云中。
var accx = 15;
var accy = 45;
var accz = 12;
//JSON FORMING BY JAVASCRIPT OBJECT
var output = [];
output[0] = {
name: "Accel_X",
value: accx.toString(), // retrieve x
};
output[1] = {
name: "Accel_Y",
value: accy.toString(), // retrieve y
};
output[2] = {
name: "Accel_Z",
value: accz.toString() // retrieve z
};
var record = [];
record[0] = {
starttime: formatDate(new Date()),
output: output,
};
var observations = [];
observations[0] = {
sensor: "C2105",
record: record,
};
var fromData = {};
fromData.version = "1.0.1";
fromData.observations = observations;
//MONTH NAME FUNCTION
function show_now(){
var my_month=new Date()
var month_name=new Array(12);
month_name[0]="JAN"
month_name[1]="FEB"
month_name[2]="MAR"
month_name[3]="APR"
month_name[4]="MAY"
month_name[5]="JUN"
month_name[6]="JUL"
month_name[7]="AUG"
month_name[8]="SEP"
month_name[9]="OCT"
month_name[10]="NOV"
month_name[11]="DEC"
return month_name[my_month.getMonth()];
}
//RETURN DATE AT FORMATTED WAY THAT IS ACCEPTED BY CLOUD
function formatDate(d) {
return d.getDate() + '-' + (show_now()) + "-" + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + " IST";
}
var fromDatan = JSON.stringify(fromData);
//alert(fromDatan);
//POST JSON SENSOR DATA
fromDatan.headers = {
"x-api-key": "ucrFr234r23rrxfAIH2L4=",
"content-type": "application/json;charset=UTF-8"
}
return fromDatan;
我在 url 节点中给出了正确的 url,但它没有返回任何响应,而且我没有看到任何数据正在发布任何人请使用 node-red.js 请帮助。