i am creating a custom node that talks to a api i want to add some status to see what is happening but it wont work any help please
module.exports = function(RED) {
function CabinetAction(config) {
RED.nodes.createNode(this,config);
var node = this;
node.id = undefined;
this.area = RED.nodes.getNode(config.area);
this.ip = "";
this.poort = 0;
this.line1 = "";
this.line2 = "";
this.line3 = "";
this.line4 = "";
this.line5 = "";
this.line6 = "";
this.line7 = "";
this.line8 = "";
this.line9 = "";
this.entry = "";
this.badge = false;
this.question = "";
this.questionLenght = 0;
this.digits = 0;
this.decimals = 0;
this.choices = "";
this.out1 = 0;
this.out2 = 0;
this.out3 = 0;
this.out4 = 0;
this.out5 = 0;
this.out6 = 0;
this.out7 = 0;
this.out8 = 0;
this.out9 = 0;
this.out10 = 0;
this.out11 = 0;
this.out12 = 0;
this.out13 = 0;
this.out14 = 0;
this.out15 = 0;
this.out16 = 0;
this.clear = "No";
this.weight = "No";
node.on('input', function(msg, nodeSend, nodeDone) {
//start check message
thisabort = RED.util.evaluateNodeProperty('Abort', 'msg', this, msg);
thiscallback = RED.util.evaluateNodeProperty('CallBack', 'msg', this, msg);
if (thiscallback != undefined && thiscallback != null)
{
if (node.area.areaid == thiscallback.AreaId){
if (node.id != undefined){
if (node.id == thiscallback._msgid){
node.id = undefined;
msg.payload = new Object;
msg.payload.Value = thiscallback.Value;
msg.payload.Type = thiscallback.Type;
delete msg.CallBack;
node.status({fill:"green",shape:"dot",text:"{ Value: '"+thiscallback.Value+"', Type: '"+thiscallback.Type+"' }"});
nodeSend(msg);
nodeDone();
}
}
}
}
else if (thisabort != undefined && thisabort != null && thisabort)
{
node.id = undefined;
}
else
{
node.id = RED.util.evaluateNodeProperty('_msgid', 'msg', this, msg);
prepare(msg,node,config,RED);
node.status({fill:"yellow",shape:"dot",text:"Waiting for message"});
nodeDone();
}
//end check message
});
}
RED.nodes.registerType("Cabinet Action",CabinetAction);
}
function prepare(msg,node,config,RED){
node.ip = config.ip;
if (config.ipType === 'msg' || config.ipType === 'flow' || config.ipType === 'global') {
node.ip = RED.util.evaluateNodeProperty(config.ip, config.ipType, this, msg);
}
node.poort = config.poort;
if (config.poortType === 'msg' || config.poortType === 'flow' || config.poortType === 'global') {
node.poort = RED.util.evaluateNodeProperty(config.poort, config.poortType, this, msg);
}
if (config.line1Type === 'msg' || config.line1Type === 'flow' || config.line1Type === 'global') {
node.line1 = RED.util.evaluateNodeProperty(config.line1, config.line1Type, this, msg);
}else{
node.line1 = config.line1;
}
if (config.line2Type === 'msg' || config.line2Type === 'flow' || config.line2Type === 'global') {
node.line2 = RED.util.evaluateNodeProperty(config.line2, config.line2Type, this, msg);
}else{
node.line2 = config.line2;
}
if (config.line3Type === 'msg' || config.line3Type === 'flow' || config.line3Type === 'global') {
node.line3 = RED.util.evaluateNodeProperty(config.line3, config.line3Type, this, msg);
}else{
node.line3 = config.line3;
}
if (config.line4Type === 'msg' || config.line4Type === 'flow' || config.line4Type === 'global') {
node.line4 = RED.util.evaluateNodeProperty(config.line4, config.line4Type, this, msg);
}else{
node.line4 = config.line4;
}
if (config.line5Type === 'msg' || config.line5Type === 'flow' || config.line5Type === 'global') {
node.line5 = RED.util.evaluateNodeProperty(config.line5, config.line5Type, this, msg);
}else{
node.line5 = config.line5;
}
if (config.line6Type === 'msg' || config.line6Type === 'flow' || config.line6Type === 'global') {
node.line6 = RED.util.evaluateNodeProperty(config.line6, config.line6Type, this, msg);
}else{
node.line6 = config.line6;
}
if (config.line7Type === 'msg' || config.line7Type === 'flow' || config.line7Type === 'global') {
node.line7 = RED.util.evaluateNodeProperty(config.line7, config.line7Type, this, msg);
}else{
node.line7 = config.line7;
}
if (config.line8Type === 'msg' || config.line8Type === 'flow' || config.line8Type === 'global') {
node.line8 = RED.util.evaluateNodeProperty(config.line8, config.line8Type, this, msg);
}else{
node.line8 = config.line8;
}
if (config.line9Type === 'msg' || config.line9Type === 'flow' || config.line9Type === 'global') {
node.line9 = RED.util.evaluateNodeProperty(config.line9, config.line9Type, this, msg);
}else{
node.line9 = config.line9;
}
// msg.Line1 = node.line1;
// msg.Line2 = node.line2;
// msg.Line3 = node.line3;
// msg.Line4 = node.line4;
// msg.Line5 = node.line5;
// msg.Line6 = node.line6;
// msg.Line7 = node.line7;
// msg.Line8 = node.line8;
// msg.Line9 = node.line9;
thisentry = RED.util.evaluateNodeProperty('Entry', 'msg', this, msg);
if (thisentry != undefined && thisentry != null)
{
node.entry = thisentry
}
else{
node.entry = config.input
}
thisbadge = RED.util.evaluateNodeProperty('Badge', 'msg', this, msg);
if (thisbadge != undefined && thisbadge != null)
{
node.badge = thisbadge
}
else{
node.badge = config.badge
}
//msg.Entry = node.entry;
if (node.entry == 'AlphaNumeric')
{
if (config.alphaNumericQuestionType === 'msg' || config.alphaNumericQuestionType === 'flow' || config.alphaNumericQuestionType === 'global') {
node.question = RED.util.evaluateNodeProperty(config.alphaNumericQuestion, config.alphaNumericQuestionType, this, msg);
}else{
node.question = config.alphaNumericQuestion;
}
if (config.alphaNumericLenght === 'msg' || config.alphaNumericLenght === 'flow' || config.alphaNumericLenght === 'global') {
node.question = RED.util.evaluateNodeProperty(config.alphaNumericLenght, config.alphaNumericLenghtType, this, msg);
}else{
node.questionLenght = config.alphaNumericLenght;
}
//msg.Question = node.question;
//msg.QuestionLenght = node.questionLenght;
}
if (node.entry == 'Numeric')
{
if (config.numericQuestionType === 'msg' || config.numericQuestionType === 'flow' || config.numericQuestionType === 'global') {
node.question = RED.util.evaluateNodeProperty(config.numericQuestion, config.numericQuestionType, this, msg);
}else{
node.question = config.numericQuestion;
}
if (config.numericDigitsType === 'msg' || config.numericDigitsType === 'flow' || config.numericDigitsType === 'global') {
node.digits = RED.util.evaluateNodeProperty(config.numericDigits, config.numericDigitsType, this, msg);
}else{
node.digits = config.numericDigits;
}
if (config.numericDecimalsType === 'msg' || config.numericDecimalsType === 'flow' || config.numericDecimalsType === 'global') {
node.decimals = RED.util.evaluateNodeProperty(config.numericDecimals, config.numericDecimalsType, this, msg);
}else{
node.decimals = config.numericDecimals;
}
//msg.Question = node.question;
//msg.Digits = node.digits;
//msg.Decimals = node.decimals;
}
if (node.entry == 'Choice')
{
if (config.choicesType === 'msg' || config.choicesType === 'flow' || config.choicesType === 'global') {
node.choices = RED.util.evaluateNodeProperty(config.choices, config.choicesType, this, msg);
}else{
node.choices = config.choices;
}
//msg.Choices = node.choices;
}
thisout1 = RED.util.evaluateNodeProperty('Out1', 'msg', this, msg);
if (thisout1 != undefined && thisout1 != null)
{
node.out1 = thisout1
}
else{
node.out1 = config.out1
}
thisout2 = RED.util.evaluateNodeProperty('Out2', 'msg', this, msg);
if (thisout2 != undefined && thisout2 != null)
{
node.out2 = thisout2
}
else{
node.out2 = config.out2
}
thisout3 = RED.util.evaluateNodeProperty('Out3', 'msg', this, msg);
if (thisout3 != undefined && thisout3 != null)
{
node.out3 = thisout3
}
else{
node.out3 = config.out3
}
thisout4 = RED.util.evaluateNodeProperty('Out4', 'msg', this, msg);
if (thisout4 != undefined && thisout4 != null)
{
node.out4 = thisout4
}
else{
node.out4 = config.out4
}
thisout5 = RED.util.evaluateNodeProperty('Out5', 'msg', this, msg);
if (thisout5 != undefined && thisout5 != null)
{
node.out5 = thisout5
}
else{
node.out5 = config.out5
}
thisout6 = RED.util.evaluateNodeProperty('Out6', 'msg', this, msg);
if (thisout6 != undefined && thisout6 != null)
{
node.out6 = thisout6
}
else{
node.out6 = config.out6
}
thisout7 = RED.util.evaluateNodeProperty('Out7', 'msg', this, msg);
if (thisout7 != undefined && thisout7 != null)
{
node.out7 = thisout7
}
else{
node.out7 = config.out7
}
thisout8 = RED.util.evaluateNodeProperty('Out8', 'msg', this, msg);
if (thisout8 != undefined && thisout8 != null)
{
node.out8 = thisout8
}
else{
node.out8 = config.out8
}
thisout9 = RED.util.evaluateNodeProperty('Out9', 'msg', this, msg);
if (thisout9 != undefined && thisout9 != null)
{
node.out9 = thisout9
}
else{
node.out9 = config.out9
}
thisout10 = RED.util.evaluateNodeProperty('Out10', 'msg', this, msg);
if (thisout10 != undefined && thisout10 != null)
{
node.out10 = thisout10
}
else{
node.out10 = config.out10
}
thisout11 = RED.util.evaluateNodeProperty('Out11', 'msg', this, msg);
if (thisout11 != undefined && thisout11 != null)
{
node.out11 = thisout11
}
else{
node.out11 = config.out11
}
thisout12 = RED.util.evaluateNodeProperty('Out12', 'msg', this, msg);
if (thisout12 != undefined && thisout12 != null)
{
node.out12 = thisout12
}
else{
node.out12 = config.out12
}
thisout13 = RED.util.evaluateNodeProperty('Out13', 'msg', this, msg);
if (thisout13 != undefined && thisout13 != null)
{
node.out13 = thisout13
}
else{
node.out13 = config.out13
}
thisout14 = RED.util.evaluateNodeProperty('Out14', 'msg', this, msg);
if (thisout14 != undefined && thisout14 != null)
{
node.out14 = thisout14
}
else{
node.out14 = config.out14
}
thisout15 = RED.util.evaluateNodeProperty('Out15', 'msg', this, msg);
if (thisout15 != undefined && thisout15 != null)
{
node.out15 = thisout15
}
else{
node.out15 = config.out15
}
thisout16 = RED.util.evaluateNodeProperty('Out16', 'msg', this, msg);
if (thisout16 != undefined && thisout16 != null)
{
node.out16 = thisout16
}
else{
node.out16 = config.out16
}
thisclear = RED.util.evaluateNodeProperty('Clear', 'msg', this, msg);
if (thisclear != undefined && thisclear != null)
{
node.clear = thisclear
}
else{
node.clear = config.clear
}
thisweight = RED.util.evaluateNodeProperty('Weight', 'msg', this, msg);
if (thisweight != undefined && thisweight != null)
{
node.weight = thisweight
}
else{
node.weight = config.weight
}
if (node.ip !== "") {
fetch("http://"+node.ip+":"+node.poort+"/FlowDevice/SetCabinet", {
method: "PUT",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
"AreaId":node.area.areaid,
"_msgid":msg._msgid,
"Badge":node.badge,
"Choices":node.choices,
"Clear":node.clear,
"Decimals":node.decimals,
"Digits":node.digits,
"Entry":node.entry,
"Line1":node.line1,
"Line2":node.line2,
"Line3":node.line3,
"Line4":node.line4,
"Line5":node.line5,
"Line6":node.line6,
"Line7":node.line7,
"Line8":node.line8,
"Line9":node.line9,
"Out1":node.out1,
"Out10":node.out10,
"Out11":node.out11,
"Out12":node.out12,
"Out13":node.out13,
"Out14":node.out14,
"Out15":node.out15,
"Out16":node.out16,
"Out2":node.out2,
"Out3":node.out3,
"Out4":node.out4,
"Out5":node.out5,
"Out6":node.out6,
"Out7":node.out7,
"Out8":node.out8,
"Out9":node.out9,
"Question":node.question,
"QuestionLenght":node.questionLenght,
"Weight":node.weight
})
})
.then(response => {
if (!response.ok) {
msg.succes = false;
msg.payload = response.statusText;
}
return response.json();
})
.then(data => {
msg.payload = new Object;
msg.payload.status = data;
if (data)
{
msg.succes = true;
msg.payload.statusText = "Action accepted";
}
else{
msg.succes = false;
msg.payload.statusText = "Action not accepted";
}
})
.catch(error => {
msg.succes = false;
msg.payload = error;
});
}
};