简体   繁体   English

是否可以使用BLE广播模式发送数据?

[英]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. 我想问你是否有可能以广播模式从BLE设备(如带有蓝牙加密狗的Raspberry Pi,Onion或Arduino)向另一台设备(如电话或其他Raspberry Pi)发送数据(字符串) ,这将在屏幕上显示数据。

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. 说实话,没有必要在屏幕上显示数据,但是其他设备必须能够使用我将创建的C程序详细说明接收到的数据。

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. 我对这个主题进行了大量的研究,但我只能找到有关Beacons的答案,这些对象无法为我的项目(如字符串)发送有用的数据,或者必须相互连接以发送/接收数据的BLE设备。

I would like to create a program in C, in order to achieve this result. 我想在C中创建一个程序,以实现这个结果。 I searched something useful in the BlueZ library but I couldn't find anything because they don't explain the meaning of their functions. 我在BlueZ库中搜索了一些有用的东西,但我找不到任何东西,因为它们没有解释它们的功能的含义。 If it's possible I don't want to creat an android/iOS app. 如果有可能我不想创建一个Android / iOS应用程序。

Yes this is possible. 是的,这是可能的。 As you may already know, there are four roles in Bluetooth Low Energy (BLE):- 您可能已经知道,蓝牙低功耗(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. Observer - 只扫描数据的设备。
  • 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. 当BLE首次推出时,信标/传感器(例如心率,温度计)占据了前两个类别,而电话/计算机占据了另外两个类别。 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. 但是,BLE已经发展,许多设备现在支持所有四种角色,并且设备可以同时在一个或多个角色中运行。

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. 关于你的问题,正如Lee Daniel Crocker所提到的,数据是数据,而你在广告中放入的只是字节,而另一端必须要理解。 You can only put 31 bytes of data in an advert report*, which is why connection-oriented data transfer is more efficient. 您只能在广告报告*中放入31个字节的数据,这就是面向连接的数据传输效率更高的原因。

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. 关于可编程性,我建议在两者上启动BlueZ命令,即将要通告的设备和将读取数据的设备。 You can do this with the Bluetoothctl command as follows:- 您可以使用Bluetoothctl命令执行此操作,如下所示: -

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. 我使用的是BlueZ版本5.50 ,我建议您也这样做。

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. 一旦您可以正确地通告数据并从另一端读取数据,您就可以浏览源代码并查看可以利用的C应用程序。 For bluetoothctl functions you want to start with the following two files:- 对于bluetoothctl函数,您希望从以下两个文件开始: -

  • bluez-5.50/client/main.c 的bluez-5.50 /客户端/ main.c中
  • bluez-5.50/client/advertising.c 的bluez-5.50 /客户端/ 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. (*)从蓝牙5开始,您可以向广告报告添加更多数据,但这是一个非常新的功能,在撰写本文时,很少有堆栈支持它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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