TheCellule / python-bleson

Python Bluetooth LE Module
https://groups.google.com/group/python-bleson
MIT License
118 stars 24 forks source link

Peripheral role #39

Closed Buzda closed 4 years ago

Buzda commented 6 years ago

Hi there, I really like library that has a feature the other libraries don't have. I faced a problem when trying to use the peripheral example. The import doesn't get anywhere as the compiler does not recognise get_provider, Peripheral...

The observer example works fine, but the peripheral does not: from time import sleep from bleson import get_default_adapter, Peripheral, Service, Characteristic, CHAR_WRITE

adapter = get_default_adapter()

peripheral = Peripheral(adapter)

MICROBIT_LED_SERVICE = 'E95DD91D-251D-470A-A062-FA1922DFA9A8' MICROBIT_LED_CHAR = 'E95D7B77-251D-470A-A062-FA1922DFA9A8'

def on_data_received(bytes): print(bytes)

led_service = Service(MICROBIT_LED_SERVICE) led_write_char = Characteristic(MICROBIT_LED_CHAR, CHAR_WRITE) led_write_char.on_data_received = on_data_received

led_service.add_characteristic(led_write_char)

peripheral.add_service(led_service)

peripheral.start() sleep(2) peripheral.stop()

WayneKeenan commented 6 years ago

Hi,

What platform are you trying it on?

The Peripheral role isn't implemented yet on Win, macOS or Linux yet.
The micro:bit port of Bleson implements an older, different and very alpha peripheral role API that hasn't yet been fully updated to the Bleson API, it's kinda halfway between the old and the new and isn't really supported, too messy.

Sorry, I don't have a timeframe on when this will change.

Regards Wayne

Buzda commented 6 years ago

Thanks Wayne for you prompt response. I'm using linux(pi zero w). Could you direct me to the old one please, I'm trying to generate multiple services with their characteristics on my project.

WayneKeenan commented 6 years ago

My I recommend you use https://github.com/ukBaz/python-bluezero

The old API looked and feels like BlueZero, https://thebubbleworks.com/bubblepy, however it wasn't made public and was based on a very old version of BlueZero.

ChillarAnand commented 4 years ago

Hi @WayneKeenan

I was trying out https://bleson.readthedocs.io/en/latest/examples.html#peripheral-example on Mac and it doesn't work. Any way to make it work on Mac or Linux?