Skip to content
Daniel Öster edited this page Jan 25, 2025 · 15 revisions

CAN logging basics

The board can operate as a CAN logger, skipping the need for purchasing an expensive tool. There are two ways to log CAN messages, via USB (more reliable), and via Webserver (easier).

CAN logging via Webserver

Note

CAN logging via Webserver does not store all messages due to limited RAM. If you need to log absolutely everything, do it via USB or to SD-CARD

Start by accessing the Webserver

On the main page, there is a button named "CAN logger" .When opened, the system starts logging CAN messages. This is disabled by default to not disturb the system.

image

Refresh the page to get an updated list of incoming (RX) and sent (TX) CAN messages.

image

USB CAN logging

To access the CAN-logging, enable the DEBUG_CAN_DATA feature. When this is enabled, all the incoming/outgoing CAN&CAN-FD messages will get timestamp, direction, ID, DLC, and data fields printed out via the Arduino IDE serial monitor. This can then be exported to a .txt file for later analysis.

##Log file format The log file format is compatible with the CANdump format. This can be read natively by tools like SavvyCAN.

Example format, CAN log:

(7.556) TX1 54A [8] 10 0 70 2 0 0 0 2B 
(7.558) TX1 54B [8] 1 8 80 12 4 0 0 0 
(7.560) TX1 54C [8] 61 66 0 0 0 0 57 0 
(7.561) TX1 1D4 [8] F7 7 0 0 7 46 0 7B 
(7.573) TX1 11A [8] 1 40 0 AA C0 0 0 3 

Example format, CAN-FD log:

(64.644) TX1 10A [32] D8 DE 99 00 00 00 00 01 FF 01 00 00 36 39 35 35 C9 02 00 00 10 00 00 35 00 00 0A 00 00 00 00 00  
(64.656) TX1 120 [32] 6E F3 99 00 00 00 00 01 FF 01 00 00 37 35 37 37 C9 02 00 00 00 00 00 35 00 00 0A 00 00 00 00 00 
(64.668) TX1 19A [32] 19 48 88 55 44 64 D8 1B 40 20 00 00 00 00 11 52 00 12 02 64 00 00 00 08 13 00 00 00 00 32 00 00 
(64.669) TX1 10A [32] 12 35 9A 00 00 00 00 01 FF 01 00 00 36 39 35 35 C9 02 00 00 10 00 00 35 00 00 0A 00 00 00 00 00 
(64.681) TX1 120 [32] A4 18 9A 00 00 00 00 01 FF 01 00 00 37 35 37 37 C9 02 00 00 00 00 00 35 00 00 0A 00 00 00 00 00 

Note

If your serial monitor is filled with strange symbols "???!"?¤¤%" , change the baud rate in the serial monitor window from 9600 -> 115200
When a large amount of CAN traffic is present on the bus, you may need to increase the serial monitor baud rate to 460800 in Software.ino ( by changing Serial.begin(115200); to Serial.begin(460800); ) of course the serial baud rate of the serial monitor then also needs to be increased to 460800.

SD card CAN logging

To enable logging of CAN messages to an SD card enable the LOG_CAN_TO_SD feature. To maximise performance you should not enable the DEBUG_CAN_DATA or LOG_TO_SD features at the same time as it could lead to CAN messages not being logged. The format of the log file is the same as the USB CAN logging feature and can be read by tools like Savvy CAN directly.

If you have debug logging enabled and there are too many messages on the CAN bus to write to the SD card the error Failed to send message to can ring buffer! will be logged.

Once enabled the CAN logger button will be enabled on the webserver, no data will be shown on the website, instead the CAN log file can be downloaded by clicking on the Export to .txt button which will download the file from the battery emulator. You can also delete the CAN log file by clicking on the Delete log file button. For very large captures it may be quicker to remove the SD card and plug it into a PC directly.

The SD card must be formatted using the FAT file system, if you are using an SD card larger than 32GB you will need to partition the card otherwise exFAT will be used which the ESP32 does not support. The best tool to use for formatting of the SD card is SD Card Formatter

On startup the SD card is checked and if you have debug logging enabled a message will be output showing success or failure.

Success Example

SD Card initialization successful.
SD Card Type: SDHC
SD Card Size: 61183 MB
Total space: 7984 MB
Used space: 2MB

Failure Example

sdmmc_init_ocr: send_op_cond (1) returned 0,107
vfs_fat_sdmmc: sdmmc_card_init failed ()x107).
Failed to initialize the card (0x107). Make sure SD_card lines have pull-up resistors in place.
SD Card initialization failed!
Clone this wiki locally