Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    BLE Callback handler for READ and WRITE events causes the DISCONNECTION

    Scheduled Pinned Locked Moved Issues & Bugs
    2 Posts 1 Posters 307 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A Offline
      aasodisen
      last edited by

      Hi,
      I am using GPY in Expansion Board 3.1

      Pycom MicroPython 1.20.2.rc7 [v1.11-6d01270] on 2020-05-04; GPy with ESP32
      Pybytes Version: 1.4.0

      Callback handler is working when events are either Bluetooth.CLIENT_CONNECTED and Bluetooth.CLIENT_DISCONNECTED.

      Callback handler is NOT working when events are either Bluetooth.CHAR_READ_EVENT and Bluetooth.CHAR_WRITE_EVENT.

      My objective is simple; to READ & WRITE Service.Characteristics Values.

      from network import Bluetooth
      
      bluetooth = Bluetooth()
      bluetooth.set_advertisement(name='GPy', service_uuid=0x1815)
      
      def conn_cb (bt_o):
          events = bt_o.events()
          if  events & Bluetooth.CLIENT_CONNECTED:
              print("Client connected")
          elif events & Bluetooth.CLIENT_DISCONNECTED:
              print("Client disconnected")
      
      bluetooth.callback(trigger=Bluetooth.CLIENT_CONNECTED | Bluetooth.CLIENT_DISCONNECTED, handler=conn_cb)
      
      bluetooth.advertise(True)
      
      srv1 = bluetooth.service(uuid=0x1815, isprimary=True)
      
      chr1 = srv1.characteristic(uuid=0x2A56, permissions=0x180A, properties=Bluetooth.PROP_READ, value=0b01)
      
      def char1_cb_handler(chr):
          events = chr.events()
          if events & Bluetooth.CHAR_READ_EVENT:
              print('Read request on char 1')
          else:
              print('invalid chr1 event')
      
      char1_cb = chr1.callback(trigger=Bluetooth.CHAR_READ_EVENT, handler=char1_cb_handler)
      A 1 Reply Last reply Reply Quote 0
      • A Offline
        aasodisen @aasodisen
        last edited by

        FIXED:

        from network import Bluetooth
        
        bluetooth = Bluetooth()
        bluetooth.set_advertisement(name='GPy', service_uuid=0x1815)
        
        def conn_cb (bt_o):
            events = bt_o.events()
            if  events & Bluetooth.CLIENT_CONNECTED:
                print("Client connected")
            elif events & Bluetooth.CLIENT_DISCONNECTED:
                print("Client disconnected")
        
        bluetooth.callback(trigger=Bluetooth.CLIENT_CONNECTED | Bluetooth.CLIENT_DISCONNECTED, handler=conn_cb)
        
        bluetooth.advertise(True)
        
        srv1 = bluetooth.service(uuid=0x1815, isprimary=True)
        chr1 = srv1.characteristic(uuid=0x2A56, properties=Bluetooth.PROP_READ, value=0x01)
        
        def char1_cb_handler(chr, *args):
            events = chr.events()
            if events & Bluetooth.CHAR_READ_EVENT:
                print("Read request on char 1")
            else:
                print("invalid chr1 event")
        
        char1_cb = chr1.callback(trigger=Bluetooth.CHAR_READ_EVENT, handler=char1_cb_handler)
        
        1 Reply Last reply Reply Quote 1

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • 1 / 1
        • First post
          Last post

        Pycom on Twitter

        Pycom