CreaTe-M8-BME / CreaTeBME

Python Package for interfacing the bluetooth IMU module for CreaTe M8 BME.
GNU General Public License v3.0
0 stars 2 forks source link

Connection to one sensor fails when connecting to multiple sensors #13

Open ttsmit opened 1 year ago

ttsmit commented 1 year ago

When connecting to multiple sensors, setting up the connection to one sensor ultimately fails. For one sensor, the following message is shown, whereafter no packets from this sensor are printed any more.

Task exception was never retrieved
future: <Task finished name='Task-3' coro=<SensorManager._connect_sensors() done, defined at /home/tmp/.venv/lib/python3.10/site-packages/CreaTeBME-1.0.1-py3.10.egg/CreaTeBME/SensorManager.py:72> exception=BleakDBusError('org.bluez.Error.Failed', 'Operation failed with ATT error: 0x0e')>
Traceback (most recent call last):
  File "/home/tmp/.venv/lib/python3.10/site-packages/CreaTeBME-1.0.1-py3.10.egg/CreaTeBME/SensorManager.py", line 75, in _connect_sensors
    await self._set_sample_rate()
  File "/home/tmp/.venv/lib/python3.10/site-packages/CreaTeBME-1.0.1-py3.10.egg/CreaTeBME/SensorManager.py", line 100, in _set_sample_rate
    await sensor.set_sample_rate(self._sample_rate)
  File "/home/tmp/.venv/lib/python3.10/site-packages/CreaTeBME-1.0.1-py3.10.egg/CreaTeBME/ImuSensor.py", line 102, in set_sample_rate
    await self.__bt_client.write_gatt_char(
  File "/home/tmp/.venv/lib/python3.10/site-packages/bleak/__init__.py", line 659, in write_gatt_char
    await self._backend.write_gatt_char(char_specifier, data, response)
  File "/home/tmp/.venv/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 905, in write_gatt_char
    assert_reply(reply)
  File "/home/tmp/.venv/lib/python3.10/site-packages/bleak/backends/bluezdbus/utils.py", line 22, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.Failed] Operation failed with ATT error: 0x0e (Unlikely Error)

Testing a setup with 4 sensors shows that the sensor which establishes a connection first (this is not per se the first sensor in the sensor_names ) loses connection with the error above. Contrary, the sensor which established a connection last, seems to be receiving twice the amount of measurement packets. After running the script for an extensive amount of time, the four sensors received 1607, 63239, 66325 and 123804 packets.

As the error message suggests, seems to go wrong when setting the sample rate in ImuSensor line 108.

Issue seems to occur on both Linux and Windows, mac not tested. Issue also occurs on package version 1.0.0.

ttsmit commented 1 year ago

Removing line 108 still poses the same issue. Error changes to line 103.