mrk-its / can2mqtt

Apache License 2.0
42 stars 5 forks source link

Script stops with error #6

Closed max-fx closed 1 year ago

max-fx commented 1 year ago

Hi Mariusz, I've been trying to get the script to work for a while, but I can't find the error. Please take a look.

esphome config:

canopen:
  id: can_gate
  canbus_id: can_bus
  node_id: 2
  entities:

  - id: light_1
    index: 1
    tpdo: 0
~/can2mqtt_available_state$ venv/bin/can2mqtt -l DEBUG
2023-05-22 20:02:01 Master asyncio            DEBUG Using selector: EpollSelector
2023-05-22 20:02:01 Master can                DEBUG can config: {'bitrate': 500000, 'interface': 'socketcan', 'channel': 'can0', 'mqtt_server': '192.168.xx.xx'}
2023-05-22 20:02:01 Master can.interfaces.socketcan.socketcan INFO Created a socket
2023-05-22 20:02:01 Master can.interfaces.socketcan.socketcan DEBUG Binding socket to channel=can0
2023-05-22 20:02:01 Master can.interfaces.socketcan.socketcan DEBUG Bound socket.
2023-05-22 20:02:01 Master canopen.network    INFO Connected to 'socketcan channel 'can0''
2023-05-22 20:02:03 Master canopen.pdo        DEBUG TPDO Map as 8
2023-05-22 20:02:03 Master canopen.pdo        DEBUG RPDO Map as 0
2023-05-22 20:02:03 Master canopen.sdo.client DEBUG Reading 0x1008:0 from node 2
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 08 10 00 00 00 00 00
2023-05-22 20:02:03 Master canopen.sdo.client DEBUG Using segmented transfer of 7 bytes
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    60 00 00 00 00 00 00 00
2023-05-22 20:02:03 Master canopen.variable   DEBUG Value of DeviceName (0x1008:0) is 'ESPHome'
2023-05-22 20:02:03 Master canopen.sdo.client DEBUG Reading 0x1017:0 from node 2
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 17 10 00 00 00 00 00
2023-05-22 20:02:03 Master canopen.variable   DEBUG Value of ProducerHeartbeatTime (0x1017:0) is 10240
2023-05-22 20:02:03 Master can2mqtt.entities  INFO node_id: 2 device name: ESPHome, heartbeat time (ms): 10240
2023-05-22 20:02:03 Master canopen.sdo.client DEBUG Reading 0x2000:0 from node 2
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 00 20 00 00 00 00 00
2023-05-22 20:02:03 Master canopen.variable   DEBUG Value of EntityTypes.Number of entries (0x2000:0) is 1
2023-05-22 20:02:03 Master can2mqtt.entities  DEBUG trying to read 1
2023-05-22 20:02:03 Master canopen.sdo.client DEBUG Reading 0x2000:1 from node 2
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 00 20 01 00 00 00 00
2023-05-22 20:02:03 Master canopen.variable   DEBUG Value of EntityTypes.EntityTypes (0x2000:1) is 3
2023-05-22 20:02:03 Master can2mqtt.entities  DEBUG val: 3
2023-05-22 20:02:03 Master can2mqtt.entities  INFO   entity: Switch(node_id=2, entity_index=1, props={})
2023-05-22 20:02:03 Master can2mqtt.entities  DEBUG setup state topics for Switch(node=2, entity_index=1), [537985280]
2023-05-22 20:02:03 Master can2mqtt.entities  DEBUG trying to read 1
2023-05-22 20:02:03 Master canopen.sdo.client DEBUG Reading 0x2010:1 from node 2
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 10 20 01 00 00 00 00
2023-05-22 20:02:03 Master canopen.sdo.client DEBUG Using segmented transfer of 7 bytes
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    60 00 00 00 00 00 00 00
2023-05-22 20:02:03 Master canopen.variable   DEBUG Value of Entity01_Metadata.Entity01_Name (0x2010:1) is 'Licht 1'
2023-05-22 20:02:03 Master can2mqtt.entities  DEBUG val: Licht 1
2023-05-22 20:02:03 Master can2mqtt.entities  DEBUG     name 1: Licht 1
2023-05-22 20:02:03 Master can2mqtt.entities  DEBUG trying to read 2
2023-05-22 20:02:03 Master canopen.sdo.client DEBUG Reading 0x2010:2 from node 2
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 10 20 02 00 00 00 00
2023-05-22 20:02:03 Master can2mqtt.entities  DEBUG subindex not found
2023-05-22 20:02:03 Master can2mqtt.entities  DEBUG trying to read 3
2023-05-22 20:02:03 Master canopen.sdo.client DEBUG Reading 0x2010:3 from node 2
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 10 20 03 00 00 00 00
2023-05-22 20:02:03 Master can2mqtt.entities  DEBUG subindex not found
2023-05-22 20:02:03 Master can2mqtt.entities  DEBUG trying to read 4
2023-05-22 20:02:03 Master canopen.sdo.client DEBUG Reading 0x2010:4 from node 2
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 10 20 04 00 00 00 00
2023-05-22 20:02:03 Master can2mqtt.entities  DEBUG subindex not found
2023-05-22 20:02:03 Master can2mqtt.entities  DEBUG mqtt config_topic: 'homeassistant/switch/can_002_01/config', payload: {'object_id': 'can_002_01', 'entity_id': 'can_002_01', 'unique_id': 'can_002_01', 'availability': [{'topic': 'homeassistant/can_002/availability'}, {'topic': 'homeassistant/can2mqtt/status'}], 'availability_mode': 'all', 'assumed_state': False, 'name': 'Licht 1', 'command_topic': 'homeassistant/can_cmd_002_20120100', 'state_topic': 'homeassistant/can_state_002_20110100'}
2023-05-22 20:02:03 Master can2mqtt.entities  DEBUG reading tpdo config
2023-05-22 20:02:03 Master canopen.sdo.client DEBUG Reading 0x1800:1 from node 2
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 00 18 01 00 00 00 00
2023-05-22 20:02:03 Master can2mqtt.entities  DEBUG recv mqtt topic: homeassistant/switch/can_002_01/config payload len: 373
2023-05-22 20:02:03 Master canopen.variable   DEBUG Value of Transmit PDO 0 communication parameters.COB-ID use by TPDO 0 (0x1800:1) is 1073742210
2023-05-22 20:02:03 Master canopen.sdo.client DEBUG Reading 0x1800:2 from node 2
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 00 18 02 00 00 00 00
2023-05-22 20:02:03 Master canopen.variable   DEBUG Value of Transmit PDO 0 communication parameters.Transmission type TPDO 0 (0x1800:2) is 254
2023-05-22 20:02:03 Master canopen.sdo.client DEBUG Reading 0x1A00:0 from node 2
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 00 1a 00 00 00 00 00
2023-05-22 20:02:03 Master canopen.variable   DEBUG Value of TPDO0 mapping parameter.Number of mapped objects TPDO0 (0x1A00:0) is 1
2023-05-22 20:02:03 Master canopen.sdo.client DEBUG Reading 0x1A00:1 from node 2
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 00 1a 01 00 00 00 00
2023-05-22 20:02:03 Master canopen.variable   DEBUG Value of TPDO0 mapping parameter.TPDO0 mapping information 1 (0x1A00:1) is 537985288
2023-05-22 20:02:03 Master canopen.sdo.client DEBUG Reading 0x1801:1 from node 2
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 01 18 01 00 00 00 00
2023-05-22 20:02:03 Master canopen.variable   DEBUG Value of Transmit PDO 0 communication parameters.COB-ID use by TPDO 1 (0x1801:1) is 1073742466
2023-05-22 20:02:03 Master canopen.sdo.client DEBUG Reading 0x1801:2 from node 2
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 01 18 02 00 00 00 00
2023-05-22 20:02:03 Master canopen.variable   DEBUG Value of Transmit PDO 0 communication parameters.Transmission type TPDO 1 (0x1801:2) is 254
2023-05-22 20:02:03 Master canopen.sdo.client DEBUG Reading 0x1A01:0 from node 2
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:03 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 01 1a 00 00 00 00 00
2023-05-22 20:02:04 Master canopen.variable   DEBUG Value of TPDO1 mapping parameter.Number of mapped objects TPDO1 (0x1A01:0) is 0
2023-05-22 20:02:04 Master canopen.sdo.client DEBUG Reading 0x1802:1 from node 2
2023-05-22 20:02:04 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:04 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 02 18 01 00 00 00 00
2023-05-22 20:02:04 Master canopen.variable   DEBUG Value of Transmit PDO 0 communication parameters.COB-ID use by TPDO 2 (0x1802:1) is 1073742722
2023-05-22 20:02:04 Master canopen.sdo.client DEBUG Reading 0x1802:2 from node 2
2023-05-22 20:02:04 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:04 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 02 18 02 00 00 00 00
2023-05-22 20:02:04 Master canopen.variable   DEBUG Value of Transmit PDO 0 communication parameters.Transmission type TPDO 2 (0x1802:2) is 254
2023-05-22 20:02:04 Master canopen.sdo.client DEBUG Reading 0x1A02:0 from node 2
2023-05-22 20:02:04 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:04 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 02 1a 00 00 00 00 00
2023-05-22 20:02:04 Master canopen.variable   DEBUG Value of TPDO2 mapping parameter.Number of mapped objects TPDO2 (0x1A02:0) is 0
2023-05-22 20:02:04 Master canopen.sdo.client DEBUG Reading 0x1803:1 from node 2
2023-05-22 20:02:04 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:04 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 03 18 01 00 00 00 00
2023-05-22 20:02:04 Master canopen.variable   DEBUG Value of Transmit PDO 0 communication parameters.COB-ID use by TPDO 3 (0x1803:1) is 1073742978
2023-05-22 20:02:04 Master canopen.sdo.client DEBUG Reading 0x1803:2 from node 2
2023-05-22 20:02:04 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:04 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 03 18 02 00 00 00 00
2023-05-22 20:02:04 Master canopen.variable   DEBUG Value of Transmit PDO 0 communication parameters.Transmission type TPDO 3 (0x1803:2) is 254
2023-05-22 20:02:04 Master canopen.sdo.client DEBUG Reading 0x1A03:0 from node 2
2023-05-22 20:02:04 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:04 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 03 1a 00 00 00 00 00
2023-05-22 20:02:04 Master canopen.variable   DEBUG Value of TPDO3 mapping parameter.Number of mapped objects TPDO3 (0x1A03:0) is 0
2023-05-22 20:02:04 Master canopen.sdo.client DEBUG Reading 0x1804:1 from node 2
2023-05-22 20:02:04 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-22 20:02:04 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 04 18 01 00 00 00 00
2023-05-22 20:02:04 Master can2mqtt.entities  DEBUG recv mqtt topic: homeassistant/can2mqtt/status b'offline'
Traceback (most recent call last):
  File "/home/firemax/can2mqtt_available_state/venv/bin/can2mqtt", line 8, in <module>
    sys.exit(main())
  File "/home/firemax/can2mqtt_available_state/venv/lib/python3.10/site-packages/main.py", line 35, in main
    asyncio.run(can2mqtt.start(**vars(args)))
  File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/firemax/can2mqtt_available_state/venv/lib/python3.10/site-packages/can2mqtt/can2mqtt.py", line 243, in start
    await asyncio.gather(
  File "/home/firemax/can2mqtt_available_state/venv/lib/python3.10/site-packages/can2mqtt/can2mqtt.py", line 158, in can_reader
    await node.tpdo.aread()
  File "/home/firemax/can2mqtt_available_state/venv/lib/python3.10/site-packages/canopen/pdo/base.py", line 67, in aread
    await pdo_map.aread(from_od=from_od)
  File "/home/firemax/can2mqtt_available_state/venv/lib/python3.10/site-packages/canopen/pdo/base.py", line 430, in aread
    value = await var.aget_raw()
  File "/home/firemax/can2mqtt_available_state/venv/lib/python3.10/site-packages/canopen/variable.py", line 91, in aget_raw
    return self._get_raw(await self.aget_data())
  File "/home/firemax/can2mqtt_available_state/venv/lib/python3.10/site-packages/canopen/sdo/base.py", line 162, in aget_data
    return await self.sdo_node.aupload(self.od.index, self.od.subindex)
  File "/home/firemax/can2mqtt_available_state/venv/lib/python3.10/site-packages/canopen/sdo/client.py", line 219, in aupload
    async with await self.aopen(index, subindex, buffering=0) as fp:
  File "/home/firemax/can2mqtt_available_state/venv/lib/python3.10/site-packages/canopen/sdo/client.py", line 402, in aopen
    raw_stream = await AReadableStream.open(self, index, subindex)
  File "/home/firemax/can2mqtt_available_state/venv/lib/python3.10/site-packages/canopen/sdo/client.py", line 550, in open
    response = await sdo_client.arequest_response(request)
  File "/home/firemax/can2mqtt_available_state/venv/lib/python3.10/site-packages/canopen/sdo/client.py", line 151, in arequest_response
    return await self.aread_response()
  File "/home/firemax/can2mqtt_available_state/venv/lib/python3.10/site-packages/canopen/sdo/client.py", line 122, in aread_response
    raise SdoAbortedError(abort_code)
canopen.sdo.exceptions.SdoAbortedError: Code 0x06020000, Object does not exist
2023-05-22 20:02:04 Master can.bus            WARNING SocketcanBus was not properly shut down
2023-05-22 20:02:04 Master can.interfaces.socketcan.socketcan DEBUG Closing raw can socket
mrk-its commented 1 year ago

esphome-canopen and can2mqtt were out of sync for a while, I've just merged changes from dev to main in both repositories. Please reflash your esp node with latest version from main branch and run latest can2mqtt.

max-fx commented 1 year ago

result after updating to the latest version

$ venv/bin/can2mqtt -l DEBUG
2023-05-23 21:42:33 Master asyncio            DEBUG Using selector: EpollSelector
2023-05-23 21:42:33 Master can                DEBUG can config: {'bitrate': 500000, 'interface': 'socketcan', 'channel': 'can0', 'mqtt_server': '192.168.10.11'}
2023-05-23 21:42:33 Master can.interfaces.socketcan.socketcan INFO Created a socket
2023-05-23 21:42:33 Master can.interfaces.socketcan.socketcan DEBUG Binding socket to channel=can0
2023-05-23 21:42:33 Master can.interfaces.socketcan.socketcan DEBUG Bound socket.
2023-05-23 21:42:33 Master canopen.network    INFO Connected to 'socketcan channel 'can0''
2023-05-23 21:42:33 Master can2mqtt.entities  DEBUG recv mqtt topic: homeassistant/can2mqtt/status b'offline'
2023-05-23 21:42:38 Master canopen.pdo        DEBUG TPDO Map as 8
2023-05-23 21:42:38 Master canopen.pdo        DEBUG RPDO Map as 8
2023-05-23 21:42:38 Master canopen.sdo.client DEBUG Reading 0x1018:1 from node 2
2023-05-23 21:42:38 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-23 21:42:38 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 18 10 01 00 00 00 00
2023-05-23 21:42:38 Master canopen.variable   DEBUG Value of Identity.VendorId (0x1018:1) is 2778335477
2023-05-23 21:42:38 Master canopen.sdo.client DEBUG Reading 0x1018:2 from node 2
2023-05-23 21:42:38 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-23 21:42:38 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 18 10 02 00 00 00 00
2023-05-23 21:42:38 Master canopen.variable   DEBUG Value of Identity.ProductCode (0x1018:2) is 1809818073
2023-05-23 21:42:38 Master canopen.sdo.client DEBUG Reading 0x1008:0 from node 2
2023-05-23 21:42:38 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-23 21:42:38 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 08 10 00 00 00 00 00
2023-05-23 21:42:38 Master canopen.sdo.client DEBUG Using segmented transfer of 10 bytes
2023-05-23 21:42:38 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-23 21:42:38 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    60 00 00 00 00 00 00 00
2023-05-23 21:42:38 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-23 21:42:38 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    70 00 00 00 00 00 00 00
2023-05-23 21:42:38 Master canopen.variable   DEBUG Value of DeviceName (0x1008:0) is 'can-node-2'
2023-05-23 21:42:38 Master canopen.sdo.client DEBUG Reading 0x1009:0 from node 2
2023-05-23 21:42:38 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-23 21:42:38 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 09 10 00 00 00 00 00
2023-05-23 21:42:38 Master can2mqtt.entities  DEBUG recv mqtt topic: homeassistant/can2mqtt/status b'offline'
Traceback (most recent call last):
  File "/home/firemax/can2mqtt_canbus_1/venv/bin/can2mqtt", line 8, in <module>
    sys.exit(main())
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/main.py", line 35, in main
    asyncio.run(can2mqtt.start(**vars(args)))
  File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/can2mqtt/can2mqtt.py", line 295, in start
    await asyncio.gather(
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/can2mqtt/can2mqtt.py", line 151, in can_reader
    node.hw_version = await node.sdo["HardwareVersion"].aget_raw()
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/canopen/variable.py", line 91, in aget_raw
    return self._get_raw(await self.aget_data())
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/canopen/sdo/base.py", line 162, in aget_data
    return await self.sdo_node.aupload(self.od.index, self.od.subindex)
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/canopen/sdo/client.py", line 219, in aupload
    async with await self.aopen(index, subindex, buffering=0) as fp:
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/canopen/sdo/client.py", line 402, in aopen
    raw_stream = await AReadableStream.open(self, index, subindex)
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/canopen/sdo/client.py", line 550, in open
    response = await sdo_client.arequest_response(request)
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/canopen/sdo/client.py", line 151, in arequest_response
    return await self.aread_response()
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/canopen/sdo/client.py", line 122, in aread_response
    raise SdoAbortedError(abort_code)
canopen.sdo.exceptions.SdoAbortedError: Code 0x06020000, Object does not exist
2023-05-23 21:42:38 Master can.bus            WARNING SocketcanBus was not properly shut down
2023-05-23 21:42:38 Master can.interfaces.socketcan.socketcan DEBUG Closing raw can socket
mrk-its commented 1 year ago

Ok, I see what happened. Please try to add to your ESP config:

canopen:
  ...
  sw_version: 0.0.1
  hw_version: 0.0.1
mrk-its commented 1 year ago

It should be fixed on can2mqtt main branch

max-fx commented 1 year ago

First of all, I would like to give a big compliment for your work. It's great to see how the project is developing.

There still seems to be a bug in the script. If the esphome notes are started first, the script will run. If the script is started first and then the esphome notes, the script stops with an error.

When the HA server is restarted, the available status is not updated.

What does the configuration look like for transmit 4 switches, 4 temperatures and uptime

mrk-its commented 1 year ago

@max-fx Thanks for all your feedback! Can you provide eample yaml files and instruction how to reproduce these errors?

max-fx commented 1 year ago

Test procedure:

  1. Start can2mqtt
  2. Power on ESP32
venv/bin/can2mqtt -l DEBUG
2023-05-26 15:30:22 Master asyncio            DEBUG Using selector: EpollSelector
2023-05-26 15:30:22 Master can                DEBUG can config: {'bitrate': 500000, 'interface': 'socketcan', 'channel': 'can0', 'mqtt_server': '192.168.10.11'}
2023-05-26 15:30:22 Master can.interfaces.socketcan.socketcan INFO Created a socket
2023-05-26 15:30:22 Master can.interfaces.socketcan.socketcan DEBUG Binding socket to channel=can0
2023-05-26 15:30:22 Master can.interfaces.socketcan.socketcan DEBUG Bound socket.
2023-05-26 15:30:22 Master canopen.network    INFO Connected to 'socketcan channel 'can0''
2023-05-26 15:30:22 Master can2mqtt.entities  DEBUG recv mqtt topic: homeassistant/can2mqtt/status b'offline'
2023-05-26 15:30:34 Master canopen.pdo        DEBUG TPDO Map as 8
2023-05-26 15:30:34 Master canopen.pdo        DEBUG RPDO Map as 8
2023-05-26 15:30:34 Master canopen.sdo.client DEBUG Reading 0x1018:1 from node 2
2023-05-26 15:30:34 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-26 15:30:34 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 18 10 01 00 00 00 00
2023-05-26 15:30:34 Master canopen.sdo.client WARNING No SDO response received
2023-05-26 15:30:34 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-26 15:30:34 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 18 10 01 00 00 00 00
2023-05-26 15:30:35 Master canopen.sdo.client WARNING No SDO response received
2023-05-26 15:30:35 Master can.interfaces.socketcan.socketcan DEBUG We've been asked to write a message to the bus
2023-05-26 15:30:35 Master can.interfaces.socketcan.socketcan.tx DEBUG sending: Timestamp:        0.000000        ID: 0602    S Rx                DL:  8    40 18 10 01 00 00 00 00
2023-05-26 15:30:35 Master can2mqtt.entities  DEBUG recv mqtt topic: homeassistant/can2mqtt/status b'offline'
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/queues.py", line 159, in get
    await getter
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 456, in wait_for
    return fut.result()
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/canopen/sdo/client.py", line 115, in aread_response
    response = await asyncio.wait_for(
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 458, in wait_for
    raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/canopen/sdo/client.py", line 151, in arequest_response
    return await self.aread_response()
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/canopen/sdo/client.py", line 118, in aread_response
    raise SdoCommunicationError("No SDO response received")
canopen.sdo.exceptions.SdoCommunicationError: No SDO response received

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/firemax/can2mqtt_canbus_1/venv/bin/can2mqtt", line 8, in <module>
    sys.exit(main())
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/main.py", line 35, in main
    asyncio.run(can2mqtt.start(**vars(args)))
  File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/can2mqtt/can2mqtt.py", line 307, in start
    await asyncio.gather(
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/can2mqtt/can2mqtt.py", line 139, in can_reader
    vendor_id = await node.sdo["Identity"]["VendorId"].aget_raw()
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/canopen/variable.py", line 91, in aget_raw
    return self._get_raw(await self.aget_data())
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/canopen/sdo/base.py", line 162, in aget_data
    return await self.sdo_node.aupload(self.od.index, self.od.subindex)
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/canopen/sdo/client.py", line 219, in aupload
    async with await self.aopen(index, subindex, buffering=0) as fp:
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/canopen/sdo/client.py", line 402, in aopen
    raw_stream = await AReadableStream.open(self, index, subindex)
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/canopen/sdo/client.py", line 550, in open
    response = await sdo_client.arequest_response(request)
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/canopen/sdo/client.py", line 155, in arequest_response
    self.abort(0x5040000)
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/canopen/sdo/client.py", line 165, in abort
    self.send_request(request)
  File "/home/firemax/can2mqtt_canbus_1/venv/lib/python3.10/site-packages/canopen/async_guard.py", line 29, in async_guard
    raise RuntimeError("Calling a blocking function while running async")
RuntimeError: Calling a blocking function while running async
2023-05-26 15:30:35 Master can.bus            WARNING SocketcanBus was not properly shut down
2023-05-26 15:30:35 Master can.interfaces.socketcan.socketcan DEBUG Closing raw can socket

esphome config:

canbus:
  - platform: esp32_can
    id: can_bus
    rx_pin: 16
    tx_pin: 17
    can_id: 0
    bit_rate: 500kbps

canopen:
  sw_version: 0.0.1
  hw_version: 0.0.1
  id: can_gate
  canbus_id: can_bus
  node_id: 2
  entities:

  - id: light_1
    index: 1
    tpdo: 0

  - id: esprestart
    index: 4
    tpdo: 1

  - id: temperature_1
    index: 5
    tpdo: 2

  - id: humidity_1
    index: 6
    tpdo: 3

  - id: esptemp
    index: 3
    tpdo: 1

  - id: uptime_sensor
    index: 2
    tpdo: 0
mrk-its commented 1 year ago

You are great tester :) I was able to reproduce it on my end.

If you need quick fix please apply this hack:

diff --git a/src/can2mqtt/can2mqtt.py b/src/can2mqtt/can2mqtt.py
index b75e6a4..581c68f 100644
--- a/src/can2mqtt/can2mqtt.py
+++ b/src/can2mqtt/can2mqtt.py
@@ -135,6 +135,8 @@ async def can_reader(can_network, mqtt_client, mqtt_topic_prefix):
                 node.device_name = None
                 node.ntm_state_entity = None

+                await asyncio.sleep(2.0)
+
                 try:
                     vendor_id = await node.sdo["Identity"]["VendorId"].aget_raw()
                     product_code = await node.sdo["Identity"]["ProductCode"].aget_raw()

It waits a bit when new node appears, to make sure it is ready. I'll work on proper fix.