tjko / nxgipd

nxgipd - a monitoring daemon for UTC Interlogix / GE Security / Caddx NetworX series alarm systems
GNU General Public License v2.0
39 stars 19 forks source link

Clock set changes? #6

Closed Dogora closed 8 years ago

Dogora commented 9 years ago

I have a few suggestions about setting the panel clock.

First, would it be good to check if shm->comm_fail==1 before attempting to set the clock? As as aside, is there any other function that maybe should check if communications fails? The flag is set, but it's not used anywhere.

Second, if setting the clock fails, would we want to try again in a hour or so?

Third, I have changed the code I'm running to set the clock at a specified time once a week, such as 9pm on Sunday. The time is set in the .conf file. Right now, the time the clock is set depends on when the daemon was started, so can be somewhat random. I just thought I'd see if there's any interest in adding this option.

tjko commented 9 years ago

_commfail was meant to be flag readable by other programs via shared memory. It's not really updated very often, so delaying some operations because it probably not worth it. nxstat probably should take it into account to show if communications with panel appear to be lost (panel powered off, etc...)

I don't recall seeing setting clock ever failing, so adding some logic might be bit overkill, or have you observed it failing often?

I'm not sure I see point setting (synchronizing) panel clock at specific times of day, as its just there to keep panel (somewhat inaccurate) internal clock sync with real time. But now it would be possible to set it at specific times using cron etc to run nxcmd setclock periodically...

One thing that I just noticed is that the current clock synchronization isn't very accurate, clock gets just synced with about +/- 60 second accuracy. Not really big deal since panel clock is read/set only with one minute resolution, but it probably keeps time within 1 second resolution internally....

I guess could adjust the code sending the set clock command to do it exactly (or few seconds before) new next minute starts...

Dogora commented 9 years ago

Early on, I had problems with a USB-RS232 dongle and USB extenders that would stop working randomly after a week or so. I had to unplug it to make it work again, which would crash the daemon due to the device disappearing (/dev/ttyUSB0). I knew the dongle stopped working when the check every 30 minutes started failing. The panel was never a problem. Once I changed the wiring, stopped using the dongle and started using a real serial port on my computer, I've never had a communication failure.

It makes good sense for nxstat to report if comm_fail is set.

I like the idea of using cron to set the clock when I want with nxcmd, so I'll start doing that.

It is interesting that the panel appears to round to the nearest minute when recording log events. For example, here are a couple of recent nxgipd log entries of mine:

2015-09-09 18:12:24: non-reporting log entry 48/185: 09/09 18:12 Closing, User=01, Partition=1
2015-09-10 08:00:45: non-reporting log entry 50/185: 09/10 08:01 Closing, User=01, Partition=1

Setting the panel clock via *97 on a keypad doesn't set seconds either. The internal clock must count seconds, as various timeouts are in seconds (entry/exit, cross-zone, etc). And, there's a setting in location 40 for chime time in increments of 50ms.

(There is a newer location, 84, you may not know about. Somewhere, I found a 1-page addendum from 2007 that describes V2 panels have adjustable begin and end days for daylight saving time. I've never set mine, and it currently shows all zeros, which is not the published defaults. Setting the clock weekly easily takes care of DST. I bought my panel in 2009.)

My computer time is set via NTP, so I believe it accurate.

Your new code to try and set the clock more accurately looks good to me. It's worth a try. Thanks for the updates!