50ButtonsEach / fliclib-linux-hci

Flic SDK for Linux
305 stars 55 forks source link

More than 5 connection CSR BC8510 #76

Closed dodepier closed 6 years ago

dodepier commented 6 years ago

More than 5 connection CSR BC8510

I have a question about the CSR BC8510. I did read that the chip does support 5 connections and 25 pending connection. What does that mean? I have now 6 flic buttons connected. However, one of the 6 buttons does lose its connection (glowing the red led when pressed). It seems that the disconnected button is random. Is it even possible to connect more than 5 buttons?

Thankyou

Emill commented 6 years ago

Hi. It's quite simple.

That chip has only support for 5 active connections at the same time. When the Bluetooth chip (central) is connected to the Flic, the central polls the Flic many times each second. The Flic must respond at least once per second or so, otherwise it is marked as being disconnected due to timeout. While being connected, you have low latency.

However, the flicd supports as many pending connections as there are space in the Bluetooth chip's white list. This means we can tell the Bluetooth chip to try to connect to these 25 devices. As soon as a Flic advertises (which it does for example when it is being clicked), the Bluetooth chip then connects to that device.

If, at any given time, the maximum number of connections is reached, the flicd won't initiate a new connection until another one disconnects. So, if you have 6 devices which you want to listen to for button events, you can still only have 5 working simultaneously. Your "random" Flic will be the one that is currently not connected.

To mitigate this we have a parameter called "auto disconnect timeout" you can set to for example 10 seconds, which means the Flic will disconnect automatically 10 seconds after inactivity. That should make the issue less of a problem, since you probably don't press all buttons you have at the same time anyway. Or just use a chip that has supports for more connections.

dodepier commented 6 years ago

Thanks a lot, sorry for the basic questions I’m quite new in this. It did select the CSR BC8510 for the good range of 100 meters and its price. So, before I will look for another controller I will first try to change the parameter. But how can I do that? I use systemd to start-up the application.

The service file:

[Unit]
Description=flicd Service
After=bluetooth.service
Requires=bluetooth.service
Before=home-assistant@homeassistant.service

[Service]
TimeoutStartSec=0
ExecStart=/usr/local/bin/flicd -f flic.sqlite3 -s 0.0.0.0 -h hci0 -w
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target
Emill commented 6 years ago

Hi. It's not done as a global setting, but is configured each time you create a connection channel (https://github.com/50ButtonsEach/fliclib-linux-hci/blob/master/ProtocolDocumentation.md#cmdcreateconnectionchannel). There you see the auto_disconnect_time parameter. See the documentation for each clientlib depending on which programming language you are using.

dodepier commented 6 years ago

Okay thanks again. I hope that I’m almost there. I use the homebridge plugin to connect my buttons to homekit:

https://www.npmjs.com/package/homebridge-flic

Should I change the parameter in the configuration file of homebridge like this?

"platforms": [
   {
       "platform": "Flic",
       "name": "Flic",
       "controllers": [
           {"host": "localhost", "port": 5551, "auto_disconnect_time": 10}
       ]
   }
]
dodepier commented 6 years ago

I did also post the question on the homebridge flic plugin page:

https://github.com/devbobo/homebridge-flic/issues/11