Skip to content
Flyght
Sign in

FlyghtEdge · Flyght Cloud

Documentation

From installing the library to a device you watch and control from anywhere, step by step.

Components · 01

Components

Every widget and module you can put on a device, with its code and parameters.

A component is a card on the device’s dashboard. The eight widgets are one line each on a page (dev.page(...)); the modules (lights, relays, sensors, motors) draw their own cards and are added with dev.use(...) before dev.begin(); flows are automations drawn in the browser. Pick one to see a preview, the code that makes it, its parameters and what it sends.

Components · 02

Toggle

An on/off switch that calls your function.

A toggle holds a boolean. The callback receives the new state each time anyone changes it: the dashboard, MQTT, the HTTP API, the cloud or a flow.

ToggleC++
dev.page("Home", "home")
   .toggle("fan", "Ceiling Fan", [](bool on) { digitalWrite(FAN_PIN, on); })
   .icon("fan");

Parameters of toggle(...)

ParameterTypeDefault / rangeMeaning
idconst char*1 to 32 of A-Z a-z 0-9 _ -Unique name of the widget. It is the key in the API, the MQTT topic and the cloud.
labelconst char*requiredThe text on the card.
cbstd::function<void(bool)>nullptrCalled on the loop task with the new state. Optional.

Modifiers

A modifier written after a widget applies to that widget (the one added last).

ModifierMeaning
size(cols)Width in columns, 1 to 3.
icon(name)The icon of the card: home, layout-grid, bulb, fan, thermo, droplet, zap, sun, gauge, activity, chart, sliders, list, type, pointer, bell, power, lock, wifi, plug, cpu, key, shield, sparkles and more.
role(Role::Viewer|Operator|Admin)The lowest role that may change the widget. Default Operator.
device(deviceId)Marks the widget as belonging to a pin device, so its card menu offers pin settings.

The default icon is power.

Set and read the value

WhereHow
From the sketchdev.ui().set("fan", true) (any non-zero number is true). Read with dev.ui().flag("fan"). dev.ui().apply("fan", "toggle", fn::Source::Code) parses the text and also runs the callback.
MQTTState on <base>/state/fan: ON or OFF. Command on <base>/set/fan: ON, OFF or TOGGLE.
Local HTTPPOST /fn/api/v1/state with {"fan":true}, or POST /fn/api/v1/ui/w/fan with {"value":null} to flip it. Accepted values: true, false, on, off, toggle.
CloudThe same text on <prefix>/<DEVICE_ID>/state/fan and <prefix>/<DEVICE_ID>/set/fan.

Components · 03

Button

A press that runs a function.

A button has no value: it only fires its callback. Because there is nothing to show, it is never published as a state.

ButtonC++
dev.page("Home", "home")
   .button("bell", "Doorbell", [] {
     digitalWrite(BELL_PIN, HIGH);
     dev.sched().after(200, [] { digitalWrite(BELL_PIN, LOW); });
   });

Parameters of button(...)

ParameterTypeDefault / rangeMeaning
idconst char*1 to 32 of A-Z a-z 0-9 _ -Unique name of the widget. It is the key in the API, the MQTT topic and the cloud.
labelconst char*requiredThe text on the card.
cbstd::function<void()>requiredCalled on the loop task at every press.

Modifiers

A modifier written after a widget applies to that widget (the one added last).

ModifierMeaning
size(cols)Width in columns, 1 to 3.
icon(name)The icon of the card: home, layout-grid, bulb, fan, thermo, droplet, zap, sun, gauge, activity, chart, sliders, list, type, pointer, bell, power, lock, wifi, plug, cpu, key, shield, sparkles and more.
role(Role::Viewer|Operator|Admin)The lowest role that may change the widget. Default Operator.
device(deviceId)Marks the widget as belonging to a pin device, so its card menu offers pin settings.

The default icon is pointer.

Press it

WhereHow
From the sketchdev.ui().apply("bell", "PRESS", fn::Source::Code) runs the callback. set() has no effect on a button.
MQTTPublish PRESS to <base>/set/bell.
Local HTTPPOST /fn/api/v1/ui/w/bell; an empty body or {"value":null} presses it.

Components · 04

Slider

A number between a minimum and a maximum.

A slider holds a number. Every value is clamped to min..max and snapped to step, whoever sets it. It starts at min.

SliderC++
dev.page("Home", "home")
   .slider("bright", "Brightness", 0, 100, 5, [](float v) { analogWrite(LED_PIN, v * 2.55); })
   .unit("%");

Parameters of slider(...)

ParameterTypeDefault / rangeMeaning
idconst char*1 to 32 of A-Z a-z 0-9 _ -Unique name of the widget. It is the key in the API, the MQTT topic and the cloud.
labelconst char*requiredThe text on the card.
minfloatrequiredThe lowest value; also the start value.
maxfloatrequiredThe highest value.
stepfloat1The size of one step. Decimals follow it: 0 when step is 1 or more, 1 from 0.1, else 2.
cbstd::function<void(float)>nullptrCalled on the loop task with the new value.

Modifiers

A modifier written after a widget applies to that widget (the one added last).

ModifierMeaning
size(cols)Width in columns, 1 to 3.
icon(name)The icon of the card: home, layout-grid, bulb, fan, thermo, droplet, zap, sun, gauge, activity, chart, sliders, list, type, pointer, bell, power, lock, wifi, plug, cpu, key, shield, sparkles and more.
unit(u)The unit shown next to the value.
decimals(d)Digits after the point, 6 at most.
role(Role::Viewer|Operator|Admin)The lowest role that may change the widget. Default Operator.
device(deviceId)Marks the widget as belonging to a pin device, so its card menu offers pin settings.

The default icon is sliders.

Set and read the value

WhereHow
From the sketchdev.ui().set("bright", 70); read with dev.ui().number("bright"). set() clamps and snaps, and does not call the callback.
MQTTA number as text with the widget’s decimals: <base>/state/bright is 70; send 70 to <base>/set/bright.
Local HTTPPOST /fn/api/v1/state with {"bright":70}.

Components · 05

Gauge

A read-only dial for a measurement.

A gauge shows a number on a dial between min and max. It is read-only: it reports what the sketch pushes.

GaugeC++
dev.page("Garden", "sprout")
   .gauge("soil", "Soil moisture", "%", 0, 100);

// in loop():
dev.ui().set("soil", readSoilPercent());

Parameters of gauge(...)

ParameterTypeDefault / rangeMeaning
idconst char*1 to 32 of A-Z a-z 0-9 _ -Unique name of the widget. It is the key in the API, the MQTT topic and the cloud.
labelconst char*requiredThe text on the card.
unitconst char*requiredThe unit text, for example "%" or "°C".
minfloatrequiredThe value at the start of the dial.
maxfloatrequiredThe value at the end of the dial.

Modifiers

A modifier written after a widget applies to that widget (the one added last).

ModifierMeaning
size(cols)Width in columns, 1 to 3.
icon(name)The icon of the card: home, layout-grid, bulb, fan, thermo, droplet, zap, sun, gauge, activity, chart, sliders, list, type, pointer, bell, power, lock, wifi, plug, cpu, key, shield, sparkles and more.
decimals(d)Digits after the point, 6 at most.
device(deviceId)Marks the widget as belonging to a pin device, so its card menu offers pin settings.

The default icon is gauge.

Set and read the value

WhereHow
From the sketchdev.ui().set("soil", 62.5); read with dev.ui().number("soil"). A NaN is sent as no value (null).
MQTT<base>/state/soil carries the number as text with the widget’s decimals.
Local HTTPGET /fn/api/v1/state lists it under values.

Components · 06

Value

A read-only number or text.

A value card shows one number or one piece of text, large. Use it for readings that need no dial and for statuses such as “Ready”.

ValueC++
dev.page("Room", "home")
   .value("temp", "Room Temperature", "°C").icon("thermo").decimals(1);

// in loop():
dev.ui().set("temp", 29.0);

Parameters of value(...)

ParameterTypeDefault / rangeMeaning
idconst char*1 to 32 of A-Z a-z 0-9 _ -Unique name of the widget. It is the key in the API, the MQTT topic and the cloud.
labelconst char*requiredThe text on the card.
unitconst char*""The unit text. Empty for none.

Modifiers

A modifier written after a widget applies to that widget (the one added last).

ModifierMeaning
size(cols)Width in columns, 1 to 3.
icon(name)The icon of the card: home, layout-grid, bulb, fan, thermo, droplet, zap, sun, gauge, activity, chart, sliders, list, type, pointer, bell, power, lock, wifi, plug, cpu, key, shield, sparkles and more.
unit(u)The unit shown next to the value.
decimals(d)Digits after the point, 6 at most.
device(deviceId)Marks the widget as belonging to a pin device, so its card menu offers pin settings.

The default icon is activity.

Set and read the value

