Skip to content

Commit

Permalink
update RTC if time differs more than 1 minute
Browse files Browse the repository at this point in the history
  • Loading branch information
saoron committed Nov 30, 2017
1 parent 5b807a7 commit d356408
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion daemons/bluetooth/updateDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!')
})
}

});
}

Expand Down

0 comments on commit d356408

Please sign in to comment.