-
Notifications
You must be signed in to change notification settings - Fork 207
/
Copy pathDeviceService.go
67 lines (58 loc) · 1.41 KB
/
DeviceService.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"context"
"fmt"
"log"
"net/http"
goonvif "github.com/use-go/onvif"
"github.com/use-go/onvif/device"
sdk "github.com/use-go/onvif/sdk/device"
"github.com/use-go/onvif/xsd/onvif"
)
const (
login = "admin"
password = "Supervisor"
)
func main() {
ctx := context.Background()
//Getting an camera instance
dev, err := goonvif.NewDevice(goonvif.DeviceParams{
Xaddr: "192.168.13.14:80",
Username: login,
Password: password,
HttpClient: new(http.Client),
})
if err != nil {
panic(err)
}
//Preparing commands
systemDateAndTyme := device.GetSystemDateAndTime{}
getCapabilities := device.GetCapabilities{Category: "All"}
createUser := device.CreateUsers{
User: onvif.User{
Username: "TestUser",
Password: "TestPassword",
UserLevel: "User",
},
}
//Commands execution
systemDateAndTymeResponse, err := sdk.Call_GetSystemDateAndTime(ctx, dev, systemDateAndTyme)
if err != nil {
log.Println(err)
} else {
fmt.Println(systemDateAndTymeResponse)
}
getCapabilitiesResponse, err := sdk.Call_GetCapabilities(ctx, dev, getCapabilities)
if err != nil {
log.Println(err)
} else {
fmt.Println(getCapabilitiesResponse)
}
createUserResponse, err := sdk.Call_CreateUsers(ctx, dev, createUser)
if err != nil {
log.Println(err)
} else {
// You could use https://github.com/use-go/onvif/gosoap for pretty printing response
fmt.Println(createUserResponse)
}
}