Skip to main content

Smart Greenhouse

In this tutorial you build a complete Myrmic application on a single computer: a smart greenhouse that keeps the soil of a grow bed inside a target moisture range - and a live web dashboard to watch it work.

You will write five cells, wire them together with events and commands, and drive the whole thing from the Myrmic CLI. Along the way you will use most of the CLI's day-to-day functionality: scaffolding, building, deploying, listing cells, sending commands, publishing and subscribing to events, serving a web frontend through the gateway, reading logs, and tearing everything down again.

No hardware is required - the sensor is mocked in software.

What You Will Build

Five cells, one per role:

CellPatternResponsibility
moisture-sensorAdapter (mocked)Publishes a moisture reading every second. The mock value swings between dry and wet, standing in for real weather and soil physics.
pumpAdapter (actuator)Accepts start / stop commands and announces its state on the pump_state event. Knows nothing about plants or policy.
grow-bedAssetOwns the canonical state of one bed of plants: latest moisture, pump status, and the moisture range the plants want. Announces every change on the bed_state event.
dashboardAdapter (gateway)Mirrors bed_state into a JSON snapshot and serves the web page at /greenhouse through the gateway. Owns no truth, makes no decisions.
irrigation-agentAgentThe only cell that makes decisions: reads the bed's bed_state and drives the pump with hysteresis.

The roles follow the cell patterns: assets own state, adapters own actuation, agents own decisions. The layering is strict: the raw moisture event is a detail of the sensor adapter, consumed only by the asset; everyone else - the agent included - reads the grow-bed's canonical bed_state. Nothing commands the pump except the agent, and the grow-bed commands nothing at all - if you later reuse it in an application without irrigation, it carries no dead weight. And the sensor and the pump do not know each other at all: in the real world they are connected by soil and water, not by software.

moisture (event) bed_state (event)
moisture-sensor ──────────────► grow-bed ────────┬────────► irrigation-agent
(canonical state) │ │
▲ ▼ │
pump_state (event)│ dashboard │ start / stop
│ │ latest.json │ (commands)
│ ▼ │
│ myrmic gateway ◄─ browser│
pump ◄──────────────────────────┘

To facilitate the visualization and understanding, we will use several terminals:

TerminalRuns
Terminal 1the Myrmic runtime
Terminal 2your working shell: scaffold, build, deploy, send
Terminal 3myrmic subscribe - a live view of the events flying around
Terminal 4the gateway

Prerequisites

  • The Myrmic CLI installed and the Rust toolchain set up - complete the Quickstart first if you have not.
  • A web browser.

Tutorial Parts

  1. The Mock Sensor - start the runtime, scaffold your first cell, and build a mock sensor - learning how cells publish and subscribe to events.
  2. The Pump - build the actuator that waters the bed - learning how to use cell commands.
  3. The Grow-Bed - build the Asset Cell that owns the bed's canonical state - learning how to model and share structured state.
  4. The Irrigation Agent - automate the watering decision - learning how cells send commands to each other.
  5. The Dashboard - put the bed on a web page served through the gateway - learning how cells face the browser.
  6. The Finale - play with the swarm, tear it down, and bring it all back with one command - learning how app_specs.yml ships an application as one unit.
Cookie Policy