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/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..e83d1f31820 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,17 @@ 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) + 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.RunWebWithConfig(ctx, myRobot, cfg, logger) + // runs the web server on the robot and blocks until the program is stopped. + return web.RunWeb(ctx, myRobot, o, logger) }