Reasons for sporadic bluetooth disconnect on iPhone - iphone

my system consists of a bluetooth accessory and an iPhone. Sometimes I see a link loss between the two devices in idle mode. I have only seen it in idle (sniff) mode so far. Sometimes it happens every few minutes, sometimes after an hour or so. I have no clue why. My accessory does a reconnect right after loosing the connection, but that is very bad user experience.
What I did so far:
I read the iPhone accessory guide and was a bit surprised about the advice to set the sniff period to 15 ms. In the example application of my chipset (CSR) I see a period of 800 slots == 500 ms. I configured my application to use minimum of 15 ms. Nevertheless the iPhone indicated a period of 384 slots.
I also checked the supervision timeout. It is set to 8000 slots == 5 seconds. Seems ok.
I also have the impression that it mainly happens if two phones are connected to the accessory. The second phone is an android. The android phone does not have a problem.
Now I run out of ideas what to do. Do you have a idea here?
Thank you,

After a lot of sniffing and debugging I found out the reason on physical layer. The situation was the following: I have a headset (HS), an iPhone (I) and an Android (A).
To reproduce I had to:
Connect HS and iPhone
Connect HS and Android. Important: The Android device had to initiate the connection.
Now the HS is in the situation where both peer devices are in bluetooth master role, the HS is in slave role on both connections.
What now happens is that both master may set the HS into sniff mode with some sniff interval which is conflicting with each other. Due to time slot collisions the connections is then lost.
One possible solution is to detect this situation on the HS and either never go to sniff mode or use a shorter timeout to change from active to sniff mode. In this case, the HS can propose the sniff intervals for both connections and prevent conflicts.

Related

Detect Iphone 6 by mac on wifi network if its not connected.

I want to track my iPhone 6s device for the probe requests it is sending to connect to the WiFi router.
This is my current setup:
I have kept the WiFi on and have forgotten the network, in the phone so that it probes new APs.
1.The location and services is disabled.
2.The Mobile-Data is also On.
3.I am using Aircrack-ng to trace the probe requests to the router.
4.I ran the setup to get the probe requests for 1 hour, but still couldn't get the entry for the iPhone.
5.I also used wireshark and a different router to detect the iPhone but still it is not available. The capture duration was 1 hour.
6.The phone screen was randomly on and off.
I have read that from iOS8 Apple uses MAC randomization for the user safety so that they can't be tracked, but now I have a clear insight of what are the conditions when the randomization occurs(location disabled and packet data disabled and phone in sleep mode.)
I want to know that is the randomization actually happening and even if it is happening, how do I know the new Locally Randomized address of my device to trace it on Aircrack-ng/Wireshark.
And If the randomization process is actually not happening then why can't I see my iPhone in the list.
Some articles I followed:
http://blog.mojonetworks.com/ios8-mac-randomization-analyzed/.
http://www.cisco.com/c/en/us/td/docs/wireless/controller/technotes/8-0/iPhone_roam/b_iPhone-roaming.html#concept_79EB523637BD49F3AE876F9C1C95DD69

how to restart iPHone/iPad Bluetooth LE after communication hangs

What is the best way to COMPLETELY restart the iOS Bluetooth BTLE central and peripheral managers, after communication stops between two iOS devices (iPad-mini)?
Sometimes after a few minutes, my BTLE communication stops (central can not get response from peripheral, though debug output of each device shows app still running and central app still is trying to scan peripheral, and peripheral is still advertising), and will not start again:
after stopping scanning and stopping advertising, comm still doesn't work;
after re-opening the app, comm still doesn't work(!);
after POWER CYCLING the iPads comm works again, but then after a few minutes dies.
Therefore, something I'm doing is clobbering maybe the iOS core Bluetooth software.
Sometimes there are error messages from the underlying BTLE layer.
BACKGROUND:
Each iPad in this system alternately works as central, to read/write data to others, and then as peripheral, to be read by others. Never at the same time, and with a 1 second delay between transistions.
The bluetooth stack is not the most robust part of iOS. This may have improved in iOS7 but issues have always existed. You most probably are stressing the system so that this hang happens more often. You should create a bug report and send it to Apple. Or create a TSI, as a developer you have two of those every year. They are the only ones who can do something about it.
To solve the issue, restarting the app usually helps but sometimes bluetooth needs to be turned on/off or worst case the device needs to be power cycled. Unfortunately, there is not programmatic way to do any of these.

iphone 3G data network timeout?

My iPhone app sends data persistently over the network, and can handle having the network completely unavailable for a time. However I do my dev on an ipod and have difficulty testing 3G connectivity issues; My question: is there period of non-connectivity, while an app is in the foreground, after which the iphone will stop checking for the network, such that there are no bars and reachability returns 0 until the user "wakes" the phone, e.g. by locking/unlocking? Or can e.g. 1 hr without data network pass and the iphone will recognize that the network is back and reachability will start returning true (I am polling every 1 minute while there is not connection to my server).
This is my experience with wifi: if, while running my app, the ipod hasn't connected to a wifi network for 1/2 hr, it stops looking for networks, and I need to lock and unlock it to stir the device into looking again.
One other thing: the iPhone has the screen dimmed by the proximity sensor while all this persistent network use is happening.
Wi-Fi going down after 30 min of inactivity is a documented behavior. Cellular network is always active, unless turned off by the user. So if it goes down for a while it should get back online automatically when possible even if there was no user activity.

