可以使用BLE广播模式发送数据吗? [英] Is it possible to send data with BLE broadcast mode?

查看:135
本文介绍了可以使用BLE广播模式发送数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问您是否可以通过广播模式将数据(字符串)从BLE设备(例如Raspberry Pi,Onion或带有蓝牙适配器的Arduino)发送到另一设备(例如电话或另一设备)Raspberry Pi),它将在屏幕上显示数据.

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.

说实话,没有必要在屏幕上显示数据,但是另一台设备必须能够使用我将创建的C程序来详细说明接收到的数据.

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.

我对此主题进行了大量研究,但我只能找到有关信标的答案,这些对象无法为我的项目发送有用的数据(例如字符串),或者必须相互连接才能发送/接收的BLE设备数据.

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.

我想用C创建一个程序,以实现此结果.我在BlueZ库中搜索了一些有用的东西,但是找不到任何东西,因为它们没有解释其功能的含义.如果有可能,我不想创建一个android/iOS应用程序.

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.

推荐答案

是可以的.您可能已经知道,蓝牙低功耗(BLE)有四个角色:-

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

  • Broadcaster-一种仅发布数据的设备.
  • 外围设备-一种可以发布数据但也可以通过远程设备连接的设备.
  • 观察者-一种仅扫描数据的设备.
  • 中央-可以扫描数据并连接到它们的设备.

首次引入BLE时,信标/传感器(例如,心率,温度计)占据了前两个类别,而电话/计算机占据了另外两个类别.但是,从那以后BLE不断发展,现在许多设备都支持这四个角色,并且一个设备可以同时在一个或多个角色中运行.

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.

关于您的问题,正如Lee Daniel Crocker提到的那样,数据就是数据,您在广告中放置的内容只会是另一端必须理解的字节.您只能在广告报表中放置31个字节的数据*,这就是为什么面向连接的数据传输效率更高的原因.

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.

关于可编程性,我建议在将要发布的设备和将要读取数据的设备上均以BlueZ命令开头.您可以使用Bluetoothctl命令执行此操作,如下所示:-

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

在观察者/中央

#bluetoothctl
[bluetooth]scan on

我正在使用 BlueZ版本5.50 ,我建议您做同样的事情.

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

一旦您可以公布数据并正确地从另一端读取数据,就可以遍历源代码,并查看可以对C应用程序使用的内容.对于bluetoothctl函数,您要从以下两个文件开始:-

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

我希望这会有所帮助.

(*)从Bluetooth 5开始,您可以添加更多数据来发布报告,但是,这是一项非常新的功能,截至撰写本文时,很少有堆栈支持该功能.

(*) 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.

这篇关于可以使用BLE广播模式发送数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