crownstone / crownstone-lib-python-uart

Library to communicate with the Crownstone network via the Crownstone USB dongle
Apache License 2.0
0 stars 4 forks source link

Unable to use the Python UART lib with Crownstone firmware version 5.3.0 #5

Closed RicArch97 closed 4 years ago

RicArch97 commented 4 years ago

All Crownstones + Crownstone USB were updated to 5.3.0. Using the latest commits from crownstone-lib-python-uart and crownstone-lib-python-core.

Logs:

2020-10-12 17:49:11 DEBUG (Thread-5) [crownstone_uart.core.uart.UartManager] Initializing... None 230400
2020-10-12 17:49:11 DEBUG (Thread-5) [crownstone_uart.core.uart.UartManager] Setting up connection.../dev/ttyUSB0 230400 True
2020-10-12 17:49:11 DEBUG (Thread-8) [crownstone_uart.core.uart.UartBridge] UartBridge: Initializing serial on port /dev/ttyUSB0 with baudrate 230400
2020-10-12 17:49:11 DEBUG (Thread-8) [crownstone_uart.core.uart.UartBridge] Read starting on serial port./dev/ttyUSB0 True
2020-10-12 17:49:11 DEBUG (Thread-5) [crownstone_uart.core.uart.UartManager] Handshake successful
2020-10-12 17:49:11 INFO (Thread-5) [crownstone_uart.core.uart.UartManager] Connection established to /dev/ttyUSB0
2020-10-12 17:49:16 WARNING (Thread-8) [crownstone_uart.core.uart.UartParser] Unknown OpCode 40110
2020-10-12 17:49:22 WARNING (Thread-8) [crownstone_uart.core.uart.UartParser] Unknown OpCode 40110
2020-10-12 17:49:23 WARNING (Thread-8) [crownstone_uart.core.uart.UartParser] Unknown OpCode 40110
2020-10-12 17:49:26 WARNING (Thread-8) [crownstone_uart.core.uart.UartParser] Unknown OpCode 40110
2020-10-12 17:49:29 WARNING (Thread-8) [crownstone_uart.core.uart.UartParser] Unknown OpCode 40110
2020-10-12 17:49:40 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.139915271798016] 'MeshHandler' object has no attribute 'deviceId'
Traceback (most recent call last):
  File "/media/DATA/Stage/stage/core/homeassistant/components/websocket_api/commands.py", line 138, in handle_call_service
    await hass.services.async_call(
  File "/media/DATA/Stage/stage/core/homeassistant/core.py", line 1335, in async_call
    task.result()
  File "/media/DATA/Stage/stage/core/homeassistant/core.py", line 1370, in _execute_service
    await handler.func(service_call)
  File "/media/DATA/Stage/stage/core/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/media/DATA/Stage/stage/core/homeassistant/helpers/service.py", line 470, in entity_service_call
    future.result()  # pop exception if have
  File "/media/DATA/Stage/stage/core/homeassistant/helpers/entity.py", line 655, in async_request_call
    await coro
  File "/media/DATA/Stage/stage/core/homeassistant/helpers/service.py", line 507, in _handle_entity_call
    await result
  File "/media/DATA/Stage/stage/core/homeassistant/components/light/__init__.py", line 249, in async_handle_light_on_service
    await light.async_turn_on(**params)
  File "/media/DATA/Stage/stage/core/homeassistant/components/crownstone/light.py", line 146, in async_turn_on
    self.uart.switch_crownstone(self.unique_id, on=True)
  File "/media/DATA/Stage/stage/core/venv/lib/python3.8/site-packages/crownstone_uart-0.7.7-py3.8.egg/crownstone_uart/core/CrownstoneUart.py", line 102, in switch_crownstone
    self.mesh.turn_crownstone_on(crownstoneId)
  File "/media/DATA/Stage/stage/core/venv/lib/python3.8/site-packages/crownstone_uart-0.7.7-py3.8.egg/crownstone_uart/core/modules/MeshHandler.py", line 29, in turn_crownstone_on
    self._switch_crownstone(crownstone_id, 255)
  File "/media/DATA/Stage/stage/core/venv/lib/python3.8/site-packages/crownstone_uart-0.7.7-py3.8.egg/crownstone_uart/core/modules/MeshHandler.py", line 66, in _switch_crownstone
    uartMessage = UartMessagePacket(self.deviceId, UartTxType.CONTROL, controlPacket).getPacket()
AttributeError: 'MeshHandler' object has no attribute 'deviceId'
2020-10-12 17:49:44 WARNING (Thread-8) [crownstone_uart.core.uart.UartParser] Unknown OpCode 40110
2020-10-12 17:49:45 WARNING (Thread-8) [crownstone_uart.core.uart.UartParser] Unknown OpCode 40110
2020-10-12 17:49:48 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.139915271798016] 'MeshHandler' object has no attribute 'deviceId'
Traceback (most recent call last):
  File "/media/DATA/Stage/stage/core/homeassistant/components/websocket_api/commands.py", line 138, in handle_call_service
    await hass.services.async_call(
  File "/media/DATA/Stage/stage/core/homeassistant/core.py", line 1335, in async_call
    task.result()
  File "/media/DATA/Stage/stage/core/homeassistant/core.py", line 1370, in _execute_service
    await handler.func(service_call)
  File "/media/DATA/Stage/stage/core/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/media/DATA/Stage/stage/core/homeassistant/helpers/service.py", line 470, in entity_service_call
    future.result()  # pop exception if have
  File "/media/DATA/Stage/stage/core/homeassistant/helpers/entity.py", line 655, in async_request_call
    await coro
  File "/media/DATA/Stage/stage/core/homeassistant/helpers/service.py", line 507, in _handle_entity_call
    await result
  File "/media/DATA/Stage/stage/core/homeassistant/components/crownstone/light.py", line 160, in async_turn_off
    self.uart.switch_crownstone(self.unique_id, on=False)
  File "/media/DATA/Stage/stage/core/venv/lib/python3.8/site-packages/crownstone_uart-0.7.7-py3.8.egg/crownstone_uart/core/CrownstoneUart.py", line 100, in switch_crownstone
    self.mesh.turn_crownstone_off(crownstoneId)
  File "/media/DATA/Stage/stage/core/venv/lib/python3.8/site-packages/crownstone_uart-0.7.7-py3.8.egg/crownstone_uart/core/modules/MeshHandler.py", line 33, in turn_crownstone_off
    self._switch_crownstone(crownstone_id, 0)
  File "/media/DATA/Stage/stage/core/venv/lib/python3.8/site-packages/crownstone_uart-0.7.7-py3.8.egg/crownstone_uart/core/modules/MeshHandler.py", line 66, in _switch_crownstone
    uartMessage = UartMessagePacket(self.deviceId, UartTxType.CONTROL, controlPacket).getPacket()
AttributeError: 'MeshHandler' object has no attribute 'deviceId'
2020-10-12 17:49:49 WARNING (Thread-8) [crownstone_uart.core.uart.UartParser] Unknown OpCode 40110

The exceptions occurred when trying to switch a Crownstone on/off.

mrquincle commented 4 years ago

Seems to be opcode 40110 (mesh profile location) on https://github.com/crownstone/bluenet/blob/master/docs/UART_PROTOCOL.md.

mrquincle commented 4 years ago

Ah error is probably unrelated to that.

RicArch97 commented 4 years ago

Found the issue for the exception:

crownstone_uart/core/modules/MeshHandler.py", line 66, in _switch_crownstone

Change

uartMessage = UartMessagePacket(self.deviceId, UartTxType.CONTROL, controlPacket).getPacket()

To

uartMessage = UartMessagePacket(self.libState.deviceId, UartTxType.CONTROL, controlPacket).getPacket()

Tested this change by switching a Crownstone, the Crownstone now switches successfully and the exception does not occur anymore. I'm not sure about the Unknown OpCode 40110 warning, that one still remains.

vliedel commented 4 years ago

Thanks! Pushed the fix.