This is a demo of a wasmCloud lattice running across an Apple MacBook Pro and 2 x Raspberry Pi 4B.
The lattice is a self-forming, self-healing mesh network that provides a unified, flattened topology across any number of disparate environments, clouds, browsers, or even hardware.
In this example, the lattice is made of three wasmcloud nodes, one on the Mac and one on each Pi. However it would work just as well with one Pi, simply collapse pi_01
and pi_02
together as you go.
The Mac node hosts the wasmcloud HTTP Server Capability that forwards incoming requests to our sandboxed Wasm actor, which can run on any node, but in this demo runs on pi_02
.
Wasmcloud has a built-in Logging Capability, which the actor uses to log to stdout
.
The Wasm actor contains our "business" logic. It is signed and only given permissions to talk with the HTTP Server capability, the Logging capability, the NumberGen capability (for generating a uuid to identify the actor instance) and our OLED capability. This OLED capability is hosted by the wasmCloud host running on pi_01
, where it natively controls an OLED display.
-
make sure I2C is enabled on
pi-01
(the Pi with the Oled display attached).sudo raspi-config
-
install Rust on each Pi
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-
install Elixir on each Pi
echo "deb https://packages.erlang-solutions.com/debian buster contrib" \ | sudo tee /etc/apt/sources.list.d/erlang-solutions.list wget https://packages.erlang-solutions.com/debian/erlang_solutions.asc \ && sudo apt-key add erlang_solutions.asc \ && rm erlang_solutions.asc sudo apt update sudo apt install erlang-parsetools erlang-dev elixir
-
clone the
wasmcloud-otp
repo, then buildhost_core
on each Pigit clone git@github.com:wasmCloud/wasmcloud-otp.git cd wasmcloud-otp git checkout v0.52.2 cd host_core make build
-
install the OLED display with SSD1306 display driver, on
pi-01
- MakerHawk OLED Display Module, SSD1306, 128x64
- Header pins need soldering onto the OLED board
- Jumper leads to these pins on the Pi:
VCC
- pin 1GND
- pin 6SCL
- pin 5SDA
- pin 3
-
find the IP address of your Mac (this may list several, in which case choose one on the interface to the subnet containing your Raspberry Pi devices)
./automation/macos.mjs --ip
and add the Mac's IP address and hostname to
/etc/hosts
on each Pi, so that you can use the OCI registry hosted on the mac. -
run NATS server, wasmcloud, redis, and a local OCI registry, on the Mac
./automation/macos.mjs --up
-
run a wasmCloud host on each Pi:
git clone git@github.com:redbadger/rpi-wasmcloud-demo.git cd rpi-wasmcloud-demo ./automation/rpi.mjs --up
-
open the washboard in a browser on the mac (http://localhost:4000) for starting providers, actors and defining links.
-
you may want to install these extensions into vscode (on the Mac and the Pi that you use to build the provider)
- Remote SSH - useful for writing code directly on a Pi.
- Rust Analyzer - essential :-)
-
install
wash
on the Mac:# using homebrew ... brew tap wasmcloud/wasmcloud brew install wash # ... or with cargo cargo install wash-cli
-
install
wash
on the Pi that is used to build the provider:cargo install wash-cli
Build the provider and the actor, and push them to an OCI registry.
# on a Raspberry Pi, e.g. via ssh, or vscode remote
# install node
curl -fsSL https://fnm.vercel.app/install | bash
source /home/pi/.bashrc
fnm install 16
# install zx
npm i --global zx
# install dirsh
cargo install dirsh
# build provider
./provider/make.mjs --build --push
# push to registry on mac (ensure there is an entry in /etc/hosts for `registry`, pointing at Mac)
make push
# on the MacBook
./actor/make.mjs --build --push
./automation/macos.mjs --start
# to test
curl -d 'Hello from wasmcloud!' http://127.0.0.1:8080
curl -X DELETE http://127.0.0.1:8080