> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hyperwisor.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Lesson 4 — The Core Loop

> Push a value up to your gauge, and send a command down from your switch.

**Goal:** close the loop from Lessons 2 and 3 — data flows *up* to your gauge, a
command flows *down* to your device. This is the heart of the whole platform.

## Up: push a value to the gauge

The gauge you made (ID `tempGauge`) updates when something pushes a value to that
ID.

**Real hardware** — from firmware:

```cpp theme={null}
void loop() {
  device.loop();
  float temperature = readTemperature();          // your sensor
  device.updateWidget(targetId, "tempGauge", temperature);
  delay(2000);
}
```

**LiveLink** — from the Device side, send a payload the gauge can read (map its
field to `tempGauge` in the widget's Data tab), and watch the gauge move.

Open the dashboard in **Preview** — the gauge tracks the value live. No polling.

## Down: send a command from the switch

Flip the **Switch** on the dashboard. It sends your `Operate` command. The device
receives it.

**Real hardware** — handle it in firmware:

```cpp theme={null}
void setup() {
  device.setUserCommandHandler([](JsonObject &msg) {
    JsonObject on = device.findAction(msg, "Operate", "ON");
    if (!on.isNull()) { /* turn the thing on */ }
    JsonObject off = device.findAction(msg, "Operate", "OFF");
    if (!off.isNull()) { /* turn it off */ }
  });
  device.begin();
}
```

**LiveLink** — the command appears in the **Device Side** log the moment you toggle
the switch; reply with `{ "status": "ok" }` from the Device side.

## What you just did

<CardGroup cols={2}>
  <Card title="Value up" icon="arrow-up">
    `updateWidget(targetId, "tempGauge", value)` → the bound gauge.
  </Card>

  <Card title="Command down" icon="arrow-down">
    The switch → `setUserCommandHandler` on the device.
  </Card>
</CardGroup>

That's the [core loop](/learn/how-it-works) working end to end — the same pattern
every Hyperwisor product runs on.

<Card title="Next: store data & automate" icon="arrow-right" href="/learn/lessons/05-store-automate">
  Log readings and add a rule.
</Card>
