Skip to content

Add descriptors, response callback, notify for esp32 - #2

Closed
icetomcat wants to merge 1 commit into
aykevl:bluetoothfrom
icetomcat:bluetooth
Closed

icetomcat wants to merge 1 commit into
aykevl:bluetoothfrom
icetomcat:bluetooth

Conversation

@icetomcat

Copy link
Copy Markdown

Example:

import utime
import bluetooth

bt = bluetooth.Bluetooth()
bt.active(True)
bt.advertise(1000, 'MicroPython')

# callback
def receive(char, msg):
    # echo
    characteristics[1].notify(msg)
    print(msg)

characteristics = [
    bluetooth.Characteristic(
        0xFF01,
        bluetooth.FLAG_WRITE | bluetooth.FLAG_READ,
        receive = receive
    ),
    bluetooth.Characteristic(
        0xFF02,
        bluetooth.FLAG_NOTIFY,
        descriptors = [
            bluetooth.Characteristic(bluetooth.UUID_CHAR_CLIENT_CONFIG, bluetooth.FLAG_WRITE | bluetooth.FLAG_READ)
        ]
    )
]

bt.add_service(0x00FF, characteristics)
gc.collect()

while True:
    characteristics[0].wait() # waiting new message, async
    utime.sleep_ms(100)

@icetomcat icetomcat closed this Mar 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant