# Auto-reconnect BLE feature request

**URL:** <https://mworks.discourse.group/t/auto-reconnect-ble-feature-request/198>\
**Category:** Support\
**Created:** [March 2, 2020, 6:13pm UTC](https://mworks.discourse.group/t/auto-reconnect-ble-feature-request/198 "2020-03-02T18:13:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [March 2, 2020, 6:13pm UTC](https://mworks.discourse.group/t/auto-reconnect-ble-feature-request/198/1 "2020-03-02T18:13:25Z")

</div>

Hey Chris,  
We are still unsure what is causing the bluetooth disconnection issues. Until then, would it be possible to add in a behavior that _stops_ the task when a Bluetooth firmata IO device disconnects; constantly attempts to reconnect (e.g. with exponential backoff); and if successfully reconnects, resumes the task from where it was?

It would be useful if these events threw warnings/errors messages on the client console, and if these events were loggable in the .mwk2 file.

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [March 2, 2020, 7:58pm UTC](https://mworks.discourse.group/t/auto-reconnect-ble-feature-request/198/2 "2020-03-02T19:58:21Z")

</div>

Hi Michael,

> Until then, would it be possible to add in a behavior that stops the task when a Bluetooth firmata IO device disconnects; constantly attempts to reconnect (e.g. with exponential backoff); and if successfully reconnects, resumes the task from where it was?

I’ve added two new parameters, [connected](https://mworks.github.io/documentation/latest/components/firmata_device.html#connected) and [reconnect\_interval](https://mworks.github.io/documentation/latest/components/firmata_device.html#connected), which enable this behavior.

`connected` should be set to the name of a variable. The variable will be set to true when the device is connected, false when it disconnects. By monitoring the value of the variable (e.g. at the beginning of each trial or via [attached actions](https://mworks.github.io/documentation/latest/guide/designing.html#variable-attached-actions)), your experiment can take appropriate action (e.g. [pause](https://mworks.github.io/documentation/latest/components/pause_experiment.html) or [resume](https://mworks.github.io/documentation/latest/components/resume_experiment.html) the experiment) when the connection state changes.

> It would be useful if these events threw warnings/errors messages on the client console, and if these events were loggable in the .mwk2 file.

The device does log messages upon disconnection and reconnection, and these messages (like all MWorks messages) will be saved in the event file. Also, the value of the `connected` variable (like all variables) will be stored in the event file.

I can update your iPad(s) whenever you like.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 19, 2022, 8:30pm UTC](https://mworks.discourse.group/t/auto-reconnect-ble-feature-request/198/3 "2022-07-19T20:30:09Z")

</div>


