Skip to content

Commit

Permalink
make set-time interval configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
isaric committed Jul 9, 2022
1 parent 143caea commit 9fdd8d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,19 @@ it will post to the slack url specified and identify the camera as "garden".
The second script deals with another problem when opting to use these cameras without a cloud provider - time synchronization.
If cut off from access to the cloud, the cameras' system clock quickly falls out of sync with the world clock and is unable to
contact an NTP server in order to correct itself. This script will continue updating the system clock with the local time of
the server in which the script is running every 30 minutes. Even with the low-cost nature of the clocks in these cameras, it is
the server in which the script is running in regular intervals. Even with the low-cost nature of the clocks in these cameras, it is
enough to maintain a sufficiently low drift for most surveillance purposes.

It requires only three arguments for usage - the url and port (seperated by semicolon), the username and the password.
It requires four arguments for usage - the url and port (one string, seperated by semicolon), the username, the password and the
interval time expressed in minutes as an integer. After interval expires, the time is set again.
It must also be compiled beforehand.

go build set-time.go


Example:

./set-time my-camera-url:1234 admin nimda
./set-time my-camera-url:1234 admin nimda 1

As with the previous script, this one keeps running and will post the current local time of the server to the camera, thereby synchronizing
its system clock with the servers.
11 changes: 10 additions & 1 deletion set-time.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/use-go/onvif/xsd"
onvif2 "github.com/use-go/onvif/xsd/onvif"
"os"
"strconv"
"time"
)

Expand All @@ -29,6 +30,14 @@ func main() {
cam, _ := onvif.NewDevice(args[0])
cam.Authenticate(args[1], args[2])

var interval = 30
if len(args) > 4 {
convInt, err := strconv.Atoi(args[4])
if err == nil {
interval = convInt
}
}

// set time again every 30 minutes
for true {
ct := time.Now()
Expand All @@ -37,7 +46,7 @@ func main() {
fmt.Printf("Could not set time. %s Exiting!\n", err)
return
}
time.Sleep(30 * time.Minute)
time.Sleep(time.Duration(interval) * time.Minute)
}

}
Expand Down

0 comments on commit 9fdd8d6

Please sign in to comment.