Is it possible to send data with BLE broadcast mode?
Asked Answered
D

1

9

I would like to kindly ask you if it's possible to send data (a string) in broadcast mode from a BLE device (like a Raspberry Pi, Onion or Arduino with a bluetooth dongle) to another device (like a Phone or another Raspberry Pi), which will show the data on screen.

To be honest it's not necessary to show the data on screen, but the other device must be able to elaborate the received data with a C program I will create.

I made a lot of researches on this topic but I could only find answers about Beacons, these objects can't send useful data for my project(like strings), or BLE devices which have to connect each other to send/receive data.

I would like to create a program in C, in order to achieve this result. I searched something useful in the BlueZ library but I couldn't find anything because they don't explain the meaning of their functions. If it's possible I don't want to creat an android/iOS app.

Donatello answered 16/11, 2018 at 16:45 Comment(4)
BLE devices can broadcast data, and any nearby device can receive these, but the amount of data is very limited. It's plenty for, say, a BLE thermometer to broadcast its temperature reading, but for any larger amount of data you'll have to connect one-to-one.Britnibrito
how can I extrapolate the broadcast data? Can I use this data in a C program?Donatello
Bytes are bytes. Data is data. Use them any way you like. I can't write your program for you.Britnibrito
Of course, I didn't mean to ask for a complete program. I just wanted to know if there are some references to any usable function in BlueZ ( I mentioned this one because is the only one I've found). Thank you very much for your answerDonatello
E
12

Yes this is possible. As you may already know, there are four roles in Bluetooth Low Energy (BLE):-

  • Broadcaster - A devices that just advertises data.
  • Peripheral - A device that advertises data but can be connected to by remote devices as well.
  • Observer - A device that just scans for data.
  • Central - A device that can scan for data as well as connect to them.

When BLE was first introduced, beacons/sensors (e.g. Heart Rate, Thermometer) occupied the first two categories and phones/computers occupied the other two. However, BLE has since evolved and a lot of devices now support all four roles and a device can operate in one or more roles at the same time.

Regarding your question, as Lee Daniel Crocker mentioned, data is data and what you put in adverts is just going to be bytes that the other end has to understand. You can only put 31 bytes of data in an advert report*, which is why connection-oriented data transfer is more efficient.

Regarding the programmability, I would recommend starting with BlueZ commands on both, the device that will advertise and the device that will read the data. You can do this with the Bluetoothctl command as follows:-

On the broadcaster/peripheral

#bluetoothctl
[bluetooth]menu advertise
[bluetooth]advertise data 00 00 00 00
[bluetooth]back
[bluetooth]advertise on

On the observer/central

#bluetoothctl
[bluetooth]scan on

I am using BlueZ version 5.50 and I recommend that you do the same.

Once you can advertise the data and read it from the other end correctly, you can go through the source code and see what you can leverage to your C application. For bluetoothctl functions you want to start with the following two files:-

  • bluez-5.50/client/main.c
  • bluez-5.50/client/advertising.c

I hope this helps.

(*) As of Bluetooth 5 you can add a lot more data to advert reports, however this a very recent feature and as of this writing very few stacks support it.

Encaustic answered 17/11, 2018 at 11:26 Comment(2)
Thank you very much! I'll certainly try this functions and I'll write an update if it works. I have another question, I hope this doesn't bother you. Where you can find manuals/links on how to use BlueZ? Because I search on the web but I didn't find anything for the students. Thank you again for your help.Donatello
Unfortunately, I don't think there is one documentation with all the details; instead you have to read through tutorials and questions on the usage. Have a look at this answer as it contains a few links to tutorials and questions:- #35390394Encaustic

© 2022 - 2024 — McMap. All rights reserved.