corvis / prana_rc

Python library and CLI to control Prana recuperators via BLE connection (https://prana.org.ua/)
GNU General Public License v3.0
20 stars 6 forks source link

get attribute issues #22

Closed viy closed 3 years ago

viy commented 3 years ago

Hay, I have strange issue with prana-rc while getting state

curl \
  -X POST \
  -H "Accept: application/json" \
  http://192.168.1.32:8881/ \
  -d '{ "jsonrpc": "2.0", "id": 1, "method": "prana.get_state", "params": {"address": "00:A0:50:BD:51:DF"} }'
{"error": {"code": -32000, "message": "Server error", "data": {"type": "RuntimeError", "args": ["Connection to device 00:A0:50:BD:51:DF failed after 5 attempts"], "message": "Connection to device 00:A0:50:BD:51:DF failed after 5 attempts"}}, "id": 1, "jsonrpc": "2.0"}%    

But Btmot on the server actually returns

> ACL Data RX: Handle 71 flags 0x01 dlen 5                                                   #490 [hci0] 730.166342
      ATT: Handle Value Notification (0x1b) len 162
        Handle: 0x000e
          Data: beef0501000000005ac001c001c001c000c0000000c001c001c0140001401400014014000080000000c001000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000004c0ae7132a117ecdcf15f773ed90f679b5c648952ba9df5a9b69881855f2f13a27b5c0684c0d445e657c638ebad4b94583cf2f421af13e88af316d7f
< ACL Data TX: Handle 71 flags 0x00 dlen 16                                                  #491 [hci0] 730.214675
      ATT: Write Request (0x12) len 11
        Handle: 0x000e
          Data: beef0501000000005a
> HCI Event: Number of Completed Packets (0x13) plen 5                                       #492 [hci0] 730.262367
        Num handles: 1
        Handle: 71
        Count: 1

How can I get debug information from prana-rc server?

corvis commented 3 years ago

Try to add environment variable PRANA_LOGGING=true this should enable extensive logging (logs will be written into stdout).

viy commented 3 years ago

I found this

2021-03-29 02:04:59,751 sizzlews.jsonrpc.manager ERROR: API Exception: {'type': 'RemoteError', 'args': ('org.bluez.Error.Failed',), 'message': 'org.bluez.Error.Failed: Operation failed with ATT error: 0x0e'}
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/sizzlews/jsonrpc/manager.py", line 142, in _get_responses
    result = await result
  File "/home/pi/.local/lib/python3.7/site-packages/prana_rc/contrib/api/handler.py", line 89, in get_state
    state = await prana_device.read_state()
  File "/home/pi/.local/lib/python3.7/site-packages/prana_rc/service.py", line 322, in read_state
    state_bin = await self._send_command(self.Cmd.READ_STATE, expect_reply=True)
  File "/home/pi/.local/lib/python3.7/site-packages/prana_rc/service.py", line 209, in _send_command
    await self.__client.write_gatt_char(self.CONTROL_RW_CHARACTERISTIC_UUID, command, response=expect_reply)
  File "/home/pi/.local/lib/python3.7/site-packages/bleak/backends/bluezdbus/client.py", line 622, in write_gatt_char
    ).asFuture(asyncio.get_event_loop())
txdbus.error.RemoteError: org.bluez.Error.Failed: Operation failed with ATT error: 0x0e
viy commented 3 years ago

looks like it was an unstable connection issue (( so no worries