WhereHow
From the sketchdev.ui().set("temp", 29.0) for a number, dev.ui().set("temp", "Ready") for text. Read with number(id) or text(id). NaN shows as no value.
MQTT<base>/state/temp carries the number as text, or the text itself.

Components · 07

Chart

A history line of a number.

A chart draws the last points values of a number. The board keeps the history, so a reload still shows the line. It is two columns wide by default.

ChartC++
dev.page("Room", "home")
   .chart("temp_hist", "Temperature", "°C", 120).every(5000);

// in loop():
dev.ui().set("temp_hist", 29.0);

Parameters of chart(...)

ParameterTypeDefault / rangeMeaning
idconst char*1 to 32 of A-Z a-z 0-9 _ -Unique name of the widget. It is the key in the API, the MQTT topic and the cloud.
labelconst char*requiredThe text on the card.
unitconst char*""The unit text.
pointsuint8_t60, 10 or moreHow many samples the history keeps.

Modifiers

A modifier written after a widget applies to that widget (the one added last).

ModifierMeaning
size(cols)Width in columns, 1 to 3.
icon(name)The icon of the card: home, layout-grid, bulb, fan, thermo, droplet, zap, sun, gauge, activity, chart, sliders, list, type, pointer, bell, power, lock, wifi, plug, cpu, key, shield, sparkles and more.
unit(u)The unit shown next to the value.
decimals(d)Digits after the point, 6 at most.
every(ms)Sampling period of the chart. Default 1000 ms.
device(deviceId)Marks the widget as belonging to a pin device, so its card menu offers pin settings.

The default icon is chart.

Set and read the value

WhereHow
From the sketchdev.ui().set("temp_hist", 29.0). If at least the sample period has passed since the last sample, set adds a new one; otherwise it overwrites the last. Read the latest with number(id).
MQTT<base>/state/temp_hist carries the latest number as text.
Local HTTPGET /fn/api/v1/ui lists the history of a chart in hist.

Components · 08

Select

One choice out of a list.

A select holds one of the options you list. The first option is the start value, and only listed options are accepted.

SelectC++
dev.page("Home", "home")
   .select("mode", "Mode", {"Auto", "Manual", "Away"}, [](const String& m) {
     applyMode(m);
   });

Parameters of select(...)

ParameterTypeDefault / rangeMeaning
idconst char*1 to 32 of A-Z a-z 0-9 _ -Unique name of the widget. It is the key in the API, the MQTT topic and the cloud.
labelconst char*requiredThe text on the card.
optionsstd::initializer_list<const char*>requiredThe choices, in order. The first is the initial value.
cbstd::function<void(const String&)>nullptrCalled on the loop task with the chosen option.

Modifiers

A modifier written after a widget applies to that widget (the one added last).

ModifierMeaning
size(cols)Width in columns, 1 to 3.
icon(name)The icon of the card: home, layout-grid, bulb, fan, thermo, droplet, zap, sun, gauge, activity, chart, sliders, list, type, pointer, bell, power, lock, wifi, plug, cpu, key, shield, sparkles and more.
role(Role::Viewer|Operator|Admin)The lowest role that may change the widget. Default Operator.
device(deviceId)Marks the widget as belonging to a pin device, so its card menu offers pin settings.

The default icon is list.

Set and read the value

WhereHow
From the sketchdev.ui().set("mode", "Manual"); read with dev.ui().text("mode"). set() does not call the callback.
MQTTThe option text on <base>/state/mode; send the exact option to <base>/set/mode.
Local HTTPPOST /fn/api/v1/state with {"mode":"Manual"}.

Components · 09

Text

A text box with a send button.

A text widget holds a short text of up to 128 characters, for a name, a message for a display or a command word.

TextC++
dev.page("Home", "home")
   .text("note", "Note", [](const String& t) { lcd.line(0, t); });

Parameters of text(...)

ParameterTypeDefault / rangeMeaning
idconst char*1 to 32 of A-Z a-z 0-9 _ -Unique name of the widget. It is the key in the API, the MQTT topic and the cloud.
labelconst char*requiredThe text on the card.
cbstd::function<void(const String&)>nullptrCalled on the loop task with the new text.

Modifiers

A modifier written after a widget applies to that widget (the one added last).

ModifierMeaning
size(cols)Width in columns, 1 to 3.
icon(name)The icon of the card: home, layout-grid, bulb, fan, thermo, droplet, zap, sun, gauge, activity, chart, sliders, list, type, pointer, bell, power, lock, wifi, plug, cpu, key, shield, sparkles and more.
role(Role::Viewer|Operator|Admin)The lowest role that may change the widget. Default Operator.
device(deviceId)Marks the widget as belonging to a pin device, so its card menu offers pin settings.

The default icon is type.

Set and read the value

WhereHow
From the sketchdev.ui().set("note", "Hello"); read with dev.ui().text("note"). A number given to set() is stored as text. set() does not call the callback.
MQTTThe text on <base>/state/note; send text (at most 128 characters) to <base>/set/note.
Local HTTPPOST /fn/api/v1/state with {"note":"Hello"}.

Components · 10

Light

A Led or an RGB light with colour, brightness and 12 effects.

A light is a module: it drives its pin or pins itself (with PWM dimming), keeps its state across reboots and renders effects 50 times a second without blocking. Add it with dev.use(...) before dev.begin().

Porch LightC++
fn::Led    led(2, "led");            // single colour on a pin
fn::RgbLed pixel(48, "rgb");         // one addressable (WS2812) pin

void setup() {
  dev.use(led).use(pixel);           // before dev.begin()
  dev.begin();
  pixel.color(0xd97706).brightness(70).effect(fn::Fx::Breathe, 3000);
}

Constructors

ConstructorMeaning
fn::Led(int pin, const char* id = "led", bool activeHigh = true, bool pwm = true)A single-colour light. activeHigh = false is for a light that is on when the pin is low. With pwm = false the pin uses digitalWrite and the light is on when brightness is 25 % or more.
fn::RgbLed(int dataPin, const char* id = "rgb")One addressable light (WS2812, or the board’s built-in RGB light, RGB_BUILTIN).
fn::RgbLed(int r, int g, int b, const char* id = "rgb", bool commonAnode = false)An RGB light on three PWM pins.

Control it (from setup() or loop())

CallMeaning
on(bool v = true), off(), toggle()Switch the light.
color(uint32_t rgbHex), color(uint8_t r, uint8_t g, uint8_t b)Set the colour (0xRRGGBB) and turn on. It also ends the effects that have no colour of their own (rainbow, sunrise).
brightness(uint8_t percent)0 to 100, gamma corrected.
effect(Fx fx, uint16_t periodMs = 0, uint32_t color2 = 0xFFFFFFFF)Start an effect. Period 0 is the effect’s default; 0xFFFFFFFF for color2 keeps the current second colour.
bool effect(const String& id, uint16_t periodMs = 0)The same by effect id; false if the id is unknown.
bool apply(const JsonRef& patch, String* err = nullptr)Several settings in one call: {on, color, color2, brightness, effect, period, order}.
state()Returns {on, color, color2, brightness, fx, period}.
colorOrder(ColorOrder o), isRgb()Colour order of an addressable light: GRB (default), RGB, BRG, RBG, GBR, BGR. It is saved at once.

Effects (fn::Fx)

EffectIdColoursDefault period
Solidsolid11000 ms
Blinkblink11000 ms
Breathebreathe13000 ms
Heartbeatheartbeat11200 ms
Strobestrobe1120 ms
Rainbowrainbow0 (automatic)6000 ms
Cyclecycle22000 ms
Candlecandle11000 ms
Policepolice2800 ms
Sossos1200 ms per dot
Sunrisesunrise0 (automatic)60000 ms
Alarmalarm1400 ms

Over the network

WhereHow
Local HTTPGET /fn/api/v1/lights lists the lights and the effects. POST /fn/api/v1/lights/<id> takes any of {"on":true,"color":"#2563eb","brightness":60,"effect":"breathe","period":3000} (on may also be "toggle").
MQTT command<base>/light/<id>/set: ON, OFF, TOGGLE, #rrggbb, an effect id such as rainbow, or a JSON patch like the HTTP body.
MQTT state<base>/light/<id>/state: the light’s state as JSON, retained, at every change.
FlowsThe blocks light.set and light.effect.

Components · 11

Relay

One to 16 relay channels on pins, each a toggle; and solenoid valves.

A relay module drives pins for you. Each channel becomes a toggle widget named <id>_<n> (relay_1, relay_2, …), so the dashboard, MQTT, Home Assistant, flows and Flyght Cloud see it like any other widget, with no callback to write.

Two channelsC++
fn::Relay relays("relay", "Pump room");

void setup() {
  relays.channel(4, "Pump 1").maxOn(600);                  // active-high, off by itself after 10 minutes
  relays.channel(5, "Valve", fn::Relay::Type::ActiveLow);  // low-level trigger board
  dev.use(relays);
  dev.begin();
}

Constructor and channels

ParameterTypeDefault / rangeMeaning
Relay(id, title): idconst char*"relay", at most 15 charactersThe prefix of the widget ids. It must outlive the object: use a string literal.
Relay(id, title): titleconst char*"Relays"The title of the module, also a literal.
channel(int pin, const char* name = nullptr, Type type = Type::ActiveHigh): pinintGPIO; -1 = not wired yetAdds a channel (before begin()). A channel without a pin does nothing. At most 16 channels.
channel(...): nameconst char*"Relay <n>"The label of the toggle.
channel(...): typeTypeActiveHighActiveHigh, ActiveLow (a low-level trigger board) or Latching.
latching(int setPin, int resetPin, const char* name = nullptr)int, intrequiredA bistable relay with two coils. A coil gets a 50 ms pulse.

Settings of the channel added last

CallMeaning
bootOn(bool on = true)The channel starts on. Otherwise it starts off.
maxOn(uint32_t seconds)Switch off by itself after this long. 0 = never.
pulse(uint32_t milliseconds)Every ON lasts this long, then OFF. 0 = stays on.
interlock(uint8_t group)1 to 255. Channels of one group are never on together.
minOff(uint32_t seconds)Rest time: after it is switched off it cannot be switched on again for this long.

Module calls

CallMeaning
page(const char* name)The page of the cards. Default "Relays".
bool set(int ch, bool on)Switch a channel from the sketch. ch counts from 0 (relay_1 is channel 0). False when the channel does not exist, has no pin, or its interlock group is busy.
bool isOn(int ch), int channels()The state of a channel (from 0) and the number of channels.

Solenoid valve

Solenoid is a one-channel Relay: it closes by itself after maxOnSeconds (a coil overheats when kept on) and rests minOffSeconds before it can open again.

ParameterTypeDefault / rangeMeaning
pinintrequiredThe pin of the valve.
idconst char*"valve"The widget id prefix (the toggle is valve_1).
nameconst char*"Valve"The label.
maxOnSecondsuint32_t60Closes by itself after this long.
minOffSecondsuint32_t2Rest time before it can open again.
typeTypeActiveHighAs for a relay channel.
C++
fn::Solenoid valve(12, "valve", "Garden valve", 120, 5);   // 2 minutes at most, 5 s rest
dev.use(valve);

Components · 12

Sensors

Eight ready-made sensor modules: a card per reading, an alarm, pins that can be moved.

Each sensor is its own module: only the ones the sketch creates end up in the firmware. It reads on its own schedule, publishes a widget per reading named <id>_<key> (a gauge or a value), and shows “—” instead of a number whenever a reading cannot be trusted.

A DHT22 with an alarmC++
fn::Dht dht(4, fn::Dht::Type::Dht22);     // data pin, type, id = "dht"

void setup() {
  dht.every(5000).alarm(35.0f, 33.0f, [](bool on) { /* switch a fan */ });
  dev.use(dht);
  dev.begin();
}

The eight sensors

ClassConstructorWhat it is
DhtDht(int pin, Type type = Type::Dht22, const char* id = "dht")Temperature and humidity, DHT11 or DHT22, one pin. Type is Dht11 or Dht22.
Ds18b20Ds18b20(int pin, const char* id = "ds18b20")Temperature, one DS18B20 on a 1-Wire pin (4.7 k pull-up to 3.3 V).
UltrasonicUltrasonic(int trigPin, int echoPin, const char* id = "distance")Distance and tank level: HC-SR04, JSN-SR04T or any trig and echo module. One per firmware. The echo pin must be 3.3 V.
AnalogSensorAnalogSensor(int pin, const char* id, const char* title, const char* unit)Anything with an analog output: water level, O2, MQ gas, ACS712 current. pin must be an ADC1 pin (the library refuses the others).
DigitalSensorDigitalSensor(int pin, const char* id, const char* title)An on/off input: float switch, water leak, flame, door.
Mhz19Mhz19(int rxPin, int txPin, HardwareSerial& port = Serial2, const char* id = "co2")CO2, MH-Z19 on a UART at 9600 baud.
PzemPzem(int rxPin, int txPin, HardwareSerial& port = Serial2, uint8_t address = 0xF8, const char* id = "mains")Mains voltage, current, power, energy, frequency and power factor: PZEM-004T v3, UART, 9600 baud.
Ina219Ina219(uint8_t address = 0x40, float shuntOhm = 0.1f, TwoWire& wire = Wire, int sda = -1, int scl = -1, const char* id = "ina219")DC voltage, current and power over I2C. shuntOhm is the resistor on the board (0.1 on most breakouts, 0.01 on the 8 A ones). sda/scl of -1 use the board default.

What each one reports

ClassWidgets (id, unit)Period: default / minimum
Dht<id>_temp °C (gauge -20 to 60), <id>_hum % (gauge 0 to 100)DHT22 2000 / 2000 ms, DHT11 1000 / 1000 ms
Ds18b20<id>_temp °C (gauge -20 to 80)2000 / 1000 ms
Ultrasonic<id>_cm cm (gauge 0 to 400); with tank() also <id>_level % (gauge 0 to 100)500 / 60 ms
AnalogSensor<id>_v in the unit you give (gauge 0 to 100, 1 decimal; change with range())1000 / 100 ms
DigitalSensor<id>_state (a value showing your active or idle label)20 / 10 ms
Mhz19<id>_ppm ppm (gauge 400 to 2000)5000 / 2000 ms
Pzem<id>_v V (gauge 0 to 260), <id>_a A, <id>_w W, <id>_kwh kWh, <id>_hz Hz, <id>_pf2000 / 1000 ms
Ina219<id>_v V (gauge 0 to 32), <id>_a A, <id>_w W1000 / 100 ms

Builders and readings of each class

ClassMembers
Dhttemperature() and humidity() return the last valid value (NaN when there is none).
Ds18b20temperature()
UltrasonicairTemperature(float celsius): the speed of sound depends on the air, give the temperature if you know it (default 20 °C). tank(float emptyCm, float fullCm): the sensor on top of a tank, adds a level in percent between the two distances. distanceCm().
AnalogSensormap(float mvLo, float mvHi, float outLo, float outHi): linear, mvLo..mvHi millivolts give outLo..outHi (clamped); default 0..3300 mV to 0..100. range(float lo, float hi, uint8_t decimals): the gauge scale and decimals. hall(float zeroMv, float mvPerAmp): a hall current sensor (ACS712), amps = (mV - zeroMv) / mvPerAmp. mq(float supplyV, float loadOhm, float r0Ohm, float a, float b): a metal-oxide gas sensor on a divider, ppm = a * (Rs/R0)^b. millivolts().
DigitalSensoractiveLow(bool on = true): wired to ground when active. pullUp(bool on = true): the internal pull-up (on by default). labels(const char* active, const char* idle): the words shown, default "Active" and "Idle". debounce(uint32_t ms): default 50. onChange(std::function<void(bool)> cb): called when the state changes. active().
Mhz19ppm() returns -1 when there is no valid reading.
Pzemvolts(), amps(), watts(). The other readings are value(3) (kWh), value(4) (Hz) and value(5) (power factor).
Ina219volts(), amps(), watts()

Members every sensor has

CallMeaning
page(const char* name)The page of the cards. Default "Sensors".
every(uint32_t ms)The reading period; a value below the sensor’s minimum is raised to it.
staleAfter(uint32_t ms)After this long without a valid reading the card shows “—” and the module is degraded. Default 5 readings; 0 = never.
alarm(float high, float low = NAN, std::function<void(bool)> cb = nullptr)An alarm on the first reading: on at high or more, off at low or less (default: the same value). Adds a widget <id>_alarm that shows ALARM or OK; cb runs on the loop task when it changes, for example to switch a relay.
alarmOn()Whether the alarm is on now.
value(int reading)The last valid value of a reading, in the order they are listed (NaN when none).
A tank and a leak switchC++
fn::Ultrasonic tank(5, 18);
fn::DigitalSensor leak(21, "leak", "Water leak");

void setup() {
  tank.tank(120, 20).every(1000);                  // empty at 120 cm, full at 20 cm
  leak.activeLow().labels("WET", "Dry").onChange([](bool wet) { /* ... */ });
  dev.use(tank).use(leak);
  dev.begin();
}

Components · 13

Motors

DcMotor on an H-bridge, Esc for brushless motors, Stepper on a step/dir driver.

Each motor is its own module with its own cards (a slider or a target, and a Stop button). Every motor starts stopped, a reversal goes through zero, Stop is both a card and a call, and a motor told to run for a while stops by itself (maxRun). Add it with dev.use(...) before dev.begin().

A DC motor on an L298NC++
fn::DcMotor fan(25, 26, 27, "fan", "Fan motor");   // pwm (enable), in1, in2

void setup() {
  fan.ramp(50).maxRun(600);       // 2 s to full speed, stops by itself after 10 minutes
  dev.use(fan);
  dev.begin();
  fan.speed(40);                  // 40 % forward; negative runs backwards
}

