I have started to use a Raspberry Pi 4 with Python. The project I'm working on has led me to a published Python library on GitHub (keshavdv/victron-ble).
Having installed the library, I can successfully run from the CLI (discover, read, dump). However, trying to achieve the same through a Python script has left me head scratching.
CLI commands used:
victron-ble discover
victron-ble dump "b5:55:aa:4d:99:33"
victron-ble read "b5:55:aa:4d:99:33"@"eb8c557386614231dbd741db97e457c5"
This is the code that I have tried to use:
from victron_ble.cli import discover
from victron_ble.cli import dump
from victron_ble.cli import read
my_id = b'b5:55:aa:4d:99:33'
#where my_id is the MAC address of the device I wish to observe
my_key = 'eb8c557386614231dbd741db97e457c5'
#where my_key is the encypytion key of the device I wish to observe
dump_result = dump(my_key)
print(dump_result)
discover_result = discover()
print(discover_result)
Have tried the following format of the my_id variable in hope:
b'b5:55:aa:4d:99:33'
'b5:55:aa:4d:99:33'
'b555aa4d9933'
b'b5-55-aa-4d-99-33'
[b5:55:aa:4d:99:33]
One question would be, how would I replicate the CL instruction but with the script, in particular the format required for the MAC address and key. Thank you
If I run with the code/script that you have posted I get the following error:
This looks to me like the
clicklibrary is expecting to inject the value in to thedumpfunction with the decorators. https://github.com/keshavdv/victron-ble/blob/e28c5f8cc5f9f3062a2f36c2115d38214c07e741/victron_ble/cli.py#L45-L55I don't have any appropriate devices so I can't test this, but it would seem like the following should work: