I want to make a stopwatch for some condition in my project.
for ex. if my node get data(something like "START") from mqtt so that will make a time count too, time will count untill my node get an another data(like "STOP") and I'll record that time between start and stop (ex. 01:32:24 ).
Thank you.
Well, one way of doing this is when you send the "Start" and "Stop" signals, you include a time stamp with them.
Then you simply subtract them.
Rather than sending ONLY a "message", send it with a TOPIC which will be used to determine if it Stops or Starts.
Eg:
(Two buttons)
Both inject the "time stamp" - which is the default in the inject
node.
Set the topic
for on as START and the topic
for the other as STOP.
Use a function
node.
Something like:
let difference = 0;
let start = 0;
if (msg.topic == "START")
{
context.set("START",msg.payload)
}
else
if (msg.topic == "STOP")
{
start = context.get("START");
difference = msg.payload - start;
msg.payload = difference
}
return msg;
Something LIKE that.
I'm not a coder, and I may have made a mistake in there, but I hope you can see the concept of what I am meaning.
Then send that node to another node (who's name I can't remember) to format it into a time format.
Thank you for reply me.
I'll try your suggestion and I have few question but let me try this first.