Home

Awesome

esp-idf-can2websocket

Brows CAN-Frame using esp-idf.
You can browse the CAN-Frame in real time using the built-in WebSocket server.
Similar to this, but this project uses the WebSocket protocol instead of the HTTP protocol.
ESP32 acts as a WebSocket server.

format-binary

I used this component.
This component can communicate directly with the browser.
There is an example of using the component here. It's a great job.

Software requirement

ESP-IDF V5.0 or later.
ESP-IDF V4.4 release branch reached EOL in July 2024.
ESP-IDF V5.1 is required when using ESP32-C6.

Hardware requirements

Wireing

SN65HVD23xESP32ESP32-S2/S3ESP32-C3/C6
D(CTX)--GPIO21GPIO17GPIO0(*1)
GND--GNDGNDGND
Vcc--3.3V3.3V3.3V
R(CRX)--GPIO22GPIO18GPIO1(*1)
Vref--N/CN/CN/C
CANL--To CAN Bus
CANH--To CAN Bus
RS--GNDGNDGND(*2)

(*1) You can change using menuconfig. But it may not work with other GPIOs.

(*2) N/C for SN65HVD232

Test Circuit

   +-----------+   +-----------+   +-----------+ 
   | Atmega328 |   | Atmega328 |   |   ESP32   | 
   |           |   |           |   |           | 
   | Transmit  |   | Receive   |   | 21    22  | 
   +-----------+   +-----------+   +-----------+ 
     |       |      |        |       |       |   
   +-----------+   +-----------+     |       |   
   |           |   |           |     |       |   
   |  MCP2515  |   |  MCP2515  |     |       |   
   |           |   |           |     |       |   
   +-----------+   +-----------+     |       |   
     |      |        |      |        |       |   
   +-----------+   +-----------+   +-----------+ 
   |           |   |           |   | D       R | 
   |  MCP2551  |   |  MCP2551  |   |   VP230   | 
   | H      L  |   | H      L  |   | H       L | 
   +-----------+   +-----------+   +-----------+ 
     |       |       |       |       |       |   
     +--^^^--+       |       |       +--^^^--+
     |   R1  |       |       |       |   R2  |   
 |---+-------|-------+-------|-------+-------|---| BackBorn H
             |               |               |
             |               |               |
             |               |               |
 |-----------+---------------+---------------+---| BackBorn L

      +--^^^--+:Terminaror register
      R1:120 ohms
      R2:150 ohms(Not working at 120 ohms)

NOTE
3V CAN Trasnceviers like VP230 are fully interoperable with 5V CAN trasnceviers like MCP2551.
Check here.

Installation

git clone https://github.com/nopnop2002/esp-idf-can2websocket
cd esp-idf-can2websocket
git clone https://github.com/Molorius/esp32-websocket components/websocket
idf.py set-target {esp32/esp32s2/esp32s3/esp32c3/esp32c6}
idf.py menuconfig
idf.py flash

Configuration

config-main config-app

CAN Setting

config-can

Display all received frames to STDOUT. stdout

WiFi Setting

config-wifi

You can use Static IP.
config-static

You can connect using mDNS name.
config-mDNS mDNS

Definition CANbus Frame

When CANbus data is received, it is sent by built-in HTTP server according to csv/can2http.csv.
The file can2http.csv has three columns.
In the first column you need to specify the CAN Frame type.
The CAN frame type is either S(Standard frame) or E(Extended frame).
In the second column you have to specify the CAN-ID as a hexdecimal number.
In the last column you have to specify the Frame Name.
A descriptive name for CAN Frame.

S,101,Water Temperature
E,101,Water Pressure
S,103,Gas Temperature
E,103,Gas Pressure

Format conversion

Troubleshooting

There is a module of SN65HVD230 like this.
SN65HVD230-1

There is a 120 ohms terminating resistor on the left side.
SN65HVD230-22

I have removed the terminating resistor.
And I used a external resistance of 150 ohms.
A transmission fail is fixed.
SN65HVD230-33

If the transmission fails, these are the possible causes.

WEB Page

The WEB page is stored in the html folder.
You can change it as you like.

Task Structure Diagram

Task_structure_diagram

Reference

https://github.com/nopnop2002/esp-idf-candump

https://github.com/nopnop2002/esp-idf-can2http

https://github.com/nopnop2002/esp-idf-can2mqtt

https://github.com/nopnop2002/esp-idf-can2usb

https://github.com/nopnop2002/esp-idf-can2socket

https://github.com/nopnop2002/esp-idf-CANBus-Monitor