Closed max-fx closed 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.
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
Ok, I see what happened. Please try to add to your ESP config:
canopen:
...
sw_version: 0.0.1
hw_version: 0.0.1
It should be fixed on can2mqtt
main branch
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
@max-fx Thanks for all your feedback! Can you provide eample yaml files and instruction how to reproduce these errors?
Test procedure:
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
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.
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: