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

    WiPy, send and receive bytes from service characteristic

    Scheduled Pinned Locked Moved WiPy 2&3
    bluetooth
    3 Posts 2 Posters 902 Views 2 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.
    • N Offline
      nick9995
      last edited by

      Hello all,

      I have two WiPy 3.0 units and I have been tasked with sending data between them.

      For starters, I chose one to be the client, the other to be the server, and I wish to read a byte from the server's characteristic and send it to the client. For the server, I am using the example code in the API example.

      For the client:

      if BluetoothConnection.isconnected():   #check if we are already connected (from previous run)
          services = BluetoothConnection.services()
          print("Available services are:")
          for service in services:
              print(service.uuid())
          print("-----------------------------")
      
          if type(service.uuid()) == bytes:
              print('Reading chars from service = {}'.format(service.uuid()))
          else:
              print('Reading chars from service = %x' % service.uuid())
          chars = service.characteristics()
          for char in chars:
              if (char.properties() & Bluetooth.PROP_READ):
                  print('char {} value = {}'.format(char.uuid(), char.read()))
      

      It works, I get 0xF1, 0xF2, 0xF3 ect. for each additional time I run the code on the client. But, if I have several services on the server, how do I specify which service I want to read chars from? I think the answer is in this line:

      chars = service.characteristics()
      

      Is there a way to pass the UUID of the service to the function characteristics()?

      FYI, I know little of Python and nothing of bluetooth BLE except for what I have been reading in the API.

      Thanks,
      Nick

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jmarcelino @nick9995
        last edited by jmarcelino

        @nick9995
        It's not currently possible to request a specific characteristic UUID, you need to iterate through the list of characteristics and look for characteristic.uuid() matches the one you're interested in. (also remember .uuid() returns the bytes representing the UUID, not an UUID string)

        1 Reply Last reply Reply Quote 0
        • N Offline
          nick9995
          last edited by nick9995

          Thanks! That answers my question!

          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