0

I am trying to learn Go, and I am reimplementing something I have written in Python as a project. I am trying to send some basic commands to a Bluetooth LE device. Ultimately, I want a Characteristic I can write to, and it seems in order to do that with the BLE library, I first need to get a connection, find the services, filtering to the one of interest, and then once I have the Service, get its characteristics. That's all fine.

I am wondering if this is the best way of creating the filter array for getting the service of interest though:

var service_filter []ble.UUID

//s_uuid := ble.MustParse("00001820-0000-1000-8000-00805f9b34fb")
s_uuid := ble.MustParse("1820")
service_filter = append(service_filter, s_uuid)

services, err := client.DiscoverServices(service_filter)
for _, s := range services {
    fmt.Printf("%s\n", s.UUID)
}

I am specifically asking about "service_filter". In other languages, I might do the following:

services, err := client.DiscoverServices([ ble.MustParse("1820") ])
for _, s := range services {
    fmt.Printf("%s\n", s.UUID)
}
3
  • 3
    []ble.UUID{ble.MustParse("1820")}? Commented Nov 23, 2021 at 16:02
  • Yes, that looks like what I am looking for. Commented Nov 23, 2021 at 16:07
  • 4
    Please take the Tour of Go. It's very good, and covers all the basics of langauge syntax, including slice literals. Commented Nov 23, 2021 at 16:14

1 Answer 1

4

Try this

services, err := client.DiscoverServices([]ble.UUID{ble.MustParse("1820")})
for _, s := range services {
    fmt.Printf("%s\n", s.UUID)
}

Initializing Slice in Go

var a = []int{1,2,3}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.