Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error when calling set target resistance level #46

Open
nbazimi opened this issue Nov 13, 2024 · 5 comments
Open

error when calling set target resistance level #46

nbazimi opened this issue Nov 13, 2024 · 5 comments
Labels
question Further information is requested

Comments

@nbazimi
Copy link

nbazimi commented Nov 13, 2024

Hi
I have smart trainer Tacx Neo 3m.
this error occurs when calling fitness machin example: set target resistance level

Traceback (most recent call last)
File "C: \Users \Baran\Desktop \Arbeit\New folder \pycycling-masterlexamples\fitness machine service example.py", line 47, in
loop.run_until_complete(run(device_address))
File "C: \Users\Baran\AppData\LocallPrograms\Python\Python37\liblasyncio\base_events.py", line 579, in run_until_complete
return future.result()
File "C:\Users\Baran\Desktop\Arbeit\New folder\pycycling-master\examples\fitness machine_service example.py", line 25, in run
await ftms.set_target_resistance_Level(10)
File "C: \Users\Baran\Desktop\Arbeit\New folder\pycycling-master\pycyclinglfitness machine service.py", line 235, in set_target_resistance leve
ftms_fitness_machine_control_point_characteristic_id, message, True
File "C:\Users\Baran\Desktop\Arbeit\New folder\pycycling-master.venv\lib\site-packages\bleakl init _py", line 659, in write_gatt_char
await self._backend write_gatt_char(char_specifier, data, response)
File "C: \Users\Baran\Desktop \Arbeit\New folder\pycycling-masterl.venv\lib\site-packages\bleaklbackends\winrt\client.py", line 876, in write_ge
f"Could not write value (data) to characteristic (characteristic.handle:04X)",
File "C:\Users\Baran\Desktop\Arbeit\New folder\pycyclinq-master.venv\lib\site-packages\bleak\backends\winrt\client.pỵ", line 116, in _ensure.
f"(fail_msgł: Protocol Error 0xfresult.protocol_error:02X): ferr)"
bleak.exc.BleakError: Could not write value b'Ix04\n' to characteristic 004B: Protocol Error 0xFD: Client Characteristic Configuration Descriptc.
WhatsApp Bild 2024-11-13 um 19 24 12_fd2857bc

@zacharyedwardbull
Copy link
Owner

Hi, I'm afraid I'm not familiar with the FTMS implementation - perhaps @tensorturtle or @bytosaur may be able to help.

@zacharyedwardbull zacharyedwardbull added the question Further information is requested label Nov 16, 2024
@bytosaur
Copy link
Contributor

Hey @nbazimi,

Firstly, I havent tried the system on windows. Any chance to test it on linux or Mac? I tested this on RPi5 and MacM1.

Secondly, can you share the complete file you r running? It looks like you have modified the example.
The line you r referring in your code is 25 while in the original example it is 90.

Thirdy, please copy the whole error message. The message you sent looks like it is missing characters and doesnt make sense, e.g. the file pycyclinglfitness machine service.py does not exist in the repository.

@tensorturtle
Copy link
Contributor

Hi I'm monitoring this issue and will chime in if I see anything I can help with. Thanks @bytosaur for taking initiative to resolve this issue.

@nbazimi
Copy link
Author

nbazimi commented Nov 18, 2024

Hey @nbazimi,

Firstly, I havent tried the system on windows. Any chance to test it on linux or Mac? I tested this on RPi5 and MacM1.

Secondly, can you share the complete file you r running? It looks like you have modified the example. The line you r referring in your code is 25 while in the original example it is 90.

Thirdy, please copy the whole error message. The message you sent looks like it is missing characters and doesnt make sense, e.g. the file pycyclinglfitness machine service.py does not exist in the repository.

this is what i used:

import asyncio
from bleak import BleakClient
from pycycling.fitness_machine_service import FitnessMachineService

async def run(address):
async with BleakClient(address, timeout=10) as client:
ftms = FitnessMachineService(client)

    # Print 'read' characteristics

    ### Fitness Machine Features
    fitness_machine_features, target_setting_features = await ftms.get_fitness_machine_feature()
    fitness_machine_features = fitness_machine_features._asdict()
    target_setting_features = target_setting_features._asdict()


    supported_resistance_level_range = (
        await ftms.get_supported_resistance_level_range()
    )
    print("Supported resistance level range:")
    print(supported_resistance_level_range)
    print()
    max_resistance = supported_resistance_level_range.maximum_resistance
    print("Setting target resistance level to 25 percent of maximum resistance level...")
    await ftms.set_target_resistance_level(10)

    await asyncio.sleep(5)

    print("Increasing target resistance level to 50 percent of maximum resistance level...")
    await ftms.set_target_resistance_level(50)

    await asyncio.sleep(5)

    # Reset target resistance level
    print("Resetting target resistance level...")

    await ftms.reset()

if name == "main":
import os

os.environ["PYTHONASYNCIODEBUG"] = str(1)

device_address = "E1:11:03:A9:40:9C"
loop = asyncio.get_event_loop()
loop.run_until_complete(run(device_address))

# Unresolved intermittent bug when writing to the control point characteristic:
# bleak.exc.BleakDBusError: [org.bluez.Error.Failed] Operation failed with ATT error: 0x80 (Unknown code)
#
# To work around this, just retry on error, like:
#
# import bleak
# while True:
#     try:
#         loop.run_until_complete(run(device_address))
#     except bleak.exc.BleakDBusError as e:
#         print("BleakDBusError, retrying...")
#         print(e)
#         continue
#     except KeyboardInterrupt:
#         break

@tensorturtle
Copy link
Contributor

@nbazimi

First, could you first enable DEBUG level logging and then please copy and paste the error (as you did at the beginning).
https://bleak.readthedocs.io/en/latest/troubleshooting.html#enable-logging

Second, git clone and run this script that I wrote to check that the trainer supports the right operations on each characteristic. Please run the script, find the trainer, and copy the output and paste it here.
https://github.com/tensorturtle/bluetooth_dissect

Third, thank you for pasting the script you've used, but for now can we focus on running the provided example script? That would reduce the confusion.

I have used this FTMS implementation on Windows (not WSL) so it is expected to work, let's try to figure out why it isn't working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants