Skip to content

Problem with SetConnectedHandler() on Linux (Raspbian) Peripheral Device #145

@SVdvr

Description

@SVdvr

Hello,

I am using your lib to create/manage a peripheral BLE device on an RPI 4.

It already works quite well, I can advertise and read/write with services and characteristics I defined. However, I would need to run a function each time a a Central device connects/disconnects to my RPI.
As I understood, the 'adapter.SetConnectHandler()' can be used for that, but it doesn't work for me.
Did I miss something ? My code is very similar to this example : https://github.com/tinygo-org/bluetooth/blob/v0.6.0/examples/circuitplay/main.go

adapter.SetConnectHandler(func(d` bluetooth.Addresser, c bool) {
		connected = c

		if !connected && !disconnected {
			clearLEDS()
			disconnected = true
		}

		if connected {
			disconnected = false
		}
	})

	must("enable BLE stack", adapter.Enable())
	adv := adapter.DefaultAdvertisement()
	must("config adv", adv.Configure(bluetooth.AdvertisementOptions{
		LocalName: "TinyGo colors",
	}))
	must("start adv", adv.Start())

How do I (is it possible to ?) configure a handler that will be called each time a central device connects to my Linux (Raspbian) peripheral ?

Thank you !

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions