用于IOS,更多说的是开发有关
蓝牙4.0 For IOS/IOS6的改进 | 蓝牙4.0 For IOS/WWDC 2012 演讲 | 蓝牙4.0 For IOS/工作模式 |
一些文档图片
-(void) readBattery:(CBPeripheral *)p { [self readValue:TI_KEYFOB_BATT_SERVICE_UUID characteristicUUID:TI_KEYFOB_LEVEL_SERVICE_UUID p:p]; } #define TI_KEYFOB_BATT_SERVICE_UUID 0x180F -(void) readValue: (int)serviceUUID characteristicUUID:(int)characteristicUUID p:(CBPeripheral *)p { UInt16 s = [self swap:serviceUUID]; UInt16 c = [self swap:characteristicUUID]; NSData *sd = [[NSData alloc] initWithBytes:(char *)&s length:2]; NSData *cd = [[NSData alloc] initWithBytes:(char *)&c length:2]; CBUUID *su = [CBUUID UUIDWithData:sd]; CBUUID *cu = [CBUUID UUIDWithData:cd]; CBService *service = [self findServiceFromUUID:su p:p]; if (!service) { printf("Could not find service with UUID %s on peripheral with UUID %s\r\n",[self CBUUIDToString:su],[self UUIDToString:p.UUID]); return; } CBCharacteristic *characteristic = [self findCharacteristicFromUUID:cu service:service]; if (!characteristic) { printf("Could not find characteristic with UUID %s on service with UUID %s on peripheral with UUID %s\r\n",[self CBUUIDToString:cu],[self CBUUIDToString:su],[self UUIDToString:p.UUID]); return; } [p readValueForCharacteristic:characteristic]; }
提示被占用
The following is a listing of behavior settings with respect to the OS X built-in Bluetooth driver. Refer to Listing 1 for setting the bluetoothHostControllerSwitchBehavior NVRAM variable.
bluetoothHostControllerSwitchBehavior="never" // when a new HCI is connected, the built-in driver stays attached to the built-in HCI
bluetoothHostControllerSwitchBehavior="always" // when a new HCI is connected, the built-in driver disconnects from the built in HCI and attaches to the external HCI
bluetoothHostControllerSwitchBehavior="default" // when a new HCI is connected, the built-in driver only disconnects from the built in HCI and attaches to the external HCI if the new module is not an Apple module.
1. 买一个CSR蓝牙4.0的usb dongle,这个网上到处都是,大约30多元。下面是图片,这几种都可以。该usb dongle在mac下是免驱动的,所以赠送的光盘没什么用处。
2.此时还无需插入usb dongle。打开OSX中的终端,敲入如下指令:
sudo nvram
bluetoothHostControllerSwitchBehavior="never"
3.进入OSX的系统信息,查看Hardware->Bluetooth设定,确认一下此时的Vendor ID is "0x5AC"即可,如下图所示。
4. 插入usb dongle,打开xcode,进行调试。
注意:调试时需要将iOS虚拟机中的蓝牙打开。如下图所示。
在iOS平台上开发BLE设备是一件很昂贵的工作,通常你需要准备以下东西:
较新的MacBook笔记本,运行xcode
iPhone 4S、新iPad或更新的iOS设备
最低99美元每年的开发者年费
但是如果你能接受只在模拟器上运行程序,而不需要真机调试或发布应用程序的话,后两项是可以省掉的。你需要准备的东西变成:
较新的MacBook笔记本,运行xcode 4.4、Mac OS X 10.7.3或更新版本
一个廉价的CSR蓝牙4.0 USB适配器(淘宝价大约30元RMB)
很奇怪的是,即使你的MacBook上带有蓝牙4.0,你还是需要这个CSR蓝牙4.0适配器。
具体步骤见苹果的文档:
http://developer.apple.com/library/ios/#technotes/tn2295/_index.html
这种调试方法在我同事的MacBook Air和我的CC2540节点板上调试通过。
还要感谢black在QQ群里共享了他修改过的TI iOS例程,使之可以点亮我的节点板上的LED,测试过程相当顺利!
As of iOS 5 and OS X 10.7 a new framework is available: The CoreBluetooth.framework. This framework enables developers to communicate with a new class of energy efficient Bluetooth devices.
The Bluetooth standard describes a number of use-cases called profiles. Each use-case standardizes one or more services a device can implement. A service publishes certain standardized characteristics which applications can read from or write to. So when writing code to interact with a heart rate service a developer can be sure it will work with both a Polar and a Wahoo strap. A full list of standardized Bluetooth low energy services is available on the Bluetooth developer site.
Using CoreBluetooth.framework
The Bluetooth standard describes a number of use-cases called profiles. Each use-case standardizes one or more services a device can implement. A service publishes certain standardized characteristics which applications can read from or write to. So when writing code to interact with a heart rate service a developer can be sure it will work with both a Polar and a Wahoo strap. A full list of standardized Bluetooth low energy services is available on the Bluetooth developer site.
When developing custom or hardware for something not covered by the standard it’s perfectly possible to define a new service and new characteristics.
None of these standardized profiles are currently implemented on iOS on a system wide level. It’s up to the developer to actually write client code to these services in the apps itself. The CoreBluetooth framework provides a general set of classes you can use to implement a profile.
As someone has mentioned, the APIs are available in the iOS 5.0 SDK. However, bear in mind that those APIs only provide support for ATT client, if you want to add services and act as a server you're out of luck for now. I truly hope Apple will add server support at some point, since some profiles (Alert Notification or Proximity) would benefit enormously: being able to be notified when you receive a new SMS/email or being able to "ping" your phone to find it would be great.
We’ve long been able to get Arduino and Android to talk to each other over Bluetooth (for example, see the Android Controlled 3D Printed Slalombot), but doing that with an iOS device has required you to be enrolled in Apple’s MFi program or you to jailbreak your device.
That seems to have changed with the addition of Bluetooth 4.0′s “Bluetooth Smart Ready devices”. Alasdair Allan [via Tom Igoe] clued me into this really interesting development. Dr. Michael Kroll is working on a Bluetooth Low Energy (BLE) Shield for Arduino based on the Bluegiga BLE112 modules:
Right after my first contact with BLE technology I was thinking of a BLE Shield for the Arduino. I really liked the Arduino BT of the Bluetooth Shield from Seeed Studio, but since these boards are not “Made for iPod”, they are not connectable to iOS Devices. The idea I had in mind was to create something similar to the Seeedstudio Bluetooth Shield where the Arduino’s Serial RX/TX pins or Pins 2/3 (with SoftwareSerial) can be used to read data from and send data to an iOS device. That said, I started a first prototype of an Arduino Shield using Bluegiga’s BLE112 Bluetooth 4.0 single mode Development Kit. Once Bluegiga’s firmware was finished and my first sketch could read and write to my iPhone 4S, l then I created my first real Arduino Shield PCB.
…
Dr. Michael Kroll: Bluetooth Low Energy (BLE) Shield for Arduino
目前有蓝牙4.0功能的手机就只有几款,摩托罗拉的刀锋系列、HTC1x和三星GS3,HTC1x和三星GS3虽然有蓝牙4.0的硬件设备但迟迟没有成熟相关SDK可以进行开发,开源的博通BLE SDK开发出来的没有手机可以使用。
目前市场上销量最好的android蓝牙4.0的就是三星GS3,但系统本身的蓝牙功能连搜索BLE的设备都搜索不到,更别说连接使用了,持续关注了几个月也只有些零散的资料有些牛人整出了些framework但需要root的用户才能使用,跟苹果需要越狱一样,买GS3这种手机的人除了开发人员估计很多都不会root的,因为一root就失去了保修服务。
最近有看到了些希望,有人用三星的开发包弄出可以搜索到所有蓝牙设备的应用了,但没有真机测试还不能确定是否可以使用。
话说iPhone的版本也只有iPhone4S以上的手机才可以使用,但ios5升级到ios6系统后也是有验证bug的,导致手机app无法下发指令数据到蓝牙设备,所以需要交互的BLE应用都没法使用,iPhone5默认的系统是ios6应该也是用不了的,而且功耗比ios5的大很多,也只能坐等苹果升级系统,不过苹果由于闭源和开发投入比较大升级日期应该不会太久,应该等几个月就可以解决了。(后注:不出所料很快就出ios6.0.1版本解决了wifi连接等问题了,同时出ios6.1bate版本)
android的就蛋痛了,各个厂商的都定制成不一样的,各个系统版本上也有差异,兼容性很难保证,屏幕大小也差别非常大,开发广泛使用的应用在兼容性上就浪费了很多精力,而需要根据各个厂商提供的不同sdk开发的应用就只能适应某一类手机了,不同厂商的基本上都不兼容得重新开发了。
另外iPhone手机的蓝牙是不能够和android手机的蓝牙通信的,而且iPhone除了蓝牙4.0以外其他版本的蓝牙外设需要通过苹果的认证才能使用的,除非大厂商大批量生产否则不可能通过认证的。所以很多小公司,解决方案的公司做iPhone的应用只能做蓝牙4.0的,android的则没有这个限制。
另外当初就搜索到健康类的应用有人做出产品的 但不是基于蓝牙4.0低功耗的 还是用蓝牙2.1的spp协议来做的,蓝牙2.1或者3.0的耗电是个比较大的问题,一些小外设,需要用纽扣电池的应用就无法真正使用,对一些创意产品如果需要经常换电池或充电对用户体验都会大打折扣,成本也会大大提高。
相对wifi和zigbee无线方案,蓝牙和无线射频模块nRF24l01成本会低很多,wifi的好处是可以比较方便实现远程控制,距离比较远,信号也相对比较稳定。
补充内容:
经过不断努力终于可以让三星的支持BLE了,HTC1X,moto这几个主流蓝牙4.0的android都可以开发了,但估计以后只会先开发三星销量大的了,不同厂商底层差别太大了。
ios6.0的问题也解决了,解决办法暂时保密。 三星的解决办法之前在博客里公开过一段时间现在公司也要设为保密了。
另外ios6.0可以把iPhone手机当从设备了,可以两台iPhone通过蓝牙通信传数据了,有点类似spp协议,但android的蓝牙4.0的没有看到相关的api。
现在LG出的google nexus 4 也支持ble蓝牙4.0了,但目前也没有对应的api和sdk
ble的发展变化比较快,之前收藏的很多网址现在都访问不了了,更新或者作废了
补充内容2:
http://processors.wiki.ti.com/index.php/Category:BluetoothLE
这个是TI的wiki上的文章,上面有moto和HTC的例子程序的,但支持不全面,之前的描述是
MotoRAZRAndroidBLEDemo Obsolete. Updated Motorola BLE SDK with new API is not compatible.
HTC1X BLE API - Complete BLE API for HTC1X (European version only!) NEW!
现在有变成下面的了
MotoRAZRAndroidBLEDemo Obsolete. Updated Motorola BLE SDK with new API is not compatible.
HTC1X BLE API - Complete BLE API for HTC1X (European version only!) Obsolete. Updated Android SDK is not 100% compatible.
三星4.0.4可以搜索到ble设备,但连接有问题,需要升级到android4.1.1以后才行
Open Bluetooth Low Energy API
http://android-btle.github.com/framework/
这个是博通的开源的api 需要root权限才能用的,用户需要像精简版rom增加google maps的add-on那样增加相关文件到手机系统里面后才能用,除了需要root外对用户要求也比较高。
你需要安装一个小的USB蓝牙适配器在车上,当然是要能够跟iPhone配对的。这个适配器会跟你的iPhone上面的Find My Car Smart一起在后台运行。当你离开车的时候,它可以自动记住最后的GPS位置。无需手动调整,而且在后台运行对电池电量的耗费也不是很多。