Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to send data with BLE broadcast mode?

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.

like image 253
Henry Avatar asked Nov 16 '18 16:11

Henry


People also ask

Can BLE send data?

The BLE Send block transmits data or instructions from your Android™ mobile device to a nearby device or sensor using the Bluetooth® Low Energy (BLE) protocol.

Can BLE broadcast?

BLE beacons work as broadcasting devices that send information one way to receiving devices, and successful transmission often requires specific software installed on devices to interact with BLE beacons.

How does BLE communication work?

BLE Beacons They broadcast to nearby Bluetooth Low Energy devices, but they do not receive data. BLE beacons do not require an internet connection to do this broadcasting. Typically this would look like a single beacon broadcasting data to smart devices (cell phones, smart watches, etc.) nearby.


1 Answers

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.

like image 58
Youssif Saeed Avatar answered Oct 23 '22 05:10

Youssif Saeed