Why isn't Bluetooth LE working from the iOS Simulator to my device? - ios

I'm trying to figure out why my BTLE TI CC2540 keyfob is working with my iPad 3 but not with the iOS Simulator equipped with a new GBU521 IOGEAR adapter on Mountain Lion.
I've been able to successfully connect the iOS 5 Simulator Bluetooth in the general settings (it says on, now) to my BT adapter, and to be considered as 'powered on' in my proof of concept app. I'm using a GBU521 IOGEAR adapter, which only worked after upgrading to Mountain Lion (tried Lion with some hack modifying some .kext files-- don't do that. Upgrading to Mountain Lion was impossible until I reverted that .kext). I then ran the Apple suggested nvram setting, rebooted, and it was able to recognize the BT adapter.
I'm able to communicate with my iPad 3 successfully (registering the button pushes, accelerometer, etc), but when I try to run it on the simulator, it just doesn't discover the device. It's telling me the BT state is CBCentralManagerStatePoweredOn, but then when I tell it to discover peripherals, it comes up with nothing.
How can I establish Bluetooth LE communication between the iOS Simulator and an LE-enabled iOS device?

(modified from my answer in other iOS Simulator Bluetooth thread here: Bluetooth Dongle and iOS Simulator)
Throw away the IOGEAR and pick up a Cirago BTA8000.
I'm not sure why you were able to turn Bluetooth on in the iOS Simulator (possibly related to your kext editing, which I tried too), but I suspect it's not actually on. I bought the IOGEAR you mention, in addition to the Cirago BTA8000, and the MediaLink 4.0 adapter. Turns out that anything based on the Broadcom chip won't work despite my MacBook having the exact same one built in, which means the MediaLink and IOGEAR don't work. My Cirago shipment just arrived this morning, and the Bluetooth slider in the iOS Simulator flicks to "ON" in less than a second.
If you want to experiment, I'd love to hear if other non-Broadcom chips work too.

Does your keyfob didn't came with a dongle? I'm planning to buy one :S
Update: I've just found this(But probably you have arleady seen this, it explains why you are using a separate adapter): http://developer.apple.com/library/ios/#technotes/tn2295/_index.html
Also the reviews on amazon of your adapter doesn't look very good. have you tried it with antoher device? http://www.amazon.com/IOGEAR-Bluetooth-Micro-Adapter-GBU521/dp/B007GFX0PY/ref=sr_1_1?ie=UTF8&qid=1344560021&sr=8-1&keywords=GBU521+IOGEAR

Related

Test bluetooth connection between iOS simulation in Xcode and a physical device? [duplicate]

I'm trying some iOS test applications on the new Mac mini, that supports Bluetooth Low Energy. The CoreBluetooth framework is used in those. However, I'm not able to get Bluetooth working in the iPhone simulator, that is part of Xcode.
When I allocate a new CBCentralManager, centralManagerDidUpdateState: receives CBCentralManagerStatePoweredOff which stands for Bluetooth is currently powered off.
The first time I ran the text application, a box was then opened up that looked pretty bugged (only language variables were used, not the actual texts) and with two buttons. The first led me to the settings panel where there was an option to enable Bluetooth. However, after I told it to enable Bluetooth, it just shows the spinning animation, and it won't either complete or cancel. Even after rebooting the Mac, there is still only the spinning animation. The box also does not open up anymore.
Essentially, I think that the iPhone simulator should support Bluetooth Low Energy. Otherwise, it does not really make sense that there is an option in the settings application on the simulator. Also, the central manager state is CBCentralManagerStatePoweredOff but not CBCentralManagerStateUnsupported which would stand for The platform doesn't support Bluetooth Low Energy. This gives also hope that support could exist.
Does the iPhone simulator support Bluetooth Low Energy?
If yes, how can I enable it?
The simulator does support Bluetooth Low Energy (4.0) according to this appnote from Apple. The only problem is that even if you have a computer with BLE inside, you will not be able to use the simulator together with it, because (I think) you occupy the availability on BLE for other devices to discover your computer, thereby restricting the functionality of the Mac.
So if you go get yourself a BLE USB dongle you will be able to use it in simulator.
EDIT: Adding information from #JoeShaw:
Unfortunately it appears as though Core Bluetooth support has been dropped from the simulator for iOS 7. Reference: doubleencore.com/2013/09/whats-new-in-bluetooth-le-ios-7. In addition, the linked technote seems to have been removed.
I have been using the simulator to test BLE apps - but you need to be on OSX 10.7. As Wilhelmsen mentioned, you also need a BLE USB dongle. In addition, you need to set an NVRAM setting:
$sudo nvram bluetoothHostControllerSwitchBehavior="never"
See this Technical Note from Apple for more details on using the simulator to test BLE apps: http://developer.apple.com/library/ios/#technotes/tn2295/_index.html
According to http://www.doubleencore.com/2013/09/whats-new-in-bluetooth-le-ios-7/, Core Bluetooth support has been dropped from the simulator as of iOS 7. I haven't figured out why yet, but it means you will need to test on real hardware in the future.
It also appears as though Apple has removed Tech Note 2295, as I get redirected when I hit the URL.
I've found that Apple writes in their own samples that the simulator cannot be used to test Core Bluetooth-based applications.
Important:
This project requires a Bluetooth LE Capable Device (Currently only the iPhone 4S) and will not work on the simulator.
I've been working on a BLE app for the past week and can say with confidence that no, the simulator does not support BLE unless the mac that your using has BLE(Macbook Air) - but even then i'm not 100% sure how to enable this(most likely by just turing on BLE on your mac and on the simulator).
If you don't have a BLE enabled mac, have to find yourself a 4s to do testing with!
One alternative approach to using CoreBluetooth in the Simulator is to use Nordic Semiconductor's CoreBluetooth-Mock library, which allows you to stub-out CoreBluetooth and provide simulated/mock peripherals for use when working with the simulator:
https://github.com/NordicSemiconductor/IOS-CoreBluetooth-Mock
It does require some minor code changes, but the interface it provides is almost identical to that of CoreBluetooth.
It's also great for writing integration tests too.
Actually I tried in the simulator and does not work.
The simulator does not recognize if you have a Bluetooth 4.0 in your computer but if you are using Command line tool projects in Xcode then it works. just for the cases you want to create something in Command line tool.

Core Bluetooth iOS CBCentralStateUnsupported [duplicate]

I'm trying some iOS test applications on the new Mac mini, that supports Bluetooth Low Energy. The CoreBluetooth framework is used in those. However, I'm not able to get Bluetooth working in the iPhone simulator, that is part of Xcode.
When I allocate a new CBCentralManager, centralManagerDidUpdateState: receives CBCentralManagerStatePoweredOff which stands for Bluetooth is currently powered off.
The first time I ran the text application, a box was then opened up that looked pretty bugged (only language variables were used, not the actual texts) and with two buttons. The first led me to the settings panel where there was an option to enable Bluetooth. However, after I told it to enable Bluetooth, it just shows the spinning animation, and it won't either complete or cancel. Even after rebooting the Mac, there is still only the spinning animation. The box also does not open up anymore.
Essentially, I think that the iPhone simulator should support Bluetooth Low Energy. Otherwise, it does not really make sense that there is an option in the settings application on the simulator. Also, the central manager state is CBCentralManagerStatePoweredOff but not CBCentralManagerStateUnsupported which would stand for The platform doesn't support Bluetooth Low Energy. This gives also hope that support could exist.
Does the iPhone simulator support Bluetooth Low Energy?
If yes, how can I enable it?
The simulator does support Bluetooth Low Energy (4.0) according to this appnote from Apple. The only problem is that even if you have a computer with BLE inside, you will not be able to use the simulator together with it, because (I think) you occupy the availability on BLE for other devices to discover your computer, thereby restricting the functionality of the Mac.
So if you go get yourself a BLE USB dongle you will be able to use it in simulator.
EDIT: Adding information from #JoeShaw:
Unfortunately it appears as though Core Bluetooth support has been dropped from the simulator for iOS 7. Reference: doubleencore.com/2013/09/whats-new-in-bluetooth-le-ios-7. In addition, the linked technote seems to have been removed.
I have been using the simulator to test BLE apps - but you need to be on OSX 10.7. As Wilhelmsen mentioned, you also need a BLE USB dongle. In addition, you need to set an NVRAM setting:
$sudo nvram bluetoothHostControllerSwitchBehavior="never"
See this Technical Note from Apple for more details on using the simulator to test BLE apps: http://developer.apple.com/library/ios/#technotes/tn2295/_index.html
According to http://www.doubleencore.com/2013/09/whats-new-in-bluetooth-le-ios-7/, Core Bluetooth support has been dropped from the simulator as of iOS 7. I haven't figured out why yet, but it means you will need to test on real hardware in the future.
It also appears as though Apple has removed Tech Note 2295, as I get redirected when I hit the URL.
I've found that Apple writes in their own samples that the simulator cannot be used to test Core Bluetooth-based applications.
Important:
This project requires a Bluetooth LE Capable Device (Currently only the iPhone 4S) and will not work on the simulator.
I've been working on a BLE app for the past week and can say with confidence that no, the simulator does not support BLE unless the mac that your using has BLE(Macbook Air) - but even then i'm not 100% sure how to enable this(most likely by just turing on BLE on your mac and on the simulator).
If you don't have a BLE enabled mac, have to find yourself a 4s to do testing with!
One alternative approach to using CoreBluetooth in the Simulator is to use Nordic Semiconductor's CoreBluetooth-Mock library, which allows you to stub-out CoreBluetooth and provide simulated/mock peripherals for use when working with the simulator:
https://github.com/NordicSemiconductor/IOS-CoreBluetooth-Mock
It does require some minor code changes, but the interface it provides is almost identical to that of CoreBluetooth.
It's also great for writing integration tests too.
Actually I tried in the simulator and does not work.
The simulator does not recognize if you have a Bluetooth 4.0 in your computer but if you are using Command line tool projects in Xcode then it works. just for the cases you want to create something in Command line tool.

If I don't have a Bluetooth LE device am I just out of luck with trying to write a program?

I see questions surrounding issues such as "Device Unsupported" in many posts on this website and on the internet, so I feel like the problems I am having are not unique.
What perplexes me (and trust me I have searched all day) is that I recently bought a new Macbook Pro computer (surely the BT on this thing is LE), upgraded to Mavericks, and am using Xcode 5. But no matter, what sample code I download, whether from the BT SIG or CSR, etc., I always get the same basic errors (on the iOS Simulator):
Something to the effect of "Device Unsupported" AND
Something about how it can't run because it's not powered on (and I did try to work around by wrapping the central.state call in an if block)
So, are the people like me who are starting to code Bluetooth today just screwed if we don't have LE devices? Did all of the BT code prior to 4.0 fall off the face of the earth or get deprecated?
Is there a simple way to force my code to run in some type of "non-LE" mode?
As for the code I'm using, I downloaded the Quick Start kit from the BT SIG, but nothing works, even simple scan programs that I have found. Ugh, any ideas out there?
My ultimate goal is to write something that will run without errors, load on my iPhone 4, and scan and pair with my car's stereo and grab all of the peripheral advertisements that it is sending out to see what all I can do with (to) the stereo.
Thanks all.
While your computer does have Bluetooth Low Energy/Bluetooth 4.0/Bluetooth Smart (they are all different names for the same thing) capabilities, these are not available to the simulator. A while ago you could add an additional BT4.0 dongle to the Mac and then access that from the simulator, but this is no longer supported - see Does the iPhone simulator in Xcode support Bluetooth Low Energy?
You can develop BT4.0/BLE code in Xcode for OSX with just your computer, but if you want to develop and test iOS code you will need a BLE capable iOS device (iPhone 4S or later, iPad mini/3rd gen/Air or an iPod Touch 5th generation)
Access to non BT4 devices is only via the Apple MFI program, with the exception of a few generic profiles, such as handsfree & A2DP streaming - but these are exposed to your program as audio devices, not as Bluetooth devices.
If you have an iPhone 4S (not iPhone 4) then you can use the LightBlue app from the App Store to see if your car stereo is advertising any BLE services (which it probably isn't).
crawdaddy18, Bluetooth Smart/4.0/LE are fundamentally different technologies then what we'll call Bluetooth Classic (2.0/2.1/EDR/BR...this is the stuff you are referring to with your car audio example). If you want to see what's going on with your car stereo, see what profiles it supports (should be listed in the documentation). Then take a look here:
https://developer.bluetooth.org/TechnologyOverview/Pages/Profiles.aspx#Profiles
This page lists all of the 'classic' profiles. You should find the ones that match your car on the list. You'll then know what functionality your car stereo supports.
Then, it's off to the races with OS documentation to look at the object models for classic Bluetooth. Usually these are either supported by an object model that represents the profile or are wrangled through RFCOM somehow...but each OS is a bit different.
But most of the tools that are out there, including the Application Accelerator, are geared to let you explore LE (Smart) devices out there. If you want to use something like the Application Accelerator to view non-LE devices, you'll have to re-jigger the code to switch the object models that you use in the OS' SDK. The reason that most recent tools you are finding now are geared towards the LE side of things is that that is where the massive growth in appcessories (and the Bluetooth industry) is heading. But there are TONS of sample code out there to help to create an app to scan and connect to classic Bluetooth devices as well.

iOS to Mac OS X [core] bluetooth data transfer

My objective here is to create a connection between a device running iOS to a device running Mac OS X, via bluetooth. I know that I might be able to use CoreBluetooth for this but I don't understand how since I don't see a method to setup a service on the iOS device and broadcast it as an available service for a device running Mac OS X. In other words, I simply want to setup a connection to get the iOS device to send data to the Mac OS X device. Also, how would I go about to specify how to setup properties of the service. I've tried researching this stuff but most of the documentation makes little sense to me. The data transfer is small so bluetooth is good enough for the job. I'm trying to avoid Bonjour for this, and the Game center framework for P2P since OS X can't handle that (I think).
In iOS6 the iPhone 4S, 5 and New iPad can work both as Peripheral and as Central in Bluetooth Smart / Low Energy mode.
Try downloading "LightBlue" APP from APP Store. It let's you put the iPhone4S or 5 into Peripheral mode with random Services which you can then read from the Mac (if you have a newer one with BT Low Energy, I use the Retina for that but also the new iMac and Mac Mini got BT Low Energy).
You are correct that Core Bluetooth only give access to Bluetooth Low Energy which doesn't allow for the MFI chip.
Just ran across this today... and just wanted to give another answer to anyone needing to communicate to a non-Bluetooth LE device from your Mac.
The way to go is with IOBluetooth, and IOBluetoothUI.
They are both frameworks for the Mac, and they allow you to communicate with both old bluetooth, and Bluetooth LE 4.0, I believe. Also, I'm pretty positive you can act as a Central and Peripheral Device using this framework.

Bonjour not advertising over BT

I've been banging my head against this for the last week or so. I've already gone through the following resources:
StackOverflow: Bonjour over bluetooth WITHOUT Gamekit ? (3844189)
StackOverflow: How does Bonjour Over Bluetooth Work (3350094)
StackOverflow: Using iOS GameKit's “Bluetooth Bonjour” with other platforms (8070998)
Technical Q&A QA1753 -- Apple Developer
WiTap sample application
SRVResolver sample application
DNSSDObjects sample application
I'm using Mac OS 10.7, Xcode 4.5, an iPhone 4 with iOS 6, and an iPad 1 with iOS 5.1.1.
My problem is this: I am modifying an application that currently uses GameKit's peer picker to connect between an iPad and a iP{hone|od touch}. We want to modify this to use Bonjour over Bluetooth instead because we've had issues with reconnecting the devices using Gamekit if the connection is lost. I've used dns_sd.h API to some success and have gotten the service to advertise and resolve over wifi, but even though I am passing kDNSServiceFlagsIncludeP2P I am not getting any success over bluetooth.
I thought possibly Bluetooth Bonjour need a PAN established between devices already, but even pairing the iPad to the iMac and browsing for DNS-SD services gives me nothing...and the iPhone won't pair to the iPad anyway.
I just finished solving this in my own app in the last 24 hours. I used the core classes from the OS X sample app DNSSDObjects. I only had to change three lines of code to add support for bluetooth. This works great in my iOS app.
In DNSSDBrowser.m, the call to DNSServiceBrowse needs to have kDNSServiceFlagsIncludeP2P passed in for the 2nd parameter.
In DNSSDRegister.m, the call to DNSServiceRegister needs the same change.
In DNSSDService.m, the call to DNSServiceResolve also needs the same change.
If you want to limit yourself to just bluetooth, and not WiFi, then the same three lines of code should be updated so the 3rd parameter is kDNSServiceInterfaceIndexP2P instead of kDNSServiceInterfaceIndexAny.
Indeed, it looks like the kDNSServiceInterfaceIndexP2P flag won't work on OSX.
If you run the code on IOS, you'll notice that Bonjour will publish two IP Adresses: one for your local WiFi network, and an 169.xx.xx.xx adress for Bluetooth.
The same code on OSX never publishes the 169.xx.xx.xx adress, so it's only found over WiFi.

Resources