Gpy cannot connect to BLE device



  • Hi,
    i have a problem with my Gpy.
    I used the example code From https://docs.pycom.io/tutorials/all/ble/.

    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) == 'Heartrate':
          print('gefunden')
          bt.stop_scan()
          try:
              print(adv.mac)
              conn = bt.connect(adv.mac)
              #bt.connect(b'\xDA\x0F\xA2\x69\x63\xCA')
              print('verbunden')
              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:
              pass
      else:
          time.sleep(0.050)
    
    
    Uploading project (main folder)...
    Not safe booting, disabled in settings
    
    Reading file status
    [1/1] Writing file main.py (1kb)
    Upload done, resetting board...
    OKets Jun  8 2016 00:22:57
    
    rst:0x7 (TG0WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    mode:DIO, clock div:1
    load:0x3fff8020,len:8
    load:0x3fff8028,len:2136
    load:0x4009fa00,len:19880
    entry 0x400a05d0
    Smart Provisioning started in the background
    See https://docs.pycom.io/smart for details
    gefunden
    b'\xcc\x80\x91J\xfb\x8d'
    
    

    after the print of the mac adresse nothing happen...

    The BLE device work, with NRF Connect its possible to connect and look the services.
    Greetings



  • I don´t know what is wrong...
    Now it doesn´t work.

    i is nit possible to connect. every time 'connection refused'

    I have no idea what i am doing wrong.



  • Thank you for your help.

    Now i searched in the forum an finde a post
    ble-connection-issue

    my issue is very embarrassing.... my Phone with the NRF app blocked the connection while scanning...
    Thank you for your help



  • So now this is printed.

    Failed: connection refused
    


  • Hi, you could try to print the exception to get a better understanding of why it's failing.

    except Exception as e:
        print("Failed: " + str(e))
    

Log in to reply
 

Pycom on Twitter