I am not really sure what I am doing, but to keep the hamster happy upstairs, I am just asking this.
I have a RasPi that is MY NTP server. All my devices use it.
It has a RTC also. Not sure how that is important just now. But I'll mention it here/now.
I know there are NTP nodes out there but they seem to be overkill for what I want to do - I think.
Basically I want a daily NTP check that the clock isn't wonky.
A machine - not sure if it will be THAT one, or another one on the network.
The other machine will get it's time - which I now see is not going to work too well given the scenario I want to test.
I know there is a problem here with what I am about to say/ask.
Ok, two problems. (ARGH!)
I don't get/understand the background workings of NTP, HW and SW clocks and who is taking to whom to get their times.
So I am already in heavy fog for what I am doing.
I have 3 clocks: NTP, HW and SW.
If one of them goes off on an excursion I want to be informed.
So say every 6 hours it looks at the 3 clocks and hope they all match - within a given margin.
If one is wrong, it tells me (sends a message).
The NTP node I have won't poll that slowly.
So I have a command I use:
timedatectl status | grep Local
and I get the local time given to me.
Put that through a string
node and it looks nice:
"Sat 2023-07-01 08:35:49 AEST"
Local time. I know that is no nice, but to establish a base line, I'll talk local for now.
Excuse me for now if this is not THE WAY.
I then read the HW and SW clocks and see if the new reading is within 30 minutes of the last time.
If it was a timestamp
I got back would be a lot easier I know.
Any thoughts on how I can make it easier?
Oh, the exciting code I use to check the NTP side is working:
[{"id":"ce5ac6a3c140825d","type":"exec","z":"675e227d.d158b4","command":"timedatectl status | grep Local","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":530,"y":3000,"wires":[["dff7cbdba175c41a","b1e36e2fa2775905"],[],[]]},{"id":"994fd43d97ac2b98","type":"inject","z":"675e227d.d158b4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":310,"y":3000,"wires":[["ce5ac6a3c140825d"]]},{"id":"dff7cbdba175c41a","type":"debug","z":"675e227d.d158b4","name":"debug 271","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":470,"y":2960,"wires":[]},{"id":"b1e36e2fa2775905","type":"string","z":"675e227d.d158b4","name":"","methods":[{"name":"collapseWhitespace","params":[]},{"name":"delLeftMost","params":[{"type":"str","value":": "}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":350,"y":3070,"wires":[["62557d9dbcb19e34"]]},{"id":"62557d9dbcb19e34","type":"debug","z":"675e227d.d158b4","name":"debug 272","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":370,"y":3110,"wires":[]}]
(Subflow and gate
nodes in here)
And this is how I read the SW and HW clocks.
I send a pulse in and get the two times sent out to the debug
nodes here. They are really text
nodes, but to reduce the junk I am posting....
[{"id":"8d34d18c.a5c1d8","type":"subflow","name":"Time Stamp","info":"","category":"","in":[{"x":80,"y":100,"wires":[{"id":"e238745c.805ad"}]}],"out":[{"x":780,"y":180,"wires":[{"id":"e238745c.805ad","port":0},{"id":"f4d2e3a6.04b528","port":0}]},{"x":780,"y":230,"wires":[{"id":"e238745c.805ad","port":0},{"id":"f24c822.a42738","port":0}]},{"x":780,"y":280,"wires":[{"id":"5da44411.ed02ac","port":0},{"id":"e238745c.805ad","port":0}]}],"env":[],"color":"#FF8888","outputLabels":["For logging use","msg.time","For filename use"],"icon":"node-red/timer.svg"},{"id":"f4d2e3a6.04b528","type":"moment","z":"8d34d18c.a5c1d8","name":"","topic":"","input":"","inputType":"msg","inTz":"Australia/Sydney","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYY-MM-DD HH:mm:ss","locale":"en_AU","output":"","outputType":"msg","outTz":"Australia/Sydney","x":400,"y":180,"wires":[["5da44411.ed02ac","3a4de0cb.6235d"]]},{"id":"5da44411.ed02ac","type":"string","z":"8d34d18c.a5c1d8","name":"","methods":[{"name":"replaceAll","params":[{"type":"str","value":":"},{"type":"str","value":""}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":450,"y":280,"wires":[[]]},{"id":"3a4de0cb.6235d","type":"change","z":"8d34d18c.a5c1d8","name":"TOPIC","rules":[{"t":"move","p":"payload","pt":"msg","to":"time","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":230,"wires":[["f24c822.a42738"]]},{"id":"e584e350.1d8a48","type":"change","z":"8d34d18c.a5c1d8","name":"Save","rules":[{"t":"set","p":"origPayload","pt":"msg","to":"payload","tot":"msg","dc":true}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":140,"wires":[["3411b340.b65a04"]]},{"id":"f24c822.a42738","type":"change","z":"8d34d18c.a5c1d8","name":"Get","rules":[{"t":"set","p":"payload","pt":"msg","to":"origPayload","tot":"msg","dc":true}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":230,"wires":[[]]},{"id":"e238745c.805ad","type":"switch","z":"8d34d18c.a5c1d8","name":"check topic","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"TIMESTAMP","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":210,"y":100,"wires":[[],["e584e350.1d8a48"]]},{"id":"3411b340.b65a04","type":"change","z":"8d34d18c.a5c1d8","name":"TimeStamp","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":210,"y":180,"wires":[["f4d2e3a6.04b528"]]},{"id":"596dfbde.39bc6c","type":"exec","z":"e2bd5a4e.5597e8","g":"9e69bb336a453bf0","command":"sudo hwclock -r","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"HWC time","x":630,"y":2240,"wires":[["f90ccbc3.25a8b","8601b654.799c6"],[],[]]},{"id":"f90ccbc3.25a8b","type":"string","z":"e2bd5a4e.5597e8","g":"9e69bb336a453bf0","name":"","methods":[{"name":"replaceAll","params":[{"type":"str","value":"-"},{"type":"str","value":"/"}]},{"name":"left","params":[{"type":"num","value":"19"}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":800,"y":2300,"wires":[["478e7ad6.3b69fc"]]},{"id":"29b57fb9.8ba4f","type":"subflow:8d34d18c.a5c1d8","z":"e2bd5a4e.5597e8","g":"9e69bb336a453bf0","name":"","x":630,"y":2190,"wires":[["e53ec78c.5d5ce8","8532dba.67d7e28"],[],[]]},{"id":"8532dba.67d7e28","type":"string","z":"e2bd5a4e.5597e8","g":"9e69bb336a453bf0","name":"","methods":[{"name":"left","params":[{"type":"num","value":"19"}]},{"name":"replaceAll","params":[{"type":"str","value":"-"},{"type":"str","value":"/"}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":800,"y":2220,"wires":[["539fda71.578aa4"]]},{"id":"539fda71.578aa4","type":"gate","z":"e2bd5a4e.5597e8","g":"9e69bb336a453bf0","name":"","controlTopic":"control","defaultState":"open","openCmd":"go","closeCmd":"stop","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":930,"y":2220,"wires":[["c10d8191.fe707","e582752f.3763f","edb7d713.13151","f205ad3c.2c3aa8"]]},{"id":"478e7ad6.3b69fc","type":"gate","z":"e2bd5a4e.5597e8","g":"9e69bb336a453bf0","name":"","controlTopic":"control","defaultState":"open","openCmd":"go","closeCmd":"stop","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":930,"y":2300,"wires":[["fb254740.543b38","789410be.8b6d78","ffff48cd.81dd","6fc84240.f1f1dc"]]},{"id":"e582752f.3763f","type":"debug","z":"e2bd5a4e.5597e8","g":"9e69bb336a453bf0","name":"Real Time (Now) with /","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1160,"y":2200,"wires":[]},{"id":"789410be.8b6d78","type":"debug","z":"e2bd5a4e.5597e8","g":"9e69bb336a453bf0","name":"HWC Time (Now) with /","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1170,"y":2280,"wires":[]}]