ios 通过蓝牙将 iPhone 连接到 Arduino

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7770973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:52:55  来源:igfitidea点击:

Connect an iPhone to Arduino over Bluetooth

iosiphonebluetootharduino

提问by Georg

I would love to be able to let my iPhone-App communicate to my Arduino over Bluetooth. I found some Bluetooth shields that support the following protocols: BCSP, DUN, LAN, GAP SDP, RFCOMM, and L2CAP. From what i found while googling a bit, is that the iPhone is hiding it's bluetooth stack away?!? Is this correct? Is there really no chance to let my iPhone communicate with an other bluetooth enabled device without jailbreaking (which as far as I know would be required if i'd use btstack: http://code.google.com/p/btstack/)?

我希望能够让我的 iPhone 应用程序通过蓝牙与我的 Arduino 通信。我发现了一些支持以下协议的蓝牙扩展板:BCSP、DUN、LAN、GAP SDP、RFCOMM 和 L2CAP。从我在谷歌搜索时发现的情况来看,iPhone 是否隐藏了它的蓝牙堆栈?!?这样对吗?真的没有机会让我的 iPhone 在没有越狱的情况下与其他支持蓝牙的设备通信(据我所知,如果我使用 btstack:http: //code.google.com/p/btstack/) ?

If bluetooth is really not possible, what other ways (expect WLAN) would you suggest to realize a communication? What I would love to realize is something like here: http://theiopage.blogspot.com/2011/08/yanis-android-wireless-eos-controller.html

如果蓝牙真的不可能,你会建议什么其他方式(期望 WLAN)来实现通信?我想意识到的是这里的东西:http: //theiopage.blogspot.com/2011/08/yanis-android-wireless-eos-controller.html

Thanks for any tips!

感谢您提供任何提示!

采纳答案by Mike

There are several connection technologies available.

有几种可用的连接技术。

As others have mentioned, standard Bluetooth (3.0) is controlled by the MFi program. The only way to connect to a non-jailbroke iPhone is to join the MFi program.

正如其他人所提到的,标准蓝牙 (3.0) 由 MFi 程序控制。连接到非越狱 iPhone 的唯一方法是加入 MFi 计划。

Serial access is interesting. You have to join MFi to distributea serial device, but you can use the Redpark Serial Cableto connect your owniPhone to a serial device.

串行访问很有趣。您必须加入 MFi 才能分发串行设备,但您可以使用Redpark 串行电缆将您自己的iPhone连接到串行设备。

There are several ways to connect Bluetooth LE devices to the Arduino. One I've used is the RedBearLabs BLE Shield. It works pretty darn well.

有几种方法可以将蓝牙 LE 设备连接到 Arduino。我使用过的一个是RedBearLabs BLE Shield。它工作得非常好。

iPhone to RedBearLab BLE Shield to Arduino, powering a hacked truck using techBASIC

iPhone 到 RedBearLab BLE Shield 到 Arduino,使用 techBASIC 为被黑卡车供电

You can also connect to an Arduino using a WiFi-serial bridge. I've had success with the WiFlydevice.

您还可以使用 WiFi 串行桥接器连接到 Arduino。我在WiFly设备上取得了成功。

iPhone to WiFly to Arduino

iPhone 到 WiFly 到 Arduino

One of the neat things about the BLE Shield and WiFly is you don't have to use Objective C or a Macintosh--although that's an option, of course. You can access both through techBASIC, running right on the iPad or iPhone.

BLE Shield 和 WiFly 的一个优点是您不必使用 Objective C 或 Macintosh——当然,这是一个选项。您可以通过techBASIC访问两者,直接在 iPad 或 iPhone 上运行。

You can probably figure these out on your own with some research and effort, but these connection technologies (plus a few more that don't apply directly to Arduino) are also covered in Building iPhone and iPad Electronics Devices, a new book from O'Reilly.

您可能可以通过一些研究和努力自行解决这些问题,但这些连接技术(以及其他一些不能直接应用于 Arduino 的技术)也在O' 的新书《构建 iPhone 和 iPad 电子设备》中有所介绍。赖利。

New Book from O'Reilly

来自 O'Reilly 的新书

回答by hotpaw2

Information about connecting to Bluetooth 3.0 or lower devices from stock OS iOS devices is only available after being accepted into Apple's MFi program.

有关从库存 OS iOS 设备连接到蓝牙 3.0 或更低版本设备的信息只有在被Apple 的 MFi 计划接受后才可用。

Bluetooth 4.0 (BLE) is accessible both in development and commercially to iOS developers (without needing access to the MFi program), using the public Core Bluetooth framework available in iOS 5 or later on iPhone 4S, iPad 3 and later devices carrying BT4.0 on-board.

蓝牙 4.0 (BLE) 可供 iOS 开发人员在开发中和商业上使用(无需访问 MFi 程序),使用在 iPhone 4S、iPad 3 和更高版本的 iPhone 4S、iPad 3 和更高版本设备上提供的公共核心蓝牙框架(无需访问 MFi 程序)在船上。

Added a few years later: There are now several BLE shields and Arduino compatible or Arduino-like products with built-in BLE (LightBlue Bean, RFduino, etc.) available in the market.

几年后添加:现在市场上有几种 BLE 扩展板和 Arduino 兼容或具有内置 BLE(LightBlue Bean、RFduino 等)的类 Arduino 产品。

回答by ygbr

Actually you can make it happen now without Jailbreaking or MFi enrollment.

实际上,您现在无需越狱或 MFi 注册即可实现。

Take a look ate Bluetooth 4.0 in newer iOS devices and Arduino BT 4.0 shield.

看看较新的 iOS 设备和 Arduino BT 4.0 盾中的蓝牙 4.0。

This might help: http://blog.makezine.com/2012/03/19/bluetooth-4-0-from-arduino-to-iphone-no-jailbreaking-no-mfi/

这可能会有所帮助:http: //blog.makezine.com/2012/03/19/bluetooth-4-0-from-arduino-to-iphone-no-jailbreak-no-mfi/

回答by Darko Djuric

Improving this answer and cover all details probably needs some article or similar. I will try to keep things short and make focus on iOS side, since Arduino basically doesn't have limitations on Bluetooth peripherals which are widely available via Arduino BLE shields, such is RedBearLab BLE Shild

改进此答案并涵盖所有细节可能需要一些文章或类似内容。我将尽量保持简短并专注于 iOS 方面,因为 Arduino 基本上对蓝牙外围设备没有限制,这些外围设备可通过 Arduino BLE 扩展广泛使用,例如 RedBearLab BLE Shild

Bluetooth v2.0 + EDR, v2.1 + EDR, v3.0 + HS....

蓝牙 v2.0 + EDR、v2.1 + EDR、v3.0 + HS....

Bluetooth stack specification prior to v4.0 doesn't contain Low Energy part. Although it is easy to use protocol, especially if simplified around SPP (Serial Port Profile) it is not available on Apple iOS devices without MFiprogram. There are few Bluetooth modules on the market such is Pan1321 from Panasonic which includes Apple authentication coprocessor and which could be used with iOS. Sad part of the story is that if you take look on this official page iOS: Supported Bluetooth profilesSPP is not there so you can choose between listed profiles (what you probably will if you are making audio or HID device).

v4.0 之前的蓝牙堆栈规范不包含低功耗部分。虽然它很容易使用协议,特别是如果围绕 SPP(串行端口配置文件)进行简化,它在没有MFi程序的Apple iOS 设备上不可用。市场上很少有蓝牙模块,例如松下的Pan1321,它包含Apple认证协处理器,可以与iOS一起使用。故事的可悲部分是,如果您查看此官方页面iOS:支持的蓝牙配置文件SPP 不存在,因此您可以在列出的配置文件之间进行选择(如果您正在制作音频或 HID 设备,您可能会这样做)。

Bluetooth Low Energy (BLE)

低功耗蓝牙 (BLE)

Migration from Bluetooth v3.0 specification to v4.0 introduced BLE. New part of specification has very little in common with previous. Basically you could look on it as Bluetooth v3.0 + BLE = v4.0 or Bluetooth Smart. BLE part of v4.0 specification is what we are interested for.

从蓝牙 v3.0 规范到 v4.0 的迁移引入了 BLE。规范的新部分与以前的几乎没有共同之处。基本上,您可以将其视为蓝牙 v3.0 + BLE = v4.0 或蓝牙智能。v4.0 规范的 BLE 部分是我们感兴趣的。

CoreBluetooth

核心蓝牙

Beside all the advantages of BLE such are low power consumption, small size, low cost, the most important was adoption by mobile manufacturers, including Apple (no MFi needed). BLE is fully supported by CoreBluetoothand implementation on iOS side is straightforward. One thing that you have to keep in mind is that BLE is low energy but also low speed. Although standard specifies minimal connection interval of 7.5ms Apple documentationsays recommendation is 30ms :-D What I have experienced using bunch of different chips and iOS devices is that you will be capable to transmit 20bytes every 20-30ms. If acknowledgment is needed, than make it double, like 40-60ms.

除了低功耗、小尺寸、低成本等 BLE 的所有优点外,最重要的是被包括 Apple 在内的移动制造商采用(不需要 MFi)。CoreBluetooth完全支持 BLE,并且在 iOS 端的实现很简单。您必须记住的一件事是 BLE 是低能量但也是低速的。尽管标准指定了 7.5毫秒的最小连接间隔,但 Apple 文档说建议是 30 毫秒 :-D 我使用一堆不同的芯片和 iOS 设备的经验是,您将能够每 20-30 毫秒传输 20 字节。如果需要确认,则将其加倍,例如 40-60 毫秒。

Custom Profiles

自定义配置文件

The list of standard BLE profilesis available by Bluetooth Special Interest Group (SIG). Take a look on GATT Based. Unfortunately, if you don't make an heart rate monitor or device from list you will probably use battery service or similar from a profiles list. Fortunately it is not complicated to create custom profile, which will be "placeholder" for application specific data you have to transmit. Understanding of Roles, GATT (Services and Characteristics), UUIDs and other is mandatory, but learning curve or BLE stack is not difficult in my opinion.

蓝牙特别兴趣小组 (SIG) 提供了标准 BLE 配置文件列表。看看基于 GATT 的。不幸的是,如果您不从列表中制作心率监测器或设备,您可能会使用配置文件列表中的电池服务或类似服务。幸运的是,创建自定义配置文件并不复杂,它将成为您必须传输的应用程序特定数据的“占位符”。必须了解角色、GATT(服务和特征)、UUID 等,但我认为学习曲线或 BLE 堆栈并不难。

Once when BLE profile, running on embedded device is known, connection and communication over BLE is very simple using CoreBluetooth library.

一旦知道在嵌入式设备上运行的 BLE 配置文件,使用 CoreBluetooth 库通过 BLE 的连接和通信非常简单。

iBeacon

信标

Apple made little hack using BLE standard as "carrier" for iBeacon. They are using manufacturer specific data in BLE advertising packet to "claim" that some device is iBeacon. Which is perfectly OK, I would say. What you should keep in mind is that BLE is not iBeacon, but all iBeacons are BLE (device with hardcoded manufacturer specific data, exposing RSSI, UUID, major and minor in broadcast BLE mode). Additionally, iBeacon is handled by CoreLocationnot CoreBluetooth. This makes clear what was Apple intension with iBeacon.

Apple 使用 BLE 标准作为 iBeacon 的“载体”进行了一些黑客攻击。他们在 BLE 广告数据包中使用制造商特定数据来“声称”某些设备是 iBeacon。我会说,这完全没问题。您应该记住的是,BLE 不是 iBeacon,但所有 iBeacon 都是 BLE(具有硬编码制造商特定数据的设备,在广播 BLE 模式下公开 RSSI、UUID、主要和次要)。此外, iBeacon 由CoreLocation处理,不是CoreBluetooth。这清楚地表明了 Apple 对 iBeacon 的意图。

Conclusion

结论

If you want to integrate iOS device with Arduino or some other embedded device BLE is definitely something that you want to consider. There are additional reasons why you want to learn more about BLE if you take a look on IoT hype and available RF options. BLE is here to stay with v4.1 and upcoming v4.2 specifications which will improve bandwidth, bring support for IPv6, better security, etc.

如果您想将 iOS 设备与 Arduino 或其他一些嵌入式设备集成,BLE 绝对是您要考虑的事情。如果您查看 IoT 炒作和可用的 RF 选项,您还有其他原因想要了解有关 BLE 的更多信息。BLE 与 v4.1 和即将推出的 v4.2 规范保持一致,这将提高带宽、带来对 IPv6 的支持、更好的安全性等。

At the end, not so short, but I hope it helps.

最后,不是那么短,但我希望它有所帮助。

回答by evotopid

So I don't know how to implement, but I think your Arduino should simulate an Bluetooth Headset and let the App parse the data. Because iPhones only support Bluetooth Headsets this would be one of the only methods. And it would be very hard.

所以我不知道如何实现,但我认为你的Arduino应该模拟一个蓝牙耳机并让App解析数据。因为 iPhone 只支持蓝牙耳机,这将是唯一的方法之一。这将是非常困难的。

I recommend you to do things like this over Wifi with an Wifi-Shield. Than you could use Apples genial bonjoursysteme, to automatically detect your hardware.

我建议您使用 Wifi-Shield 通过 Wifi 执行此类操作。比您可以使用 Apples genial bonjoursysteme 来自动检测您的硬件。

Hope that gives you some idea, how to solve the problem,

希望能给你一些想法,如何解决问题,

Leo

狮子座

回答by Vladimir Tsykunov

Some BLE modules can be used in iBeacon mode and are connectable to IOs. I worked with modules HM10 and HM11, based on CC2540/CC2541. They have several AT commands for iBeacon setup. Changable registers are UUID, Major, Minorand Measured Power. More detailes in this article "Turn your CC2541 based HM-10 Bluetooth Smart Module into an iBeacon"

一些 BLE 模块可以在 iBeacon 模式下使用并且可以连接到 IO。我使用基于 CC2540/CC2541 的模块 HM10 和 HM11。他们有几个用于 iBeacon 设置的 AT 命令。可变寄存器有UUIDMajorMinorMeasured Power。这篇文章中的更多细节“将基于 CC2541 的 HM-10 蓝牙智能模块变成 iBeacon”