Check state and send to mqtt from multiple array

#1

Hello i need some help , how to check casenamemax inside any array [0][1][2]........

example if case == 01 send to mqtt ........ with all index data status,imei,casenamemax

or case == 02,03 ...... send

image

Thank you for reply

#2

Use the function node and do it in javascript

#3

yeah i use it in javascript and i dont know how to write it thx sir

#4
 var l = msg.payload[0].length;

for (var i = 0; i < l; i++) {
   node.send({
        payload: msg.payload[0][i].casenamemax
  });
}
return msg;

I try this code can output same as i send before

#5

The msg.payload[0][i] bit is wrong and the length calculation, and also you are returning the original message at the end. Something like this may be better.

var l = msg.payload.length;
for (var i = 0; i < l; i++) {
   node.send({
        payload: msg.payload[i].casenamemax
  });
}
return null;

For the future you can debug your code using node.warn(). So after the var l = .. line you could have put

node.warn("l is " + l);

and it would have displayed the value of l in the debug pane. By adding warn statements through the code you can find which bit is not working.