Is using airplane mode an acceptable way to test a lack of connection?

We are in the process of developing an method of caching so that our app can continue to operate in an area with very little/no signal.
Obviously users will try to continue to use functions that require data and we need to handle the inevitable failure of these requests appropriately.
Essentially we are sat in the office, switching airplane mode on and off to simulate entering/exiting signal then adjusting our app to fix any issues this may arise.
What I'd like to know is, is using airplane mode going to give us a reasonable simulation of entering/exiting an area with no data or are there other implications?
I've seen questions raising the issue that the 3G/EDGE connection may not always wake up after airplane mode is switched on - while I appreciate this method is no way as good as actually being out in the field testing, if we can get a reasonable simulation and account for the majority of the problems that arise then I think this is an acceptable tradeoff.
I apologise if this has been asked before, I did do a search on here & on google but couldn't find any appropriate results.
You should try the Network Link Conditioner
There is a WWDC 2012 session called Networking Best Practices that mentions it (but he does not explain how to use it there).
To get it, you have to go to XCode/Open Developer Tool/More Developer Tools.. and download the latest Hardware IO Tools for XCode.
Once you install it from the IO Tools pkg, "Network Link Conditioner" will appear in System Preferences
You can then do something like 100% packet loss to simulate one of those routers that pretends you are connected but actually doesn't work.
On iOS, the network link conditioner is under Settings / Developer (you must have enabled Developer mode in XCode first to see it)
The main problem is that in the Airplane Mode the networking operations fail fast, while spotty mobile signal will lead to timeouts and a-few-bytes-an-hour speeds. This is usually a significant difference from the UI viewpoint. (It might be worth a try to use some bandwidth throttle to starve the testing machine and see how it behaves when the network starts to break?)
A few years back, when testing remote devices which used the cell network to communicate with the 'home base', we did things like move them into a shielded room (make shift), place large shields on three of four sides to force them to connect to a certain tower (and therefore, network), etc. Brute force physical methods. Since this actually cuts off the signal, it may be a more realistic approach.
You may also want to try this through your wlan-router. First, disable data roaming on your iPhone. Then, let the iPhone be connected to the internet through your wlan network. Then, disconnect the gateway on your wlan router while your iPhone is still connected to the wlan network.
This depends on what failure modes you are trying to test.
I use Airplane mode as a first pass check to make sure an app submission isn't quickly rejected.
Other network failure handling checks might include:
3G only (no wifi).
WIFI only (in Airplane mode).
Pulling the power cord on the WIFI access point.
Pulling the network cable from the back of the WIFI access point after connecting to it (Reachability may falsely say yes).
Walking in and out of a basement
elevator (or other Faraday cage) in the middle of a transfer.
Driving between 2 cell towers during a data transfer.
Walking between 2 enabled WIFI access points between connection and data transfer.
Starting the app after more than 30 minutes of device inactivity (radios may be idle).
Running the app while another app (Safari, Mail) is downloading in the background.
etc.

Losing network connectivity on iPhone

I am developing a network application on iPhone that requires internet connection all the time. However, once I login to the server and keep the iPhone idle for a while, the iPhone goes to sleep mode and disconnects my network connection (it logs me out).
If I run the same application on iPhone, while the iPhone is connected to the PC through USB cable, it never loses its network connection.
In the info.plist file I have added these two flags, but does not seem to have any effect.
UIRequiresPersistentWifi -> true
SBUsesNetwork - integer ->3
Am I missing anything? Could you please let me know how can I make sure that the network connection is persistent throughout the life of the application?
In your application delegate ("appDelegate"), disable the idle timer in the +initialize method:
myApp.idleTimerDisabled = YES;
Note that this will keep your iPhone from sleeping while your app is open. This can present issues with battery life.
Another option might be to set up a background thread that opens a small CFStream on a timed basis.
What do you mean by "logs me out" here? At the network level, there is no "logged in" (*). There are only packets. You send them or you don't. So does your server process have some expectation of packets or messages arriving periodically? If it does, then you must send them, and that means that you can't go idle (idleTimerDisabled = YES). If you control the server, it is better to make it less demanding about how often you talk to it. This all happens well above the network layer, however.
UIRequiresPersistentWifi means that the Wifi radio is kept on while you're app is running, even if you don't talk on it. This is important for receiving data. Otherwise you drop off the network and others can't talk to you after about 30 minutes. It should be set in Info.plist, but this is certainly in your app bundle. If it weren't, your app wouldn't launch, so that isn't the problem.
(*) The cell network does have the concept of logged in, but that's not what's causing your problem.