I'm trying to setup a small application that connects to a BLE device, enables notifications on a characteristic and periodically receives data updates. I already have an application up and running on macOS using tinygo-org/bluetooth. But when I tried it on my Raspberry Pi I could not make it work.
So, instead of relying on tinygo-org/bluetooth I tried using this library, but I've had no luck.
I've tried using AcquireNotify and reading from the file descriptor:
fd, mtu, err := characteristic.AcquireNotify(map[string]interface{}{})
if err != nil {
return err
}
go func(f dbus.UnixFD, mtu uint16) {
fileR := os.NewFile(uintptr(f), "notifyfd")
defer fileR.Close()
reader := bufio.NewReader(fileR)
p := make([]byte, mtu)
for {
n, err := reader.Read(p)
if err != nil {
if err == io.EOF {
// channel closed on disconnection
println("Stopping notifications reader")
return
}
println("Err: ", err.Error())
}
println("Received message with size: ", n)
}
}(fd, mtu)
And also WatchProperties and StartNotify:
ch, err := characteristic.WatchProperties()
if err != nil {
return err
}
go func() {
for update := range ch {
if update.Interface == "org.bluez.GattCharacteristic1" && update.Name == "Value" {
println("Message received")
}
}
}()
c.characteristic.StartNotify()
But none of them work. I'm not sure if this is a problem related to the raspberry pi itself, my bluez version, or if it is a bug somewhere in this library.
I've checked the examples and I would say that there's nothing with my code. Has anyone successfully received notifications using this library? Is there something I'm missing here?
Thanks in advance!
Environment
Bluez 5.50
Raspberry Pi 3B (OS: Raspbian GNU/Linux 10 (buster)
Hi!
I'm trying to setup a small application that connects to a BLE device, enables notifications on a characteristic and periodically receives data updates. I already have an application up and running on macOS using tinygo-org/bluetooth. But when I tried it on my Raspberry Pi I could not make it work.
So, instead of relying on tinygo-org/bluetooth I tried using this library, but I've had no luck.
I've tried using
AcquireNotify
and reading from the file descriptor:And also
WatchProperties
andStartNotify
:But none of them work. I'm not sure if this is a problem related to the raspberry pi itself, my bluez version, or if it is a bug somewhere in this library.
I've checked the examples and I would say that there's nothing with my code. Has anyone successfully received notifications using this library? Is there something I'm missing here?
Thanks in advance!
Environment
Raspbian GNU/Linux 10 (buster)