All Projects → redbadger → rpi-wasmcloud-demo

redbadger / rpi-wasmcloud-demo

Licence: MIT license
Demo running wasmcloud lattice on MacOS and 2x Raspberry Pi 4B

Programming Languages

rust
11053 projects
javascript
184084 projects - #8 most used programming language
Dockerfile
14818 projects
Makefile
30231 projects
Starlark
911 projects

Projects that are alternatives of or similar to rpi-wasmcloud-demo

rasa-docker-arm
Rasa Docker image for ARMv7. Runs on a Raspberry Pi.
Stars: ✭ 19 (+5.56%)
Mutual labels:  raspberry-pi-4b
WiFiConnect
WiFi connection manager for ESP32 and ESP8266 with OLED support
Stars: ✭ 28 (+55.56%)
Mutual labels:  oled-ssd1306
webassembly-tour
⚙️ Take you through a tour of WebAssembly (WASM targets on WASI) with wasmCloud, Krustlet, WAGI, etc. 🌟 Give it a star if you like it.
Stars: ✭ 111 (+516.67%)
Mutual labels:  wasmcloud

Raspberry Pi wasmcloud Demo

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.

wasmcloud lattice across Mac and Pi

Setup

  1. make sure I2C is enabled on pi-01 (the Pi with the Oled display attached).

    sudo raspi-config
  2. install Rust on each Pi

    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  3. 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
  4. clone the wasmcloud-otp repo, then build host_core on each Pi

    git clone [email protected]:wasmCloud/wasmcloud-otp.git
    cd wasmcloud-otp
    git checkout v0.52.2
    cd host_core
    make build
  5. install the OLED display with SSD1306 display driver, on pi-01

    1. MakerHawk OLED Display Module, SSD1306, 128x64
    2. Header pins need soldering onto the OLED board
    3. Jumper leads to these pins on the Pi:
      1. VCC - pin 1
      2. GND - pin 6
      3. SCL - pin 5
      4. SDA - pin 3
  6. 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.

  7. run NATS server, wasmcloud, redis, and a local OCI registry, on the Mac

    ./automation/macos.mjs --up
  8. run a wasmCloud host on each Pi:

    git clone [email protected]:redbadger/rpi-wasmcloud-demo.git
    cd rpi-wasmcloud-demo
    
    ./automation/rpi.mjs --up
  9. open the washboard in a browser on the mac (http://localhost:4000) for starting providers, actors and defining links.

  10. you may want to install these extensions into vscode (on the Mac and the Pi that you use to build the provider)

    1. Remote SSH - useful for writing code directly on a Pi.
    2. Rust Analyzer - essential :-)
  11. install wash on the Mac:

    # using homebrew ...
    brew tap wasmcloud/wasmcloud
    brew install wash
    
    # ... or with cargo
    cargo install wash-cli
  12. install wash on the Pi that is used to build the provider:

    cargo install wash-cli

Build

Build the provider and the actor, and push them to an OCI registry.

provider

# 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

actor

# on the MacBook
./actor/make.mjs --build --push

Run

./automation/macos.mjs --start

Test

# to test
curl -d 'Hello from wasmcloud!' http://127.0.0.1:8080
curl -X DELETE http://127.0.0.1:8080

Photo of setup

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].