Ok what the heck is up with iOS6 and how it handles Bluetooth LE disconnections? Before the device would disconnect immediately but now, for some strange reason, the device waits to disconnect for about 30-60 seconds. I need it to disconnect ASAFP!
I've been searing all over the internet trying to figure out how to initiate an immediate disconnection from the peripheral and I found this nifty email that explains a workaround is to unsubscribe from notifications on the service characteristics.
Now I think I'm doing that.. When I want to disconnect I call [connected_device setNotifyValue:NO forCharacteristic:connected_characteristic]
Then, in the didUpdateNotificationStateForCharacteristic function, I have...
if((int)characteristic.isNotifying == 0){
[manager cancelPeripheralConnection:peripheral];
}
In the function didDisconnectPeripheral...
connected_peripheral = nil;
connected_characteristic = nil;
[connected_peripheral release];
[connected_characteristic release];
I've also taken a good hard look at Apple's CoreBluetooth Temperature Sensor example but it hasn't really helped much....
Any help on this would be amazing!! I just don't know what I'm missing.....
UPDATE: It looks like the app needs to be connected to the bluetooth device for at least a minute before it is allowed to disconnect. If the app is connected for over a minute it will disconnect immediately when the command is sent. Otherwise, it will wait until that one minute mark to actually disconnect.
UPDATE: When I try to disconnect before the one minute mark, I get the following output to the log when the device actually disconnects.
Oct 24 16:49:35 Christophers-iPhone awdd[8168] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary
Oct 24 16:49:35 Christophers-iPhone awdd[8168] <Error>: CoreLocation: CLClient is deprecated. Will be obsolete soon.
According to Apple, this new feature is "by design".
The way we resolved this issue was to send a command to the Peripheral and have it disconnect from its end. If you do this, then the disconnect is immediate. I do not know why Apple changed this behavior from iOS5 to iOS6 but they must have had their reasons. Of course this solution only works if you have access to the Peripheral firmware and can change it. If there is a different solution, then we have not found it.
That was a bug in iOS 6.0, in 6.1 it's fixed.
Related
I'm using the STM BlueNRG-MS chip on my peripheral device and after connection I'd like to read the name of the connected central device (android phone).
I thought I can do this directly in my user_notify routine which is registered as hci callback
/* Initialize the Host-Controller Interface */
hci_init(user_notify, NULL);
So on the EVT_LE_CONN_COMPLETE event, I take the provided handle for the central device and I use aci_gatt_read_using_charac_uuid() to read what I thought is the characteristic with the device name (uuid 0x2a00).
case EVT_LE_META_EVENT:
{
evt_le_meta_event *evt = (void *)event_pckt->data;
switch(evt->subevent){
case EVT_LE_CONN_COMPLETE:
{
evt_le_connection_complete *cc = (void *)evt->data;
GAP_ConnectionComplete_CB(cc->peer_bdaddr, cc->handle);
uint16_t uuid = 0x2a00;
resp = aci_gatt_read_using_charac_uuid(cc->handle, 0, 1, UUID_TYPE_16, (uint8_t*)&uuid);
LOG("GATT read status: %d", resp);
enqueEvent(EVENT_BLE_CONNECTED);
}
break;
}
}
Long story short, it doesn't work. First thing I'm not sure about is, what is the start_handle and end_handle parameter of aci_gatt_read_using_charac_uuid(), it returns ERR_INVALID_HCI_CMD_PARAMS.
Can someone shed some light here?
update
What also puzzles me is that the function aci_gatt_read_using_charac_uuid() is nowehere referenced in the BlueNRG-MS Programming Guidelines.
update2
I changed the function call to aci_gatt_read_using_charac_uuid(cc->handle, 0x0001, 0xffff, UUID_TYPE_16, (uint8_t*)&uuid); but I still get the ERR_INVALID_HCI_CMD_PARAMS. What which paramter could even be invalid? The uuid exists, I can read the device name if I use the BlueNRG GUI with a bluetooth dongle.
update3
Has anyone ever used this function or somehow managed to read a characteristic from a central device? I'd highly appreciate any help or hint.
Here you go, The BlueNRG-MS Bluetooth® LE stack application command interface (ACI) - User manual
page 75 - 4.6.25 Aci_Gatt_Read_Charac_Using_UUID()
and make sure you have called Aci_Gatt_Init()
The user manual is last revised July 2019, the document you link to is from 2018, don't know if this is why ?
The start_handle and end_handle is the range of handles in your service as pictured here -
Here is a discussion to the closest thing I could find to match your question.
As it turned out there are two bugs in the BlueNRG API.
In bluenrg_aci_const.h file the OCF code OCF_GATT_READ_USING_CHARAC_UUID shall be 0x119 instead of 0x109.
And in the implementation of the aci_gatt_read_using_charac_uuid() function, there is a missing setting on event:
rq.event = EVT_CMD_STATUS;
Patching them fixed the issue.
I am a newbie in CANOPEN. I wrote a program that read actual position via PDO1 (default is statusword + actual position).
void canopen_init() {
// code1 setup PDO mapping
nmtPreOperation();
disablePDO(PDO_TX1_CONFIG_COMM);
setTransmissionTypePDO(PDO_TX1_CONFIG_COMM, 1);
setInhibitTimePDO(PDO_TX1_CONFIG_COMM, 0);
setEventTimePDO(PDO_TX1_CONFIG_COMM, 0);
enablePDO(PDO_TX1_CONFIG_COMM);
setCyclePeriod(1000);
setSyncWindow(100);
//code 2: enable OPeration
readyToSwitchOn();
switchOn();
enableOperation();
motionStart();
// code 3
nmtActiveNode();
}
int main (void) {
canopen_init();
while {
delay_ms(1);
send_sync();
}
}
If I remove "code 2" (the servo is in Switch_on_disable status), i can read position each time sync send. But if i use "code 2", the driver has error "sync frame timeout". I dont know driver has problem or my code has problem. Does my code has problem? thank you!
I don't know what protocol stack this is or how it works, but these:
setCyclePeriod(1000);
setSyncWindow(100);
likely correspond to these OD entries :
Object 1006h: Communication cycle period (CiA 301 7.5.2.6)
Object 1007h: Synchronous window length (CiA 301 7.5.2.7)
They set the SYNC interval and time window for synchronous PDOs respectively. The latter is described by the standard as:
If the synchronous window length expires all synchronous TPDOs may be discarded and an EMCY message may be transmitted; all synchronous RPDOs may be discarded until the next SYNC message is received. Synchronous RPDO processing is resumed with the next SYNC message.
Now if you set this sync time window to 100us but have a sloppy busy-wait delay delay_ms(1), then that doesn't add up. If you write zero to Object 1007h, you disable the sync window feature. I suppose setSyncWindow(0); might do that. You can try to do that to see if that's the issue. If so, you have to drop your busy-wait in favour for proper hardware timers, one for the SYNC period and one for PDO timeout (if you must use that feature).
Problem fixed. Due to much EMI from servo, that make my controller didn't work properly. After isolating, it worked very well :)!
I'm developing an HID Host application to comunicate with a own device and I'm using the NUCLEO-F446ZE board.
At the start I tried to use the HID_Standalone application in the STM32CubeF4 firmware package and then, I tried to develop a new application with STMCube configurator.
In both case I tried to connect (with OTG connector) 3 different type of mouse and 1 keyboard and no all device are able to comunicate with microcontroller:
with Typhoon mouse 40260 the USBH_Process state machine in the usbh_core.c file of the Middlewares, blocks in the HOST_ENUMERATION state (line 462) because the USBH_HandleEnum(phost) function try to get device descriptior (line 646 same file) but the USBH_HandleControl() function read all times USBH_URB_NOTREADY state (line 600 of usbh_ctlreq.c) until HAL_HCD_Disconnect_Callback() called by interrupt.
with Trust mouse 16144 is the same with Typhoon mouse with difference that the HAL_HCD_Disconnect_Callback() isn't called by interrupt.
with Dell Mouse XN966 all work fine and I can see the data.
with asus keyboard G01 KB the USBH_Process state machine in the usbh_core.c come up to HOST_DEV_DISCONNECTED where there is the BgndProcess but I can't receive data because in the HID_Handle the fifo has the tail and head at the same value.
All the previous devices are tested with PC and work fine and the board are powerd with external source.
What can be the problem and how can I fix it?
Thanks in advance
My apps could slow down in iOS 11, iPhone 6 plus. (Other iOS run as expected.)
I know SecTrustEvaluate() method is a reason that make the app slow down.
I run its in main thread takes about 3 seconds. So i use gcd to move its to background thread.
- (void)URLSession:(NSURLSession *)session didReceiveChallenge(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
BOOL allowConnect = //Server Trust Evaluation in here
dispatch_async( dispatch_get_main_queue(), ^{
if (allowConnect) {
//completionHandler;
} else {
//cancel
}
});
});
}
}
Then it do not block UI, but take 20 seconds for server trust validation.
Can someone know this issue? Please help me. Thanks.
I configure out my problem. This does not relate to iOS 11. It's my fault.
I create one NSURLSession for each security download image request on the same host.
Because TLS session is computationally expensive so that make my app slow down.
My solution is create only one session for all download request.
So evaluated server certificate’s result will be cached, and next request(on the same host, port) you don’t need evaluation server trust.
More info:
https://developer.apple.com/library/content/qa/qa1727/_index.html
Why is a HTTPS NSURLSession connection only challenged once per domain?
I have been having this issue with the NetworkManager which hangs/stuck forever after few request repeatedly (Url with different parameter still). Mostly it works till the 4th request then on the 5th request it hangs.
Please see the code
ConnectionRequest r = new ConnectionRequest();
r.setUrl(url);
r.setPost(false);
r.setDuplicateSupported(true);
NetworkManager.getInstance().addToQueueAndWait(r); // hangs right here
Reader reader = new InputStreamReader(new ByteArrayInputStream(r.getResponseData()), "UTF-8");
I have read few others had the same issue and I did add setDuplicateSupported(true) still getting the same error.
Any help is really appreciated. I really thank for Shai (from codename one) for being very supportive.
Thanks,
addToQueueAndWait literally waits until the network request finishes and in this case it doesn't finish or timeout. You can set a timeout to a lower value to make this fail more gracefully. I suggest reviewing the request you are making and why it is failing.
I also suggest looking at the network monitor to see what is going on.