Reading beacons TxPower by WiPy V3.1



  • 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


Log in to reply
 

Pycom on Twitter