DcMotor

A brushed DC motor on an H-bridge (L298N, TB6612, L9110, DRV8871 and similar): speed from -100 to 100 %.

ParameterTypeDefault / rangeMeaning
pwmPinintrequiredThe enable or speed input of the bridge.
in1PinintrequiredA direction input.
in2Pinint-1The second direction input. With -1 only one direction pin is used (forward = high).
idconst char*"motor"The widget id prefix.
titleconst char*"DC motor"The title of the module.
CallMeaning
ramp(float percentPerSecond)How fast the speed changes. Default 100 (1 s to full speed); 0 = no ramp.
maxRun(uint32_t seconds)Stops by itself after this long. 0 = never.
pwmFrequency(uint32_t hz)The PWM frequency. Default 20000.
page(const char* name)The page of the cards. Default "Motors".
void speed(float percent)The speed to ramp to, -100 to 100.
void stop()To zero at once, with no ramp.
float speed()The current speed.

Widgets: <id>_speed (slider -100 to 100, step 5, %), <id>_stop (button) and <id>_now (value “Output”, %).

Esc

A brushless motor through an ESC, driven by a 50 Hz servo pulse: throttle from 0 to 100 %.

ParameterTypeDefault / rangeMeaning
pinintrequiredThe signal pin of the ESC.
idconst char*"esc"The widget id prefix.
titleconst char*"Brushless motor"The title of the module.
CallMeaning
pulse(uint16_t minUs, uint16_t maxUs)The pulse range. Default 1000 to 2000 µs.
ramp(float percentPerSecond)Default 50; 0 = no ramp.
armTime(uint32_t ms)The idle pulse before it accepts a throttle. Default 3000.
maxRun(uint32_t seconds)Stops by itself after this long. 0 = never.
page(const char* name)The page of the cards. Default "Motors".
void throttle(float percent)0 to 100; ignored while the ESC is arming.
void stop()The idle pulse at once.
bool armed(), float throttle()Whether the ESC accepts a throttle; the current throttle.

Widgets: <id>_thr (slider 0 to 100, %) and <id>_stop (button).

Stepper

A step/dir driver (A4988, DRV8825, TB6600 and similar): move to a position with acceleration. Positions are in steps from where the power came on, or from setPosition().

ParameterTypeDefault / rangeMeaning
stepPinintrequiredThe step pulse pin.
dirPinintrequiredThe direction pin.
enablePinint-1The driver’s enable pin; -1 = none.
idconst char*"stepper"The widget id prefix.
titleconst char*"Stepper"The title of the module.
CallMeaning
maxSpeed(float stepsPerSecond)Default 800, up to about 5000.
acceleration(float stepsPerSecond2)Default 1600.
limits(long minPosition, long maxPosition)The allowed range. Default -10000 to 10000.
enableActiveHigh(bool on = true)By default the driver is enabled by a low level.
releaseAfter(uint32_t ms)Disable the driver this long after a move. Default 2000; 0 = keep it on.
reverse(bool on = true)Reverse the direction.
page(const char* name)The page of the cards. Default "Motors".
bool moveTo(long position)Move to a position (clamped to the limits). False if the hardware did not start; while moving, the new target is queued.
bool moveBy(long steps)Move relative to the target.
void stop()Stops at once; the position stays right.
setPosition(long p)Declare the current position (only while it is not moving).
long position(), bool moving()The position in steps; whether it is moving.

Widgets: <id>_target (slider from the minimum to the maximum limit, step 1, steps), <id>_pos (value “Position”) and <id>_stop (button).

C++
fn::Esc    prop(13, "prop", "Propeller");
fn::Stepper slide(32, 33, 14, "slide", "Slide");

void setup() {
  prop.pulse(1000, 2000).maxRun(120);
  slide.limits(0, 4000).maxSpeed(1200).enableActiveHigh();
  dev.use(prop).use(slide);
  dev.begin();
  slide.moveTo(2000);
}

Components · 14

Flows

Visual automations: triggers, logic and actions drawn as blocks in the browser.

A flow is a small program made of blocks: a trigger starts it, logic blocks decide and wait, action blocks do something. You draw it in the device’s web page (Devices, Flows: drag blocks from the palette, connect the dots, press Run). There is no C++ call that defines a flow in code: flows are data, saved in the board.

Enable the Flows moduleC++
fn::Flows flows;

