func cmdServe(c *cli.Context) error { testSvc := ble.NewService(lib.TestSvcUUID) testSvc.AddCharacteristic(lib.NewCountChar()) testSvc.AddCharacteristic(lib.NewEchoChar()) if err := ble.AddService(testSvc); err != nil { return errors.Wrap(err, "can't add service") } fmt.Printf("Serving GATT Server for %s...\n", c.Duration("tmo")) ctx := ble.WithSigHandler(context.WithTimeout(context.Background(), c.Duration("tmo"))) return chkErr(ble.AdvertiseNameAndServices(ctx, "Gopher", testSvc.UUID)) }
func main() { flag.Parse() d, err := dev.NewDevice(*device) if err != nil { log.Fatalf("can't new device : %s", err) } ble.SetDefaultDevice(d) testSvc := ble.NewService(lib.TestSvcUUID) testSvc.AddCharacteristic(lib.NewCountChar()) testSvc.AddCharacteristic(lib.NewEchoChar()) if err := ble.AddService(testSvc); err != nil { log.Fatalf("can't add service: %s", err) } // Advertise for specified durantion, or until interrupted by user. fmt.Printf("Advertising for %s...\n", *du) ctx := ble.WithSigHandler(context.WithTimeout(context.Background(), *du)) chkErr(ble.AdvertiseNameAndServices(ctx, "Gopher", testSvc.UUID)) }