Lopy - picking up MAC address from Ibeacon



  • hello,

    After an extensive search on the forum (I might be a horrible searcher, or the forum search mechanisms might be sloppy - I don't know), I didn't find anything that enlightened me on my issue:

    I have 4 Ibeacon BLE devices that I want to detect with a single lopy unit using bluetooth.
    All I need is their RSSI, and since printing out the bluetooth.get_adv shows me something that looks like a MAC address as the first thing, I thought that reckognizing the beacons on that would be the most straightforward approach. I might be wrong..

    The printed MAC address looks something like this: b'FS\xbd\x8c\xd2\x11' (this is just one of many), but the MAC address on my beacons look like this: ED:BE:D4:8D:0B:87

    What are these different formats ? Especially the first one I find hard to identify. And how would one go about converting it into something like the second one?

    Thanks a bunch <3



  • The MAC address printed on your beacons is just a nicely formatted version in hexadecimal of the 6 byte address. What you get from Python are the actual 6 bytes themselves (hence the b' at the start) and when you print them they get turned into the correspond ASCII characters for that value (or \xYY if it's not a printable character)

    You can use the binascii.hexlify function to turn each of those bytes into hexadecimal and make a string which is closer to what you have. For example your b'FS\xbd\x8c\xd2\x11'

    >>> import binascii
    >>> binascii.hexlify(b'FS\xbd\x8c\xd2\x11')
    
    b'4653bd8cd211'
    

    So this address is 46:53:bd:8c:d2:11

    Of course you can split into pairs, add the colons and make all letters uppercase too using standard string manipulation.



Pycom on Twitter

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.