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

    Cannot connect BLE in LoPy

    Scheduled Pinned Locked Moved LoPy
    5 Posts 2 Posters 80 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.
    • F Offline
      Fikret Avci
      last edited by

      Hi all,

      I have a LoPy device and I want to connect a device via Bluetooth. It can read the advertises, but it cannot connect the device. Is there any Bluetooth setting I need to set in LoPy device or the corresponding device, or is there any way to debug it? The adv_type I am receiving is 0. Here is the code I am trying:

      from network import Bluetooth
      import time
      bt = Bluetooth()
      bt.start_scan(-1)
      
      while True:
          adv = bt.get_adv()
      
          if adv and bt.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL) == 'BBC micro:bit [zaput]':
              print(adv.adv_type)
      
              try:
                  conn = bt.connect(adv.mac)
                  print('connected')
                  services = conn.services()
                  for service in services:
                      time.sleep(0.050)
                      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()))
                  conn.disconnect()
                  break
              except:
                  print("Error while connecting or reading from the BLE device")
                  break
          else:
              time.sleep(0.050)
      

      Also, I am getting these lines as the output and firmware version:

      0
      Error while connecting or reading from the BLE device
      Pycom MicroPython 1.20.2.r6 [v1.11-c5a0a97] on 2021-10-28; LoPy with ESP32
      Pybytes Version: 1.7.1
      
      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jcaron @Fikret Avci
        last edited by

        @Fikret-Avci Are you able to connect to the device using a different device, like a smartphone with nRF Connect for instance (or one of the many other BLE scanners)?

        F 1 Reply Last reply Reply Quote 0
        • F Offline
          Fikret Avci
          last edited by

          @jcaron I can connect other device with app on the smart phone. Also, I could connect LoPy when I use it as server.

          1 Reply Last reply Reply Quote 0
          • F Offline
            Fikret Avci @jcaron
            last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • F Offline
              Fikret Avci
              last edited by

              It says OSError: connection refused after trying to connect with connect(adv.mac)

              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