/esp-idf-can2websocket

Brows CAN-Frame using esp-idf

Primary LanguageCMIT LicenseMIT

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

  • SN65HVD23x CAN-BUS Transceiver
    SN65HVD23x series has 230/231/232.
    They differ in standby/sleep mode functionality.
    Other features are the same.

  • Termination resistance
    I used 150 ohms.

Wireing

SN65HVD23x ESP32 ESP32-S2/S3 ESP32-C3/C6
D(CTX) -- GPIO21 GPIO17 GPIO0 (*1)
GND -- GND GND GND
Vcc -- 3.3V 3.3V 3.3V
R(CRX) -- GPIO22 GPIO18 GPIO1 (*1)
Vref -- N/C N/C N/C
CANL -- To CAN Bus
CANH -- To CAN Bus
RS -- GND GND GND (*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

  • Binary
    format-binary

  • Octal
    format-octal

  • Decimal
    format-decimal

  • Hexadecimal
    format-hex

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.

  • There is no receiving app on CanBus.
  • The speed does not match the receiver.
  • There is no terminating resistor on the CanBus.
  • There are three terminating resistors on the CanBus.
  • The resistance value of the terminating resistor is incorrect.
  • Stub length in CAN bus is too long. See here.

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