简体   繁体   English

我们如何通过低功耗蓝牙 (BLE) 使用 HTTP?

[英]How can we use HTTP over Bluetooth Low Energy (BLE)?

Is there a way to send HTTP messages (GET, POST, etc) from BLE central(client) to BLE Peripheral(Server)?有没有办法将 HTTP 消息(GET、POST 等)从 BLE 中央(客户端)发送到 BLE 外设(服务器)? Currently, I am sending plain text using GATT protocol.目前,我使用 GATT 协议发送纯文本。 Since an HTTP server already running inside my Peripheral, I would rather utilize HTTP protocol.由于一个 HTTP 服务器已经在我的外设中运行,我宁愿使用 HTTP 协议。 Somebody suggested me to use HPS(HTTP Proxy Service) over BLE to do this job.有人建议我在 BLE 上使用 HPS(HTTP 代理服务)来完成这项工作。 But I really don't have any idea about HPS.但我真的对 HPS 一无所知。

Is there any other way to send HTTP messages from Client to Server over BLE?有没有其他方法可以通过 BLE 从客户端向服务器发送 HTTP 消息? Can anybody tell me how this can be done?谁能告诉我如何做到这一点? or Is there any other way to send HTTP over BLE.或者有没有其他方法可以通过 BLE 发送 HTTP。

Any help would be appreciated任何帮助,将不胜感激

I disagree with Emil's statement that IPv6 over Bluetooth is the only standardised option.我不同意 Emil 的说法,即基于蓝牙的 IPv6 是唯一的标准化选项。 I work for the Bluetooth SIG btw.顺便说一句,我为蓝牙 SIG 工作。 The HTTP Proxy Service is a standard GATT service. HTTP 代理服务是标准的 GATT 服务。 You can download the specification here: https://www.bluetooth.com/specifications/gatt/您可以在此处下载规范: https : //www.bluetooth.com/specifications/gatt/

There are comments here to the effect that "HTTP over Bluetooth" is a bad idea but no elaboration as to what it is that is "bad".这里有评论说“蓝牙上的 HTTP”是一个坏主意,但没有详细说明什么是“坏”。 I think there may be some confusion about what's involved though and what the intended use of the HTTP Proxy Service is.我认为可能对所涉及的内容以及 HTTP 代理服务的预期用途存在一些混淆。

This GATT HTTP Proxy service must run on a device that has both a Bluetooth Low Energy (LE) stack and a TCP/IP stack.此 GATT HTTP 代理服务必须在同时具有低功耗蓝牙 (LE) 堆栈和 TCP/IP 堆栈的设备上运行。 It has GATT characteristics that allow HTTP requests to be configured, by writing values to those characteristics.它具有 GATT 特性,允许通过向这些特性写入值来配置 HTTP 请求。 This includes HTTP header values.这包括 HTTP 标头值。 The expectation is that most such parameters will not change or at least not change frequently after they have initially been set.预期大多数此类参数在初始设置后不会更改或至少不会频繁更改。 Devices acting as a client to the GATT HTTP Proxy Service then send data over HTTP and TCP/IP indirectly , via the GATT server.充当 GATT HTTP 代理服务客户端的设备然后通过 GATT 服务器间接通过 HTTP 和 TCP/IP 发送数据。 They do this by writing to the HTTP Entity Body characteristic.... typically a small value such as a sensor reading.他们通过写入 HTTP Entity Body 特征来实现这一点……通常是一个很小的值,例如传感器读数。 An HTTP operation is then triggered by the GATT client device by writing a single byte to the HTTP control point characteristic (eg 1 to trigger an HTTP GET).然后,GATT 客户端设备通过将单个字节写入 HTTP 控制点特征(例如,1 以触发 HTTP GET)来触发 HTTP 操作。

