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 connects but connection is lost immediately

    Scheduled Pinned Locked Moved WiPy 2&3
    blewipy2.0connectivity
    4 Posts 2 Posters 1.4k 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.
    • salvoaerodevS Offline
      salvoaerodev
      last edited by

      I wrote a simple script to discover a device with a fixed adv complete name, and connect to this device with his MAC address. After found it i need to connect to that device and discover services and characteristics, but after the connection i get a GATT object and connection closes when i try to discover his services.

      I verified the connection on my BLE device. The connection started normally. Anyway when i call the

      bluetooth.isconnected()
      

      it fails and on my console i do not get the error message i wrote for that condition.

      The full code i wrote is here

      import binascii
      from network import Bluetooth
      bluetooth = Bluetooth()
      bluetooth.start_scan(10)    # start scanning with no timeout
      while bluetooth.isscanning():
          adv = bluetooth.get_adv()
          if(adv != None):
              name = bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL)
              print(name)
              if(name == 'xDev-FF:A1:B0-M01'):
                  mac_address = binascii.hexlify(adv.mac)
                  print("MAC: "+ str(mac_address))
                  print("DATA: {}".format(binascii.hexlify(adv.data)))
                  conn = bluetooth.connect(adv.mac)
                  if(conn.isconnected()):
                      print("Connection opened!")
                  print("Connected to device with addr = {}".format(binascii.hexlify(adv.mac)))
                  services = conn.services()
                  print("Service List")
                  for service in services:
                      time.sleep(0.050)
                      print(service)
      

      And here the log

      xDev-FF:A1:B0-M01
      MAC: b'f10403020100'
      DATA: b'020106120978444f4d2d46463a41313a42302d4d3031020afe000000000000'
      Connected to device with addr = b'f10403020100'
      Traceback (most recent call last):
        File "<stdin>", line 18, in <module>
      OSError: connection already closed
      
      1 Reply Last reply Reply Quote 1
      • A Offline
        Arkaik
        last edited by

        Hi, I had the same problem, which firmware version are you using?

        Personnaly I was using 1.6.12.b1.
        Following this topic I found that downgrading to 1.4.0.b1 works.

        Hope it helps.

        1 Reply Last reply Reply Quote 0
        • salvoaerodevS Offline
          salvoaerodev
          last edited by

          It's your same firmware @Arkaik, so probably it's a bug introduced with 1.6.12.b1. I will try to downgrade too. Thanks for your support and let's keep in touch for next updates on BLE.

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

            @salvoaerodev Sure, I hope this bug will be fixed soon as it could be nice to reupgrade firmware for already fixed bugs.

            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