简体   繁体   English

iOS BLE蓝牙 - 发送/接收HEX数据

[英]iOS BLE Bluetooth - send/receive HEX data

I am creating an iOS application that should connect to a custom BLE device. 我正在创建一个应该连接到自定义BLE设备的iOS应用程序。 I need to iOS app to send 2 HEX commands, one to enable a part of the device and another to request for Data. 我需要iOS应用程序发送2个HEX命令,一个用于启用设备的一部分,另一个用于请求数据。

Is there any way in iOS to send/receive custom HEX data, other than working with services & characteristics? 除了使用服务和特性之外,iOS中有没有办法发送/接收自定义HEX数据?

No that is not possible, but the reason for this is not iOS but that the 'services' and 'characteristics' are just part of how the BLE protocol is defined. 不,这是不可能的,但其原因不是iOS,而是'服务'和'特征'只是BLE协议定义的一部分。

Official spec: https://developer.bluetooth.org/TechnologyOverview/Pages/BLE.aspx 官方规范: https//developer.bluetooth.org/TechnologyOverview/Pages/BLE.aspx

Generic Attribute Profile 通用属性配置文件

The latest Bluetooth specification uses a service-based architecture based on the attribute protocol (ATT). 最新的蓝牙规范使用基于属性协议(ATT)的基于服务的架构。 All communication in low energy takes place over the Generic Attribute Profile (GATT). 低能量的所有通信都通过通用属性配置文件(GATT)进行。 An application or another profile uses the GATT profile so a client and server can interact in a structured way. 应用程序或其他配置文件使用GATT配置文件,以便客户端和服务器可以以结构化方式进行交互。

The server contains a number of attributes, and the GATT Profile defines how to use the Attribute Protocol to discover, read, write and obtain indications. 服务器包含许多属性,GATT配置文件定义了如何使用属性协议来发现,读取,写入和获取指示。 These features support a service-based architecture. 这些功能支持基于服务的体系结构。 The services are used as defined in the profile specifications. 服务按配置文件规范中的定义使用。 GATT enables you to expose service and characteristics defined in the profile specification. GATT使您可以公开概要文件规范中定义的服务和特征。

The other answer is accidentally right, but for the wrong reasons. 另一个答案是意外的,但出于错误的原因。

Of course it is possible in BLE to send any kind of data, not just GATT. 当然,在BLE中可以发送任何类型的数据,而不仅仅是GATT。 It's just that iOS forces you to work with GATT . 这只是iOS强迫你使用GATT There are no iOS APIs for anything else. 其他任何东西都没有iOS API。 So, yes, it is iOS that prevents you from doing it. 所以,是的, iOS是阻止你这样做的。

If you wouldn't be forced to work with GATT, there would be some other options: 如果您不被迫与GATT合作,还会有其他选择:

  • L2CAP Credit-Based Channels - you create a channel that allows you to send full 23 octets of data per packet (that's in BLE 4.0 and 4.1; 4.2 allows more than that), in whatever format you choose to. L2CAP基于信用的频道 - 您创建一个频道,允许您以每个数据包发送完整的23个八位字节数据(在BLE 4.0和4.1中; 4.2允许更多数据),无论您选择何种格式。
  • With access to the HCI, you can send a custom ACL Data Packet to avoid the L2CAP header. 通过访问HCI,您可以发送自定义ACL数据包以避免L2CAP标头。 But you need to also modify the other side to make sure it parses it correctly. 但是你还需要修改另一面以确保它正确解析它。

Yes you can send data over ble device. 是的,您可以通过ble设备发送数据。 I've implemented already. 我已经实施了。 By implementing peripheral object's writevalue method to send data on given characteristics of your ble devices. 通过实现外围对象的writevalue方法来发送有关ble设备的给定特征的数据。 And also for getting data back from the BLE devices you could use peripheral object's readValue method. 而且,为了从BLE设备获取数据,您可以使用外围对象的readValue方法。 Data will be started in update delegate method of bluetooth framework 数据将在蓝牙框架的更新委托方法中启动

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

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