It's perhaps a misnomer to talk about HTTP over Bluetooth.谈论基于蓝牙的 HTTP 可能用词不当。 That's not what's happening here.这不是这里发生的事情。 This is a three tier architecture, with very lightweight Bluetooth LE communication between (1) a Bluetooth device and a (2) dual technology Bluetooth and TCP/IP device, acting as a proxy, which then communicates the Bluetooth encoded request that it has configured within it, to a (3) remote HTTP server over TCP/IP.这是一个三层架构,在 (1) 蓝牙设备和 (2) 双技术蓝牙和 TCP/IP 设备之间具有非常轻量级的蓝牙 LE 通信,充当代理,然后传送它已配置的蓝牙编码请求在其中,通过 TCP/IP 连接到 (3) 远程 HTTP 服务器。

As for the comments about using the serial port profile and the suggestion that this would offer performance advantages, this too is questionable.至于关于使用串行端口配置文件的评论以及这将提供性能优势的建议,这也是值得怀疑的。 There's no detail on what is envisaged here but I assume the idea is that entire HTTP operations be formulated and sent over a Bluetooth BR/EDR connection using the serial port profile.这里没有关于设想的细节,但我认为这个想法是使用串行端口配置文件通过蓝牙 BR/EDR 连接制定和发送整个 HTTP 操作。 Bluetooth BR/EDR runs at 2 mega symbols per second at the physical layer and by default, Bluetooth LE runs at 1 mega symbol per second.蓝牙 BR/EDR 在物理层以每秒 2 兆符号的速度运行,默认情况下,蓝牙 LE 以每秒 1 兆符号的速度运行。 But since Bluetooth 5, released several years ago, Bluetooth LE also supports 2 mega symbols per second.但自从几年前发布的蓝牙 5 以来,蓝牙 LE 也支持每秒 2 个兆符号。 Furthermore, due to the design of the HTTP Proxy Service, with fixed or rarely varying component parts of an HTTP request only needing to be configured once, you will probably find you're transferring less data when using HPS vs SPP.此外,由于 HTTP 代理服务的设计,HTTP 请求的固定或很少变化的组件部分只需要配置一次,您可能会发现在使用 HPS 与 SPP 时传输的数据更少。 It all depends, of course but I think this is likely....当然,这一切都取决于,但我认为这很可能......

Hope this helps.希望这可以帮助。

<edit> You asked if there were any other way than the standardised HPS to send HTTP messages over Bluetooth. <edit>你问过除了标准化的 HPS 之外是否还有其他方式可以通过蓝牙发送 HTTP 消息。 From what I know you have one more standardised option.据我所知,您有一个更标准化的选择。 </edit> The only thing standardised is IPv6 over BLE, but it's far from well-supported. </edit>唯一标准化的是 IPv6 over BLE,但它远没有得到很好的支持。 The problem with http is that it will be pretty inefficient due to long strings that need to be sent as headers. http 的问题在于,由于需要作为标头发送的长字符串,它的效率非常低。

<edit>

You can find the HPS service here: https://www.bluetooth.org/docman/handlers/downloaddoc.ashx?doc_id=308344 .您可以在此处找到 HPS 服务: https : //www.bluetooth.org/docman/handlers/downloaddoc.ashx? doc_id =308344

If you really want to use HTTP over BLE but don't want to use any of the standardised ways, you could for example open up an L2CAP CoC and simply send the HTTP request in one direction and send back the HTTP response in one direction.如果您真的想在 BLE 上使用 HTTP 但不想使用任何标准化方式,您可以例如打开一个 L2CAP CoC 并简单地在一个方向上发送 HTTP 请求并在一个方向上发回 HTTP 响应。 That way you just replace TCP with L2CAP CoC.这样你只需用 L2CAP CoC 替换 TCP。

</edit>

You can use Bluetooth gateway.您可以使用蓝牙网关。 Some Bluetooth gateways support Restful API to operator devices.一些蓝牙网关支持对运营商设备的 Restful API。

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

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