void setup() {
  dev.license(FN_LICENSE_KEY);          // flows need a Pro (or higher) key
  dev.features().defaultOn("flows");    // first-boot switch ON (default OFF)
  dev.use(flows);                       // the engine and the "Flows" page
  dev.begin();
}

Editions

FeatureLowest editionDefault
flowsProoff
flowsRtosEnterpriseoff

On a Free edition only GET /fn/api/v1/flows works (it answers allowed:false); the other flow routes answer 403. When the edition allows flows but the switch is off the answer is 409: turn on Visual flows in Settings first.

The blocks

CategoryBlockSettingsOutputs
Triggertrigger.manualnone (the Run button)then
Triggertrigger.bootnone (once, when the app is ready)then
Triggertrigger.intervalevery ms, default 1000; 50 or morethen
Triggertrigger.widgetwidget; when any, on, off, above, below; valuethen
Triggertrigger.mqtttopic, default flyght/cmd ({base} allowed)then
Triggertrigger.httpname, default doorbell (POST /flows/hook/<name>)then
Triggertrigger.aperturefeed people or ppe; camera (empty = any); fire changes or every updatethen
Triggertrigger.buttonpin; edge press, release, change; pullup (default true)then
Logiclogic.delayms, default 1000then
Logiclogic.ifop ==, !=, >, <, contains, is on, is off; valueyes, no
Logiclogic.repeattimes, default 3each, done
Logiclogic.splitmode parallel or serial1, 2, 3
Logicvalue.setvalue, default {value}then
Actionaction.logmessagethen
Actionwidget.setwidget, valuethen
Actiongpio.writepin (default 2); level high, low, togglethen
Actionmqtt.publishtopic (default {base}/event), payload (default {value}), retainthen
Actionhttp.requestmethod GET or POST; url; bodyok, failed (value = status)
Devicelight.setlight, power on, off, toggle, keep; color; brightnessthen
Devicelight.effectlight, effect, speed ms (0 = default), color, color2then
Devicelcd.printrow (default 0), textthen
Devicetft.textx, y, text, color, size, clearthen
Devicemcu.sendline, default SET {value}then

Texts may use {value}, {uptime}, {time}, {id} and {name}; MQTT topics also {base}. Several wires from one output run in parallel; logic.split in serial mode runs outputs 1, 2 and 3 one after another, and logic.repeat runs each N times then done.

Limits

WhatLimit
Flows on a board8
Blocks per flow / wires per flow40 / 80
Runs in flight per flow16
Block id / flow name / a setting1 to 12 characters / 40 / 200
Body of a save16384 bytes
Work per step48 block runs, so a loop without a Wait cannot freeze the board

Flow data and the API

PUT /fn/api/v1/flows/newJSON
{ "name": "Traffic light", "on": true, "rtos": false,
  "nodes": [
    { "id": "n1", "type": "trigger.manual", "x": 30, "y": 120, "p": {} },
    { "id": "n2", "type": "logic.split", "x": 270, "y": 110, "p": { "mode": "serial" } },
    { "id": "n3", "type": "light.set", "x": 520, "y": 0,
      "p": { "light": "builtin", "power": "on", "color": "#ef4444" } }
  ],
  "wires": [ ["n1", 0, "n2"], ["n2", 0, "n3"] ] }

CallMeaning
GET /fn/api/v1/flowsThe flows, allowed, on, the maximum.
GET /fn/api/v1/flows/blocks, GET /flows/<id>The catalogue of blocks; one flow.
PUT /fn/api/v1/flows/new or /flows/<id>Create or save (admin). A wire is [fromBlockId, outputIndex, toBlockId]. new answers {"ok":true,"id":"f3"}; 409 at 8 flows.
DELETE /fn/api/v1/flows/<id>Delete a flow (admin).
POST /fn/api/v1/flows/<id>/runRun a flow (operator); 409 if it has no trigger block.
POST /fn/api/v1/flows/hook/<name>Fire the trigger.http blocks of that name; the whole request body becomes {value}.
POST /fn/api/v1/flows/aperture{"feed":"people","camera":"gate-1","count":7} or {"feed":"ppe","camera":"gate-1","violations":2} for trigger.aperture.

Flows on their own thread (Enterprise)

Each flow has a boolean rtos. It needs the Enterprise edition and the flowsRtos switch on; otherwise it is reset to false and the flow runs on the main loop. A flow with rtos true gets its own FreeRTOS task for its logic blocks (Wait, If, Repeat, Split, Set value). All other blocks are handed to the main loop task, so GPIO and light changes still run there. The task’s stack, priority and period are fixed by the library; there is no parameter for them.