This is a program that lets the Olimex ESP32-EVB act as a socketcand adapter. It runs a server on port 29536 that translates traffic between TCP socketcand clients and its CAN bus.
Clients can connect to the adapter via TCP socketcand to communicate with the CAN bus connected to the adapter.
Client1 <---TCP Socketcand---> |---------------------------|
| esp32_socketcand_adapter |
Client2 <---TCP Socketcand---> | running on |
| Olimex ESP32-EVB |
Physical CAN bus (vcan0) <---> |---------------------------|
Here's an image of an example setup:
-
Install Esptool by running:
python -m pip install esptool -
Download the latest
esp32_socketcand_adapter.binfile from the Releases page. -
Connect an Olimex ESP32-EVB to your computer with a micro USB cable.
-
Flash your ESP32 by running
python -m esptool write_flash 0 esp32_socketcand_adapter.bin -
Optionally, monitor log output on Linux by running:
tail -f /dev/ttyUSB0
Replace /dev/ttyUSB0 with the port you're using. Run
lsusbto get a list of USB ports.Note: Flashing will fail if the port is being monitored.
Alternatively, you can build the project yourself.
-
Install ESP-IDF.
-
Download this repository.
-
Run
idf.py buildto build the project. -
Run
idf.py flashto flash your ESP32.
-
On startup, your ESP32 will print its curent network settings over USB UART. Hold button
BUT1for 1 second to reset the settings to default. The default settings are:- Ethernet uses statically assigned IP:
- Address: 192.168.2.163
- Netmask: 255.255.255.0
- Gateway: 192.168.2.1
- Wi-Fi is disabled.
- CAN bitrate is 500 kbit/s.
- Ethernet uses statically assigned IP:
-
Use an ethernet cable to connect the ESP32 to your computer or a local network.
-
In a web browser, go to http://192.168.2.163/, or whatever the ESP32's ethernet IP is. You should see a web interface served by the ESP32 over HTTP. Change network settings to your liking.
-
Connect the ESP32 to a CAN bus.
This example lets you listen to CAN packets from the ESP32 Socketcand Adapter. This example only works on Linux.
-
Install can-utils. On Debian:
sudo apt install can-utils. -
Install socketcand by following the instructions in the socketcand repository.
-
Create a virtual CAN device:
sudo ip link add dev vcan0 type vcan. -
Enable the virtual CAN device:
sudo ip link set up vcan0. -
In the background, start
./socketcandcl -v --server [ESP32 IP ADDRESS] -i vcan0,vcan0. Use the IP address of your ESP32. -
Print incoming CAN packets with
candump vcan0.
If the CAN bus has OpenCyphal nodes on it, you can interact with them using yakut. Here are some examples:
# Monitor the CAN bus using:
yakut --transport "CAN(can.media.socketcand.SocketcandMedia('can0','192.168.2.163'),99)" monitor
# Get the info of node 18 on the CAN bus using:
yakut --transport "CAN(can.media.socketcand.SocketcandMedia('can0','192.168.2.163'),99)" call 18 uavcan.node.GetInfo.1.0 '{}'
# Get the name register of node 18 on the CAN bus using:
yakut --transport "CAN(can.media.socketcand.SocketcandMedia('can0','192.168.2.163'),99)" call 18 uavcan.register.Access.1.0 "{'name':{'name':'NAME'}}"