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

    GATTCCharacteristics.write('value') doesn't work!

    Scheduled Pinned Locked Moved WiPy 2&3
    blewipy2.0
    6 Posts 3 Posters 1.7k Views 3 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.
    • I Offline
      Innocenzo
      last edited by Innocenzo

      Re: BLE connects but connection is lost immediately

      Hi,

      I notice that with firmware 1.7.6.b1 now the BLE connection function works fine. Now it is possible discover all services and characteristics, but the write function on a characteristic does not work. In my code example chars[0] is a PROP_WRITE charateristic, but when I write something on it, anything happen.

      from network import Bluetooth
      import ubinascii
      import machine
      import uos
      import utime
      
      bt = Bluetooth()
      bt.start_scan(-1)
      while True:
          adv = bt.get_adv()
          try:
              if adv and bt.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL) == 'X-DOM-NC':
                  print(adv.mac)
                  conn = bt.connect(adv.mac)
                  while not conn.isconnected():
                      machine.idle()
                  print("connected")
                  print(conn)
                  services = conn.services()
                  print("services")
                  print(services)
                  print(services[0].uuid())
                  print(services[1].uuid())
                  print(services[2].uuid())
                  chars = services[2].characteristics()
                  print(chars)
                  print(chars[0].properties())
                  print(chars[1].properties())
                  print(chars[0].uuid())
                  print(chars[1].uuid())
                  chars[0].write(b'x0f')
                  utime.sleep(2)
                  break
          except:
              print("Error while connecting or reading from the BLE device")
              break
      while True:
          pass
      conn.disconnect()
      
      1 Reply Last reply Reply Quote 0
      • B Offline
        bucknall
        last edited by

        Hi @Innocenzo,

        Thanks for alerting us to this problem. Would you mind creating an issue on our GitHub repo (https://github.com/pycom/pycom-micropython-sigfox/issues) regarding your concerns?

        Thanks! :)

        Alex

        Developer Evangelist - Pycom

        I K 2 Replies Last reply Reply Quote 1
        • I Offline
          Innocenzo @bucknall
          last edited by Innocenzo

          @bucknall I notice that if the characteristic that I want write has a property = PROP_WRITE the write function doesn't work. Instead if the characteristic has a property = PROP_WRITE_NR , the function works fine.

          EDIT: I have opened a issue on GitHub

          B 1 Reply Last reply Reply Quote 0
          • B Offline
            bucknall @Innocenzo
            last edited by

            @Innocenzo Definitely sounds like a bug! I'll check this out later today!

            Developer Evangelist - Pycom

            1 Reply Last reply Reply Quote 0
            • K Offline
              kutysam @bucknall
              last edited by

              @bucknall
              Hi, I have a ble device and i can confirm that Prop_write_nr works!

              And sorry for piggy backing, cause this issue is related to BLE GATTC too.
              https://forum.pycom.io/topic/1486/reading-descriptors-of-ble-client-gattc-device

              Anyway to change the properties of a gattc manually?

              writeChar.properties() --> 22
              00010110

              00010000 Bluetooth.PROP_NOTIFY
              00000100 Bluetooth.PROP_WRITE_NR
              00000010 Bluetooth.PROP_READ

              I need this to be in.
              00100000 Bluetooth.PROP_INDICATE
              00110110 --> 54

              Android, pygatt and mrsurly fork of micropython has a way to change it as such.

              B 1 Reply Last reply Reply Quote 0
              • B Offline
                bucknall @kutysam
                last edited by

                @kutysam Hmm ok! One of our engineers is having a look at it today so I'll keep you posted!

                Developer Evangelist - Pycom

                1 Reply Last reply Reply Quote 0

                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