For the sake of this example the payload looks like this:
Time 10:23:4
Shame it isn't better formatted, but anyway.
In light of recent problems I found this problem - or maybe it has only now stuck its head up.
Weirdly it hasn't shown itself until recently.
This dates back to a problem which happened every day at midnight.
But that's a whole other story.
So:
I am sending in the above message to a function
node.
I want to determine the "seconds past/since midnight".
This is the code:
var hour = parseInt(msg.payload.slice(0,2));
var minute = parseInt(msg.payload.slice(3,5));
var second = parseInt(msg.payload.slice(6,8));
node.warn("Time " + msg.payload);
node.warn("Hour " + hour);
node.warn("Minute " + minute);
node.warn("Second " + second);
var time = hour*3600 + minute * 60 + second;
msg = {payload: time, topic: 'RTC'};
return msg;
There is a second node which sets the topic as local
to differentiate between the clock and the RTC.
Here's the rub:
Screen shot 1:
HWC time parsed by the function
node. See results.
Screen shot 2:
RasPi time parsed by the other function
node with the same code.
Sorry I didn't have the debug
node active.
However: the errors! Why?
It is the same code.
Yes, I am missing an elephant.
I accept I maybe should "split" the string with a :
.
That aside, why does one work and the other fail?
Thanks in advance.