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

    Reading beacons TxPower by WiPy V3.1

    Scheduled Pinned Locked Moved WiPy 2&3
    1 Posts 1 Posters 149 Views 1 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
      momentaj
      last edited by

      Hi,

      I am playing with WiPy V3.1 to read advertising data sent. I have some BLE beacons (Ruuvi, Kontakt, Estimote, ...) in my lab and I am getting the MAC, RSSI, AdvData, ... for them.

      Everything seems OK except TxPower: I can see the TxPower for all the beacons in my cellphone. But, the code below always prints 'None'.

      from network import Bluetooth
      from ucollections import namedtuple
      import ubinascii
      
      TagData = namedtuple('TagData', (
          'mac',
          'addr_type',
          'adv_type',
          'rssi',
          'tx_power',
          'data',
          'name',
          'data_array'
      ))
      
      encoding = "ascii"
      bluetooth = Bluetooth()
      bluetooth.deinit()
      bluetooth.init()
      bluetooth.start_scan(2)
      
      tags = []
      
      while bluetooth.isscanning():
      
          adv = bluetooth.get_adv()
          if not adv:
              continue
      
          mac = ubinascii.hexlify(adv.mac, ':').decode(encoding)
      
          name_b = bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL)
          if name_b:
              name = str(name_b, encoding)
          else:
              name = ''
      
          data_array = []
          data_array.append(bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_TX_PWR))
          data_array.append(bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_FLAG))
          data_array.append(bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_16SRV_PART))
          data_array.append(bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_T16SRV_CMPL))
          data_array.append(bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_32SRV_PART))
          data_array.append(bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_32SRV_CMPL))
          data_array.append(bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_128SRV_PART))
          data_array.append(bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_128SRV_CMPL))
          data_array.append(bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_SHORT))
          data_array.append(bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL))
          data_array.append(bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_DEV_CLASS))
          data_array.append(bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_SERVICE_DATA))
          data_array.append(bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_APPEARANCE))
          data_array.append(bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_ADV_INT))
          data_array.append(bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_32SERVICE_DATA))
          data_array.append(bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_128SERVICE_DATA))
          data_array.append(bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_MANUFACTURER_DATA))
      
      
          tag = TagData(mac, adv.addr_type, adv.adv_type, adv.rssi, bluetooth.resolve_adv_data(adv.data, Bluetooth.ADV_TX_PWR), adv.data, name, data_array)
          tags.append(tag)
      
      for tag in tags:
          print(tag.data_array[0])
      

      I want to read Bluetooth.ADV_TX_PWR value for each advertising data.

      Am I missing something?

      Thanks

      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