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 + CC2650 - Bluetooth connection fail / return closed GATTCConnection

    Scheduled Pinned Locked Moved WiPy 2&3
    blewipy 2.0gattcconnectionbluetoothclosed
    6 Posts 3 Posters 2.3k 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.
    • A Offline
      Arkaik
      last edited by Arkaik

      Hi,
      I'm trying to connect to a TI CC2650 sensor using bluetooth from Wipy 2.0
      I'm using the release 1.6.12.b1.

      Here is my code

      bt = Bluetooth()
      print("Scanning devices (press ctrl+c to stop scanning)")
      bt.start_scan(-1)
      
      advertisements = []
      
      
      ### Scanning devices ###
      try:
          while True:
              time.sleep(1)
              print(".", end="")
              register_device(advertisements, bt.get_adv())
      except KeyboardInterrupt:
          print("\nScan finished :\n")
          bt.stop_scan()
      
      if len(advertisements) > 0:
          
          ### Print detected devices ###
          print(str(len(advertisements)) + " devices detected :")
          for adv in advertisements:
              print("\tRaw advertisement : " + str(adv))
              print("\t\tMac address : " + str(binascii.hexlify(adv.mac)))
              print("\t\tData : " + str(binascii.hexlify(adv.data)))
              name = bt.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL)
              manufacturer = bt.resolve_adv_data(adv.data, Bluetooth.ADV_MANUFACTURER_DATA)
              print("\t\tName : " + str(name))
              print("\t\tManufacturer : " + str(manufacturer))
              print()
          print()
      
          ### Ask user to select device ###
          print("To which device do you want to connect?")
          i = 0
          for adv in advertisements:
              print(str(i) + " - " + str(bt.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL)) + " : " + str(binascii.hexlify(adv.mac)))
              i+=1
          chosen_device = input()
      
          ### Connecting to the selected device ###
          dev_mac = advertisements[int(chosen_device)].mac
          print("Connecting to " + str(bt.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL)) + " : " + str(binascii.hexlify(adv.mac)))
      
          connection = bt.connect(dev_mac)
          
          if connection.isconnected():
              print("\tConnection succesful")
          else:
              print("\tConnection failed")
          
          print(connection)
          
          services = connection.services()
          print(services)
          
      else:
          print("No device detected")
      

      The problem I'm facing is I can't connect to the sensor. Or I can connect but with a closed connection.

      Here is the execution of the code

      PYB: soft reboot
      Scanning devices (press ctrl+c to stop scanning)
      ....
      Scan finished :
      1 devices detected :
      Raw advertisement : (mac=b'\xb0\xb4H\xc9Q\x86', addr_type=0, adv_type=3, rssi=-39, data=b'\x02\x01\x05\x03\x02\x80\xaa\x06\xff\r\x00\x03\x00\x00\x11\tCC2650 SensorTa')
      Mac address : b'b0b448c95186'
      Data : b'020105030280aa06ff0d0003000011094343323635302053656e736f725461'
      Name : CC2650 SensorTa
      Manufacturer : b'\r\x00\x03\x00\x00'
      To which device do you want to connect?
      0 - CC2650 SensorTa : b'b0b448c95186'
      0
      Connecting to CC2650 SensorTa : b'b0b448c95186'
      Connection failed
      <GATTCConnection>
      Traceback (most recent call last):
      File "main.py", line 86, in <module>
      OSError: connection already closed
      MicroPython v1.8.6-593-g8e4ed0fa on 2017-04-12; WiPy with ESP32
      Type "help()" for more information.

      When it succeeds to connect, it returns me a GATTCConnection but when I try a .isconnected(), the connection is always closed yet.

      If I understood well, if the connection failed I should not have a GATTCConnection object but a NoneType object. So I conclude the connection work but for an unknown reason the connection is closed.

      As you can see I also try to access a service on this connection but as predicted it fails.

      I've read that it could come from the firmware version here : https://forum.pycom.io/topic/791/bluetooth-wipy-client-connecting-to-wipy-peripheral

      Does anyone already had a similar problem or know from where it could come from ?

      A 1 Reply Last reply Reply Quote 0
      • A Offline
        Arkaik @Arkaik
        last edited by

        @Arkaik Finally the firmware version was the problem, after downgrading it to 1.4.0.b1 everything worked fine.

        Does someone know why it doesn't work with new releases? Will this bug be fixed?
        Even if the program works now I woud like to be able to upgrade the firmware later.

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

          Sorry to bring up this older topic but what are you running on your Sensortag? Is it just the TI demo code or something custom?

          A 1 Reply Last reply Reply Quote 0
          • A Offline
            Arkaik @jmarcelino
            last edited by

            @jmarcelino Hi, I was running the TI demo code as I just programmed the Wipy, I didn't modify the sensor or added a DevPack if that's what you're asking for.

            1 Reply Last reply Reply Quote 0
            • B Offline
              berni
              last edited by

              I'm trying to talk to the SensorTag with the LoPy and I have the same issues with the latest firmware. Anyone has made any progress or could create a connection and retrieve data from a SensorTag?

              A 1 Reply Last reply Reply Quote 0
              • A Offline
                Arkaik @berni
                last edited by

                @berni I don't know if the bug was solved in new firmware releases, You should try the same code on the 1.4.0.b1 version, maybe it'll solve your problem.

                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