简体   繁体   中英

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.

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 (eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM