Back to Index

Definition: every(interval_ms [, "label"]) { ... } — Allowed: top-level declaration; Not allowed: nesting inside blocks.

Registers a repeating scheduled block that runs approximately every interval_ms. Optional string label lets you manually fire it via trigger("label"). Must be declared at the top level (not inside other blocks). If interval_ms is negative, the task is registered but never auto-runs; you can still fire it with trigger("label") for manual-only tasks.

Inside an every block, next; exits the current run early (skips the rest of that block for this tick). break/continue still apply only to nested for loops.

Timing note: with a 100 ms cycle the observed jitter is about 1%. For more deterministic timing, avoid every intervals below 100 ms.

Example

every(5000, "telemetry") {
  publish("plc/temp", temp());
}

Here, the block publishes temperature every 5 seconds and can be fired immediately with trigger("telemetry").