help with bluetooth esp32

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
tagilux
Posts: 1
Joined: Sun Sep 06, 2020 3:15 pm

help with bluetooth esp32

Post by tagilux » Sun Sep 06, 2020 3:55 pm

hi ALL,

I have a SENSOR_TAG (http://store.linksprite.com/bluetooth-4 ... -nrf51822/), and wanted to know if anyone knew of some documentation for a beginner (a complete noob). I'd like to use a ESP32 to read the data from this TAG

I've looked into the example uPy bluetooth scripts, but the TAG has different details from a standard bluetooth device, like a temp sensor or a HR monitor, etc. I am not sure how to address this TAG - send a notify - connect to it or read the decode the data...

Here are links to images of LighBlue app details for the TAG -
https://ibb.co/0c3ghWj
https://ibb.co/rsNkYHL

I'd appreciate any help I can get.

Thanks
Tag

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: help with bluetooth esp32

Post by jimmo » Tue Sep 08, 2020 2:31 am

tagilux wrote:
Sun Sep 06, 2020 3:55 pm
I've looked into the example uPy bluetooth scripts, but the TAG has different details from a standard bluetooth device, like a temp sensor or a HR monitor, etc. I am not sure how to address this TAG - send a notify - connect to it or read the decode the data...
One of the best ways to figure this stuff out is to try and connect to it with your phone using the "nRF Connect" app (available for iOS and Android).

Then you should be able to modify the "ble_temperature" example to set the correct UUIDs for the services/characteristics that the tag supports.

xwb
Posts: 14
Joined: Sun Oct 25, 2020 8:33 am

Re: help with bluetooth esp32

Post by xwb » Sat Oct 31, 2020 1:58 am

Agreed. Followed this post and downloaded the NRF Connect app. It is very helpful. However, how can you decode the Raw Data properly? It Is something like 0x1AFF4C0002150000000000.......2000DBF (UUID is 00000000-0000-0000-0000-000000000000 Major is 2, Minor is 13)
Most other libraries return something different like

Code: Select all

04 3E 2B 02 01 02 01 **76 1E 3C BB 18 FE** 1F 03 19 00 00 02 01
  04 02 0A FC 0D FF FF FF A1 A2 A3 A4 A5 A6 A7 A8 A9 B1 06 08
  62 6C 75 65 79 E4
  
Thank you very much for your help in advance.

xwb
Posts: 14
Joined: Sun Oct 25, 2020 8:33 am

Re: help with bluetooth esp32

Post by xwb » Sat Oct 31, 2020 10:42 am

Ok I feel like I should help everyone who may visit this page in the future who are trying to read Ibeacons with their esp32.
If anyone needs help about specific parts of the implementation, feel free to reply to the post
For the raw data:
1: Decode the raw input data with

Code: Select all

ubinascii.hexlify(advertise_data)
For the event handler, create a function like

Code: Select all

def bt_irq(event, data):
	if event == _IRQ_SCAN_RESULT:
		#do something

#declare the event handler like this: 		
bluetooth.BLE().irq(handler=bt_irq)
The binary should now look something like #1aff4c0002150000000000000000000000000000000000020019bf
2: It is in binary string, turn it into string with

Code: Select all

the_hexlified_raw_input.decode("utf-8")
2.5:
check if it is an beacon by the first few digits? (1aff4c)'

3: get the uuid, major and minor out of them - concatenate the string
the uuid is position 13-44 so

Code: Select all

raw_string_input[12:44]  #(python index starts from zero, includes the first digit and does not include the last digit)
For the major and minor, it is in 0-9, a-f so for every 16 values, it will move up 1 unit. (I reverse engineered it)
To decode this, do:

Code: Select all

int(raw_string_input[x:x],16).  
this will turn it into its original value

now you are officially done!

xwb
Posts: 14
Joined: Sun Oct 25, 2020 8:33 am

Re: help with bluetooth esp32

Post by xwb » Sat Oct 31, 2020 2:32 pm

ok no its not that simple different beacons have different characters before the uuid. Will update when I have time. Obviously not the correct way to detect ibeacons as you can simply refer to the hex values but it works for me for now

Post Reply