Device gets disconnected every 20 sec in avg

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.xmece.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
12 posts / 0 new
Last post
Ezza
Offline
Last seen:1 year 6 months ago
加入:2017-09-07 11:33
Device gets disconnected every 20 sec in avg

Hi,
I'm using DA14580 to transfer data via UART.
When I added the uart connection, the devices gets disconnected from the phone every 20sec in avg.
If I don't use uart, the device does not disconnect. (from the main loop I send uart request every 10sec)
user_app_disconnectis invoked after 20sec from connecting to the device via phone.

What could be the issue with my uart implementation that may cause the device to get disconnect? Or, how can I prevent the device from getting disconnected.
How can I figure out what is causing the disconnection.

Thanks,
Ezza

Device:
Ezza
Offline
Last seen:1 year 6 months ago
加入:2017-09-07 11:33
After debugging, gapc

After debugging, gapc_disconnect_ind_handler is invoked.

static int gapc_disconnect_ind_handler(ke_msg_id_t const msgid,
struct gapc_disconnect_ind const *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
{
if (KE_IDX_GET(src_id) == diss_env.con_info.conidx)
{
diss_disable(param->conhdl);
}

return (KE_MSG_CONSUMED);
}

-----------------------------------
gapc_disconnect_ind const *param parameter has a reason for the disconnect.

/// Indicate that a link has been disconnected
struct gapc_disconnect_ind
{
/// Connection handle
uint16_t conhdl;
/// Reason of disconnection
uint8_t reason;
};
The原因value is 0x08.

MT_dialog
Offline
Last seen:3 months 2 days ago
Staff
加入:2015-06-08 11:34
Hi Ezza,

Hi Ezza,

Well, what i can assume is that you are keeping the ARM occupied using the UART and there are no BLE events scheduled during that time, so the device never gets up on time for the connection event, eventually you are loosing the connection event and the timeout occurs. The disconnection reason that you get is due to connection timeout which indicates that you are missing connection events.

Thanks MT_dialog

Ezza
Offline
Last seen:1 year 6 months ago
加入:2017-09-07 11:33
Hi,

Hi,
Thanks for the reply.
How can I prevent that from happening?
I don't want my device to get disconnected during uart event.

ibbkoeln
Offline
Last seen:4 months 2 days ago
加入:2016-03-18 10:34
Hi Ezza,

Hi Ezza,

也许你正在做一些time-consuming or blocking operations during the uart calls in main loop? What do you mean by "main loop"? As far as I know there is no main loop in the user application api, just callbacks. I guess we have to see your code to better understand that.

Regards,
Oliver

Ezza
Offline
Last seen:1 year 6 months ago
加入:2017-09-07 11:33
Hi,

Hi,
Since DA14580 does not have a "Read" indication event. I had to enter the Main arch and added a custom code there.
In the main loop of arch_main, I call UART commands to update the DB of the ble, in order for the phone applciation read updated data.
For example, I have a counter on my ST firmware that is being updated all the time, and the application needs to read that counter. I keep it updated on the DB of the BLE by sending UART command from the main loop every 10s.

有什么方法可以增加价值的时间吗out for the disconenction event? (i.e. even if I don't catch connection events, wait longer than 20s).
Why sending\getting commands via UART causes a disconnection?

Thanks,
Ezza

ibbkoeln
Offline
Last seen:4 months 2 days ago
加入:2016-03-18 10:34
Hi Ezza,

Hi Ezza,

to read the values periodically I would highly recommend to use easy-timer api instead of changing arch_main since this can easily disturb the ble timing. Here is how I would implement this:

#define READ_VALUE_INTERVAL 1000 // 1 => 10ms

static timer_hnd readValueTimer = EASY_TIMER_INVALID_TIMER;
static uint8 rxData[RX_SIZE];

void rxUartCallback(uint8 state) {
if(state==UART_OK) {
// process rxData here
readValueTimer = app_easy_timer(100, readValueFromUart);
} else {
// error handling
}
}

void readValueFromUart() {
uart_read(rxData, RX_SIZE, rxUartCallback);

uint8 cmd[] = { ... };
uart_write(cmd, sizeof(cmd), NULL);
}

void user_on_connection(uint8_t connection_idx, struct gapc_connection_req_ind const *param) {
...
readValueTimer = app_easy_timer(READ_VALUE_INTERVAL, readValueFromUart);
}

void user_on_disconnect( struct gapc_disconnect_ind const *param ) {
if(readValueTimer != EASY_TIMER_INVALID_TIMER) {
app_easy_timer_cancel(readValueTimer);
readValueTimer = EASY_TIMER_INVALID_TIMER;
}
}

Regards,
Oliver

Ezza
Offline
Last seen:1 year 6 months ago
加入:2017-09-07 11:33
Hi,

Hi,
Unfortunately, it still the same issue. I changed my code and removed everything from arch_main and used easy_timer.
Also, even if I send events from the phone like "write", it still will disconnect in 20sec in avg.

ibbkoeln
Offline
Last seen:4 months 2 days ago
加入:2016-03-18 10:34
Is the connection stable

Is the connection stable without reading/writing to a characteristic and only reading values over uart continuously in background?

Ezza
Offline
Last seen:1 year 6 months ago
加入:2017-09-07 11:33
Hi,

Hi,
It's not stable even when I'm doing nothing (no read and no write).
I just connect to the device and waited for it to get disconnected.

Ezza
Offline
Last seen:1 year 6 months ago
加入:2017-09-07 11:33
Hi,

Hi,
Where can I jandle the disconnection event, and prevent it from happening?
Its a blocker for us, since the device keeps getting disconnected and the phone-application get's exceptions till it finally success reading all the values from ble. This causes a dramatic decrease of the performance.

MT_dialog
Offline
Last seen:3 months 2 days ago
Staff
加入:2015-06-08 11:34
Hi Ezza,

Hi Ezza,

You will have prevent any UART activity from overlapping your connection interval, the UART communication should be in bursts and not having the ARM occupied for long since if you do the ARM wont be able to program the BLE events on time. For example you could attach a UART logic in the .app_on_system_powered in order to process any UART events but you should not stay there for long, you should return KEEP_POWERED in order to force again the schedule_while_ble_on() to re-run in order to schedule any BLE events that will occur and then the SDK will run the .app_on_system_powered again for the rest of the UART activity. Regarding increasing the supervision timeout, i suppose that the now the timeout is allready large 20 seconds if increasing it this will save you from the disconnection depends on the connection interval that you are using, but again this is not a solution you should review your implementation in order not to loose the connection events during the UART interaction. You cant stop the disconnection from triggering, the message is comming from the stack as soon as the supervision timeout occurs, even if you prevent the message notfying your callback the device will still be disconnected.

Thanks MT_dialog