I am trying to build a flow, that reads sensor data and transfers by CANBUS. Sometimes, null
data is coming what I mean is tempInt
or ldrInt
could be null.
var msg2 = {
payload:
{
"$class": "org.acme.testnetwork.UpdateSensorData",
"sampDevice": "houseMehmet",
"newTempVal": tempInt,
"newLightVal": ldrInt,
"timeStamp": Date().toString()
}
};
Although I can access msg.payload.newLightVal
and set it to any value, in the case that its value is null, the control statement such below fails.
if(msg.payload.newLightVal===null){
msg.payload.newLightVal = -1 ;
}
Are you sure that tempInt
and ldrInt
are null
and not undefined
.
I think they may be undefined
in which case replace ===
with ==
in the if statement i.e
if(msg.payload.newLightVal==null)
Edit : Since the msg.payload.newLightVal is NaN , this should be the if clause
if(msg.payload.newLightVal==null || isNaN(msg.payload.newLightVal))