What's wrong comparing numbers with switch node? I don't get an error, so I think my code is correct:
The true comes from this function node, where it works:
let val = Date.now() / 1000 | 0; // timestamp in sec
msg.payload = msg.payload === val ? true : false;
My MQTT node uses JSON interpretation, to get a number. The flow:
You will see the red box around your "number" this is because it is not a number, it needs to be evaluated first.
You can use jsonata to do calculations, although current time will change during the operation so you may not get a match to the payload anyway ?
What are you trying to do with the flow ?
If you want to check if msg.payload is true or false, then click the chevron next to "==" and select "is true" or "is false"
 p.s. In your function code, when you divide your timestamp by 1000 you will end up with a float, you will need to round it. You also may want to compare if difference between timestamps(inseconds) is > or < than a certain period.
I don't really understand your answer. Why is it not a number? My code? In my function node, it will generate a number!?
Choosing JSONata will also result in a red box. Perhaps I have to change the code??
Problem could be the correct time, so I will need a function node anyway to unsharp the time.
I get a timestamp from another program on my RASPI via MQTT and this is my way to test, if the program sending the MQTT is alive.
numbers are for numbers only. It does NOT evaluate a forumla.
Your equation is not proper JSONata
The == is just comparing payload with what you type in - it doesn't do the calculation for you.
But if you do something like this, then it will. So injecting payload of 5 will pass to output 1
But as I said you would need to look at reducing the time stamp anyway to allow processing time
Ok, thanks I learned:
== is only for distinct numbers
JSONata is only for basic calculation (like adjust measurement)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.