Socketcan interface naming scheme

Hi all, I’m writing a utility to grab some battery diagnostics over CAN.

It appears that, depending on the model of GX device or firmware version, the SocketCAN name for the BMS port is ‘vecan1’ or ‘can1’ - any thoughts on how to pin that down programmatically rather than modifying each deployment?

I am currently dumping the output of an exec node running ‘canshow’ but that seems a bit ugly…

Yes, you can list the devices via the shell, you should be able to filter out the second field name easily enough:

root@am62xx:~# ip link show type can
3: vecan0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 100
    link/can 
4: vecan1: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 100
    link/can
root@am62xx:~# ip -o link show type can | awk -F ': ' '{print $2}'
vecan0
vecan1

Hi @Dean_Commodore ,

I have the same issue. So I added logic to Node-Red to verify the CAN interface name

[
    {
        "id": "493f26a77a9ec46e",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "e5170a78393e72b2",
        "type": "inject",
        "z": "493f26a77a9ec46e",
        "name": "Auto-detect on deploy",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 165,
        "y": 100,
        "wires": [
            [
                "1fe6451b90b09f47"
            ]
        ]
    },
    {
        "id": "1fe6451b90b09f47",
        "type": "exec",
        "z": "493f26a77a9ec46e",
        "command": "ls /sys/class/net",
        "addpay": "",
        "append": "",
        "useSpawn": "false",
        "timer": "",
        "winHide": false,
        "oldrc": false,
        "name": "List network interfaces",
        "x": 385,
        "y": 100,
        "wires": [
            [
                "9874a0d3d5de224a"
            ],
            [],
            []
        ]
    },
    {
        "id": "9874a0d3d5de224a",
        "type": "function",
        "z": "493f26a77a9ec46e",
        "name": "Detect CAN interface",
        "func": "const lines = (msg.payload || '').split('\\n').map(l => l.trim()).filter(Boolean);\nconst canIfaces = lines.filter(l => /^(ve)?can\\d+$/.test(l));\n\nif (canIfaces.length === 0) {\n    node.error('No CAN interface found under /sys/class/net -- leaving flow.canInterface untouched');\n    return null;\n}\n\n// Prefer plain can0/can1 over vecan0/vecan1 if both happen to exist\ncanIfaces.sort((a, b) => (a.startsWith('ve') ? 1 : 0) - (b.startsWith('ve') ? 1 : 0));\n\nconst chosen = canIfaces[0];\nflow.set('canInterface', chosen);\n\nmsg.payload = `Detected CAN interface: ${chosen} (candidates found: ${canIfaces.join(', ')})`;\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 605,
        "y": 100,
        "wires": [
            [
                "37cbb11252d7377a"
            ]
        ]
    },
    {
        "id": "37cbb11252d7377a",
        "type": "debug",
        "z": "493f26a77a9ec46e",
        "name": "CAN interface detection result",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 855,
        "y": 100,
        "wires": []
    },
    {
        "id": "708269b11fe3d756",
        "type": "comment",
        "z": "493f26a77a9ec46e",
        "name": "Auto-detects CAN interface on every deploy",
        "info": "Runs 'ls /sys/class/net' once, ~1s after deploy, and sets flow.canInterface to whichever of can0/can1/vecan0/vecan1 is found (preferring plain can* over vecan* if both exist). Check the debug sidebar to confirm what was detected. If it ever picks the wrong one (e.g. both present), use the manual 'CAN interface = ...' buttons to override.",
        "x": 235,
        "y": 60,
        "wires": []
    }
]

Thanks @nickdb, awk and grep can do anything :stuck_out_tongue:

And @Vladyslav_Kh , I always forget about sysfs!

Does the different naming come down to hardware or firmware? I have read that some of the microcontrollers for the GX have onboard CAN, and some use external controllers.

Trying to answer my own question…

Ekrano GX (v3.81):

vecan0 → ../../devices/platform/soc/1c69000.spi/spi_master/spi1/spi1.0/net/vecan0
vecan1 → ../../devices/platform/soc/1c68000.spi/spi_master/spi0/spi0.0/net/vecan1

Cerbo Mk2 (v3.75):

vecan0 → ../../devices/platform/soc/1c2bc00.can/net/vecan0
vecan1 → ../../devices/platform/soc/1c17000.spi/spi_master/spi0/spi0.0/net/vecan1

Cerbo Mk1 (v3.81 HQ26xxxxx):

vecan0 → ../../devices/platform/soc/1c2bc00.can/net/vecan0
vecan1 → ../../devices/platform/soc/1c17000.spi/spi_master/spi0/spi0.0/net/vecan1

Cerbo Mk1 (v3.90-beta6 HQ20xxxx)

can0 → ../../devices/platform/soc/1c2bc00.can/net/can0
can1 → ../../devices/platform/soc/1c28c00.serial/1c28c00.serial:0/1c28c00.serial:0.0/serial1/serial1-0/net/can1

As far as I am aware it is hardware. Moving from the same version on a mk1 cerbo to a mk3, the naming changed.

/sys/devices/platform/bus@f0000/20701000.can/net/vecan0
/sys/devices/platform/bus@f0000/20100000.spi/spi_master/spi0/spi0.0/net/vecan1