From cd2c3c251994172f45d8ebb369876bc06dfa86d4 Mon Sep 17 00:00:00 2001 From: Cheuk Tse Date: Wed, 5 Oct 2022 16:31:18 -0400 Subject: [PATCH 1/3] update --- examples/mysensor/server/config.json | 12 ------------ examples/mysensor/server/server.go | 15 ++++++--------- 2 files changed, 6 insertions(+), 21 deletions(-) delete mode 100644 examples/mysensor/server/config.json diff --git a/examples/mysensor/server/config.json b/examples/mysensor/server/config.json deleted file mode 100644 index 2f44c676e3d..00000000000 --- a/examples/mysensor/server/config.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "network": { - "bind_address": "localhost:8081" - }, - "components": [ - { - "name": "sensor1", - "type": "sensor", - "model": "mySensor" - } - ] -} diff --git a/examples/mysensor/server/server.go b/examples/mysensor/server/server.go index 7b91a279e35..c9dd3b9ef2d 100644 --- a/examples/mysensor/server/server.go +++ b/examples/mysensor/server/server.go @@ -11,10 +11,11 @@ import ( "go.viam.com/rdk/components/sensor" "go.viam.com/rdk/config" "go.viam.com/rdk/registry" + "go.viam.com/rdk/resource" robotimpl "go.viam.com/rdk/robot/impl" "go.viam.com/rdk/robot/web" - "go.viam.com/rdk/utils" + weboptions "go.viam.com/rdk/robot/web/options" ) var logger = golog.NewDebugLogger("mysensor") @@ -59,16 +60,12 @@ func main() { } func mainWithArgs(ctx context.Context, args []string, logger golog.Logger) (err error) { - // we set the config here, but it can also be a commandline argument if so desired. - cfg, err := config.Read(ctx, utils.ResolveFile("./examples/mysensor/server/config.json"), logger) - if err != nil { - return err - } - myRobot, err := robotimpl.RobotFromConfig(ctx, cfg, logger) + s := &mySensor{Name: "sensor1"} + + myRobot, err := robotimpl.RobotFromResources(ctx, map[resource.Name]interface{}{sensor.Named("sensor1"): s}, logger) if err != nil { return err } defer myRobot.Close(ctx) - - return web.RunWebWithConfig(ctx, myRobot, cfg, logger) + return web.RunWeb(ctx, myRobot, weboptions.New(), logger) } From 2d53a2201779ba41ed7a830523794cb6e7bef7f4 Mon Sep 17 00:00:00 2001 From: Cheuk Tse Date: Thu, 6 Oct 2022 14:53:04 -0400 Subject: [PATCH 2/3] add --- examples/mysensor/README.md | 2 +- examples/mysensor/client/client.go | 2 +- examples/mysensor/server/server.go | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/mysensor/README.md b/examples/mysensor/README.md index 9ec8601cb35..fb0cf64d52a 100644 --- a/examples/mysensor/README.md +++ b/examples/mysensor/README.md @@ -72,7 +72,7 @@ To use this custom server as part of a larger robot, you’ll want to add it as ] ``` -And to ensure that the custom server starts up with the rest of the robot, you can run the custom server binary as a process. +And to ensure that the custom server starts up with the rest of the robot, you can run the custom server binary as a process as part of the robot config. ``` "processes": [ diff --git a/examples/mysensor/client/client.go b/examples/mysensor/client/client.go index 8ce408c9815..80731abd15d 100644 --- a/examples/mysensor/client/client.go +++ b/examples/mysensor/client/client.go @@ -14,7 +14,7 @@ func main() { logger := golog.NewDebugLogger("client") robot, err := client.New( context.Background(), - "localhost:8080", + "localhost:8081", logger, ) if err != nil { diff --git a/examples/mysensor/server/server.go b/examples/mysensor/server/server.go index c9dd3b9ef2d..aaffa891685 100644 --- a/examples/mysensor/server/server.go +++ b/examples/mysensor/server/server.go @@ -67,5 +67,8 @@ func mainWithArgs(ctx context.Context, args []string, logger golog.Logger) (err return err } defer myRobot.Close(ctx) - return web.RunWeb(ctx, myRobot, weboptions.New(), logger) + o := weboptions.New() + // the default bind address is localhost:8080, specifying a different bind address to avoid collisions. + o.Network.BindAddress = "localhost:8081" + return web.RunWeb(ctx, myRobot, o, logger) } From 3bb88f7ea2ec23b87e16f01396d8ae21d82b39fb Mon Sep 17 00:00:00 2001 From: Cheuk Tse Date: Thu, 6 Oct 2022 14:55:28 -0400 Subject: [PATCH 3/3] add log --- examples/mysensor/server/server.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/mysensor/server/server.go b/examples/mysensor/server/server.go index aaffa891685..e83d1f31820 100644 --- a/examples/mysensor/server/server.go +++ b/examples/mysensor/server/server.go @@ -70,5 +70,7 @@ func mainWithArgs(ctx context.Context, args []string, logger golog.Logger) (err o := weboptions.New() // the default bind address is localhost:8080, specifying a different bind address to avoid collisions. o.Network.BindAddress = "localhost:8081" + + // runs the web server on the robot and blocks until the program is stopped. return web.RunWeb(ctx, myRobot, o, logger) }