converting bluetooth bytes mac address issue !

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
shenouda
Posts: 3
Joined: Thu May 14, 2020 10:11 am

converting bluetooth bytes mac address issue !

Post by shenouda » Thu May 14, 2020 10:24 am

hello,
I am developing something on esp32 with bluetooth
simply I scan and got the result:

Code: Select all

def bt_irq(event, data):
  if event == _IRQ_SCAN_RESULT:
    # A single scan result.
    addr_type, addr, connectable, rssi, adv_data = data
    print('type:{} addr:{} rssi:{} data:{}'.format(addr_type, ubinascii.hexlify(addr), rssi, ubinascii.hexlify(adv_data)))
    print(addr)

  elif event == _IRQ_SCAN_COMPLETE:
    # Scan duration finished or manually stopped.
    print('scan complete')

the result:

Code: Select all

type:1 addr:b'790c96ba0d35' rssi:-38 data:b'1eff060001092002a7ad7a8ddbb036b1379963a399cc0731f7d591c43e87c9'
b'y\x0c\x96\xba\r5'
however when I scan using nRf connect app on android, I get the DC:FB:48:4D:62:A9 and this is the actual mac address

so how to get from b'y\x0c\x96\xba\r5' to DC:FB:48:4D:62:A9 ??
or where is the issue ??

thanks.

sikky
Posts: 1
Joined: Sat May 30, 2020 4:16 pm

Re: converting bluetooth bytes mac address issue !

Post by sikky » Sat May 30, 2020 4:37 pm

Hi shenouda,

I am new to Micropython and this forum. This is my first post. I am trying my hands on it.
The way I see the data, The mac address it is showing in the IRQ result is different from the one that you have looked into nRF connect app.

type:1 addr:b'790c96ba0d35' rssi:-38 data:b'1eff060001092002a7ad7a8ddbb036b1379963a399cc0731f7d591c43e87c9'
b'y\x0c\x96\xba\r5'

here in the above data
addr: 0x79 0x0C 0x96 0xBA 0x0D 0x35 -> this is the mac address (79:0C:96:BA:0D:35)
data: 1eff060001092002a7ad7a8ddbb036b1379963a399cc0731f7d591c43e87c9
1e - Length - (30, there are 30 bytes followed after this byte)
ff - Type - Manufacturer Specific (1 byte)
data - 060001092002a7ad7a8ddbb036b1379963a399cc0731f7d591c43e87c9 (29 bytes)

the address that it is showing b'y\x0c\x96\xba\r5' is same as above. To decode it you can relate it to ASCII encoding as below
the number after "\x" is hex number and if you don't see "\x" then these all are chars.
y - 0x79
\x0c - 0x0C
\x96 - 0x96
\xba - 0xBA
\r - 0x0D
5 - 0x35
overall -> 0x79 0x0C 0x96 0xBA 0x0D 0x35 (79:0C:96:BA:0D:35)
This address is same as the address you got in the variable 'addr'

I suggest that to recheck on nRF connect app and confirm the MAC address. If you are sure of the MAC address on nRF connect then wait for the bluetooth device to scan once again and show you the results that you are expecting.
I guess by this time you would have already resolved this one.

Thanks for giving me an opportunity to contribute here.

shenouda
Posts: 3
Joined: Thu May 14, 2020 10:11 am

Re: converting bluetooth bytes mac address issue !

Post by shenouda » Sat May 30, 2020 5:06 pm

Dear Sikky,

I found the issue, I was checking a windows 10 device Bluetooth (it was the only available device then).
for some reason windows 10 changes the mac ( not sure what's happening :?: , I am not interested ) and I got the results right scanning for all other devices anything else.

Post Reply