-
Notifications
You must be signed in to change notification settings - Fork 7
/
client.go
50 lines (45 loc) · 1.17 KB
/
client.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
package main
import (
"context"
"github.com/viam-modules/viamrtsp"
"go.viam.com/rdk/components/camera"
"go.viam.com/rdk/logging"
"go.viam.com/rdk/resource"
"go.viam.com/rdk/robot/client"
"go.viam.com/utils/rpc"
)
func main() {
logger := logging.NewDebugLogger("client")
machine, err := client.New(
context.Background(),
"<machine-address>", // replace with your machine address, api key etc.
logger,
client.WithDialOptions(rpc.WithEntityCredentials(
"<api-key-id>",
rpc.Credentials{
Type: rpc.CredentialsTypeAPIKey,
Payload: "<api-key>",
})),
)
if err != nil {
logger.Fatal(err)
}
defer machine.Close(context.Background())
qs := []resource.DiscoveryQuery{
{
API: camera.API,
Model: viamrtsp.ModelAgnostic,
Extra: map[string]interface{}{
"username": "<onvif-username>", // optional credentials for if your device is ONVIF authenticated
"password": "<onvif-password>",
},
},
}
discoveries, err := machine.DiscoverComponents(context.Background(), qs)
for _, discovery := range discoveries {
logger.Infof("Discovered: %v", discovery.Results)
}
if err != nil {
logger.Fatalf("Failed to discover due to: %v", err)
}
}