From d356408827677e70dbddb077a129ed0092a96074 Mon Sep 17 00:00:00 2001 From: Yossi Date: Thu, 30 Nov 2017 12:28:59 +0200 Subject: [PATCH] update RTC if time differs more than 1 minute --- daemons/bluetooth/updateDate.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/daemons/bluetooth/updateDate.js b/daemons/bluetooth/updateDate.js index 4498403..6c562e1 100644 --- a/daemons/bluetooth/updateDate.js +++ b/daemons/bluetooth/updateDate.js @@ -31,10 +31,20 @@ updateDate.prototype.onWriteRequest = function(data, offset, withoutResponse, ca this._value = data; if (this._value.toString().length == 10){ + var cmd = "sudo date -s '@"+this._value.toString()+"'"; exec(cmd, function(error, stdout, stderr) { // command output is in stdout - console.log('time updated!') + console.log('time updated!') + //if date from device differs by a minute from current date > update RTC + + if (Math.abs(data.toString() - (new Date().getTime() / 1000)) > 1000*60){ + var RTCcmd = "sudo hwclock -w"; + exec(RTCcmd, function(error, stdout, stderr) { + console.log('HW clock updated!') + }) + } + }); }