kevincar / bless

Cross-platform Bluetooth Low Energy Server Python Library
MIT License
111 stars 30 forks source link

Allow callbacks for connection/disconnection #114

Open beachcitiessoftware opened 1 year ago

beachcitiessoftware commented 1 year ago

Describe the solution you'd like It would be great if the BlessServer could expose some callbacks, for when a connection / disconnection occurs.

thodpap commented 2 months ago

I found out that there are some functions that you can set for just callbacks. Suppose you have

def handle_start_notifying(data):
 print(data)
def handle_stop_notifying(data):
 print(data)
def message_handler(message):
 print(data) # message format 

server = BlessServer(...)
...
await server.start()

server.app.StartNotify = handle_start_notifying # It seems that the input is None every time
server.app.StopNotify = handle_stop_notifying # It seems that the input is None every time

server.app.bus.add_message_handler(message_handler)

Check this for the message_handler object