bgapi icon indicating copy to clipboard operation
bgapi copied to clipboard

How to request data from connected Server?

Open Gruftgrabbler opened this issue 1 year ago • 0 comments

Issue Summary

I am facing a problem with my BLE Client's data request to a BLE Server. The issue is related to the pybgapi library, and I need assistance in resolving it.

[I created another Issue at the pybgapi repository. I am not 100% sure if it goes there or here, if you think I am in the wrong spot let me know or delete the issue]

Here is the relevant code snippet:

if self.conn_state == "enable_indication":
    # ...
    self.lib.bt.gatt.read_characteristic_value(
        evt.connection, SENSOR_DATA_CHARACTERISTIC)

The SENSOR_DATA_CHARACTERISTIC variable is defined as:

#UUID = 34850bc9-95e5-4701-956c-656ce1afdc66
SENSOR_DATA_CHARACTERISTIC = b"\x66\xdc\xaf\xe1\x6c\x65\x6c\x95\x01\x47\xe5\x95\xc9\x0b\x85\x34"

I am encountering the following error:

File "/Users/username/Documents/GitHub/pybgapi-examples/lib/python3.11/site-packages/bgapi/apiparser.py", line 30, in toInt
    return int(s)
ValueError: invalid literal for int() with base 10: b'f\xdc\xaf\xe1lel\x95\x01G\xe5\x95\xc9\x0b\x854'

I also tried another variant where I casted the byte to an integer value, but I guess this was not a good idea neither.

    self.lib.bt.gatt.read_characteristic_value(
        evt.connection, int.from_bytes(SENSOR_DATA_CHARACTERISTIC, byteorder='little'))

Thank you for any advice in solving this issue and let me know if you need more information.

Gruftgrabbler avatar Nov 01 '23 13:11 Gruftgrabbler