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 scan between pycoms

    Scheduled Pinned Locked Moved WiPy 2&3
    2 Posts 2 Posters 297 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.
    • M Offline
      mdelhorno
      last edited by

      Hi everyone,

      I’m trying to develop an application that continuously scan the BLE network and gets the RSSI level from some devices I selected.

      My testbed is composed by:

      • 5 WiPy3 + pysense board. Firmware: 1.18.2.r7
      • 1 WiPy3 + pysense board: Firmware: 1.17.5.b6
      • 1 WiPy3 + pytrack board. Firmware: 1.18.0

      All of them are running the same code (below) but the only board that gets BLE measurements of the other devices is the pytrack (pysenses don’t “see” each other). This is the first time that I use BLE so I might have a lack of understanding about how BLE works.

      bt = Bluetooth()
      bt.set_advertisement(name=client_id, service_uuid=b'1234567890123456')
      bt.advertise(True)
      
      macs_bt = {‘MAC-1’, ‘MAC-2’, ‘MAC-3’, ‘MAC-4’, ‘MAC-5’, ‘MAC-6’, ‘MAC-7’} 
      rssi_bt = []
      
      def scan_bluetooth(delay):
          bt.start_scan(-1)
      
          while True:
              try:
                  rssi = {}
                  advs = bt.get_advertisements()
      
                  for ad in advs:
                      bssid = change_mac_format(ubinascii.hexlify(ad.mac).decode('utf-8'))
      
                      if bssid in macs_bt:
                          rssi[bssid] = ad.rssi
      
                  if rssi:
                      rssi['timestamp'] = get_date()
                      rssi_bt.append(rssi)
      
                  time.sleep(delay)
              except Exception as ex:
                  sys.print_exception(ex)
      

      Any idea what’s going on?

      Thanks :)

      O 1 Reply Last reply Reply Quote 0
      • O Offline
        oligauc @mdelhorno
        last edited by

        @mdelhorno Please can you send you full code to support@pycom.io . The code below is working for me:

        from network import Bluetooth
        import utime
        
        bluetooth = Bluetooth()
        
        bluetooth.set_advertisement(name='Module_1', service_uuid=b'1234567890123456')
        bluetooth.advertise(True)
        
        bluetooth.start_scan(-1)    # start scanning with no timeout
        
        while True:
            print(bluetooth.get_adv())
            utime.sleep(0.2)
        
        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