A distributed Erlang application running on ESP32 microcontrollers using AtomVM. Two ESP32 boards communicate over WiFi and play ping-pong by exchanging messages and flashing LEDs.
You MUST flash your ESP32 with an AtomVM image built from the main branch, not a release version. The distributed Erlang features required for this project are only available in the latest development version.
To build and flash AtomVM:
git clone https://github.com/atomvm/AtomVM.git
cd AtomVM
git checkout main
# Follow AtomVM build instructions for ESP32
# Flash the generated .img file to your ESP32Edit src/config.erl to set your WiFi credentials:
get() ->
#{
sta => [{ssid, "YourSSID"}, {psk, "YourPassword"}],
port => 6969,
led => #{pin => 2, flash_duration => 100}
}.make buildThis compiles the Erlang code and creates an .avm package file at:
_build/default/lib/iot_node.avm
Flash both ESP32 boards with the compiled application:
# Flash both ESP32 at once
make flash
# Or flash individually
make flash1 # Flash ESP32 #1 on /dev/tty.usbserial-0001
make flash2 # Flash ESP32 #2 on /dev/tty.usbserial-3Note: Update the PORT1 and PORT2 variables in Makefile to match your USB serial ports.
- Both ESP32 boards boot and connect to WiFi
- Each board starts distributed Erlang with a unique node name based on its IP:
atomvm@192.168.1.49atomvm@192.168.1.50
- After a 5-second stabilization period, the
.50node sends the firstping - The nodes exchange
ping/pongmessages indefinitely - Each message reception triggers an LED flash
- Both ESP32 must be on the same WiFi network
- The application expects IP addresses:
192.168.1.49for one board192.168.1.50for the other
- If your DHCP assigns different IPs, update the logic in
src/iot_node.erl:65-68
- Ensure both ESP32 are running the same code version
- Check that both boards have the same cookie (
AtomVM) - Verify network connectivity between the boards
- Make sure you're using AtomVM from
mainbranch, not a release - Check that WiFi credentials are correct in
config.erl
You can also trigger the ping-pong from an Erlang shell:
% Connect to the node
erlang:set_cookie('atomvm@192.168.1.50', 'AtomVM').
% Send initial ping
{ping_pong, 'atomvm@192.168.1.50'} ! ping.
% To stop
{ping_pong, 'atomvm@192.168.1.50'} ! stop.