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.
- ToggleAn on/off switch.
- ButtonA press that runs a function.
- SliderA number between a minimum and a maximum.
- GaugeA read-only dial for a measurement.
- ValueA read-only number or text.
- ChartA history line of a number.
- SelectOne choice out of a list.
- TextA text box with a send button.
- LightA Led or RGB light with effects.
- RelayUp to 16 channels and solenoid valves.
- SensorsEight ready-made sensor modules.
- MotorsDC motor, brushless ESC and stepper.
- FlowsVisual automations made of blocks.
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.
dev.page("Home", "home")
.toggle("fan", "Ceiling Fan", [](bool on) { digitalWrite(FAN_PIN, on); })
.icon("fan");Parameters of toggle(...)
| Parameter | Type | Default / range | Meaning |
|---|---|---|---|
id | const 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. |
label | const char* | required | The text on the card. |
cb | std::function<void(bool)> | nullptr | Called on the loop task with the new state. Optional. |
Modifiers
A modifier written after a widget applies to that widget (the one added last).
| Modifier | Meaning |
|---|---|
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
| Where | How |
|---|---|
| From the sketch | dev.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. |
| MQTT | State on <base>/state/fan: ON or OFF. Command on <base>/set/fan: ON, OFF or TOGGLE. |
| Local HTTP | POST /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. |
| Cloud | The same text on <prefix>/<DEVICE_ID>/state/fan and <prefix>/<DEVICE_ID>/set/fan. |
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.
dev.page("Home", "home")
.slider("bright", "Brightness", 0, 100, 5, [](float v) { analogWrite(LED_PIN, v * 2.55); })
.unit("%");Parameters of slider(...)
| Parameter | Type | Default / range | Meaning |
|---|---|---|---|
id | const 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. |
label | const char* | required | The text on the card. |
min | float | required | The lowest value; also the start value. |
max | float | required | The highest value. |
step | float | 1 | The size of one step. Decimals follow it: 0 when step is 1 or more, 1 from 0.1, else 2. |
cb | std::function<void(float)> | nullptr | Called on the loop task with the new value. |
Modifiers
A modifier written after a widget applies to that widget (the one added last).
| Modifier | Meaning |
|---|---|
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
| Where | How |
|---|---|
| From the sketch | dev.ui().set("bright", 70); read with dev.ui().number("bright"). set() clamps and snaps, and does not call the callback. |
| MQTT | A number as text with the widget’s decimals: <base>/state/bright is 70; send 70 to <base>/set/bright. |
| Local HTTP | POST /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.
dev.page("Garden", "sprout")
.gauge("soil", "Soil moisture", "%", 0, 100);
// in loop():
dev.ui().set("soil", readSoilPercent());Parameters of gauge(...)
| Parameter | Type | Default / range | Meaning |
|---|---|---|---|
id | const 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. |
label | const char* | required | The text on the card. |
unit | const char* | required | The unit text, for example "%" or "°C". |
min | float | required | The value at the start of the dial. |
max | float | required | The value at the end of the dial. |
Modifiers
A modifier written after a widget applies to that widget (the one added last).
| Modifier | Meaning |
|---|---|
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
| Where | How |
|---|---|
| From the sketch | dev.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 HTTP | GET /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”.
dev.page("Room", "home")
.value("temp", "Room Temperature", "°C").icon("thermo").decimals(1);
// in loop():
dev.ui().set("temp", 29.0);Parameters of value(...)
| Parameter | Type | Default / range | Meaning |
|---|---|---|---|
id | const 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. |
label | const char* | required | The text on the card. |
unit | const char* | "" | The unit text. Empty for none. |
Modifiers
A modifier written after a widget applies to that widget (the one added last).
| Modifier | Meaning |
|---|---|
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
| Where | How |
|---|---|
| From the sketch | dev.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.
dev.page("Room", "home")
.chart("temp_hist", "Temperature", "°C", 120).every(5000);
// in loop():
dev.ui().set("temp_hist", 29.0);Parameters of chart(...)
| Parameter | Type | Default / range | Meaning |
|---|---|---|---|
id | const 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. |
label | const char* | required | The text on the card. |
unit | const char* | "" | The unit text. |
points | uint8_t | 60, 10 or more | How many samples the history keeps. |
Modifiers
A modifier written after a widget applies to that widget (the one added last).
| Modifier | Meaning |
|---|---|
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
| Where | How |
|---|---|
| From the sketch | dev.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 HTTP | GET /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.
dev.page("Home", "home")
.select("mode", "Mode", {"Auto", "Manual", "Away"}, [](const String& m) {
applyMode(m);
});Parameters of select(...)
| Parameter | Type | Default / range | Meaning |
|---|---|---|---|
id | const 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. |
label | const char* | required | The text on the card. |
options | std::initializer_list<const char*> | required | The choices, in order. The first is the initial value. |
cb | std::function<void(const String&)> | nullptr | Called on the loop task with the chosen option. |
Modifiers
A modifier written after a widget applies to that widget (the one added last).
| Modifier | Meaning |
|---|---|
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
| Where | How |
|---|---|
| From the sketch | dev.ui().set("mode", "Manual"); read with dev.ui().text("mode"). set() does not call the callback. |
| MQTT | The option text on <base>/state/mode; send the exact option to <base>/set/mode. |
| Local HTTP | POST /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.
dev.page("Home", "home")
.text("note", "Note", [](const String& t) { lcd.line(0, t); });Parameters of text(...)
| Parameter | Type | Default / range | Meaning |
|---|---|---|---|
id | const 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. |
label | const char* | required | The text on the card. |
cb | std::function<void(const String&)> | nullptr | Called on the loop task with the new text. |
Modifiers
A modifier written after a widget applies to that widget (the one added last).
| Modifier | Meaning |
|---|---|
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
| Where | How |
|---|---|
| From the sketch | dev.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. |
| MQTT | The text on <base>/state/note; send text (at most 128 characters) to <base>/set/note. |
| Local HTTP | POST /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().
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
| Constructor | Meaning |
|---|---|
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())
| Call | Meaning |
|---|---|
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)
| Effect | Id | Colours | Default period |
|---|---|---|---|
Solid | solid | 1 | 1000 ms |
Blink | blink | 1 | 1000 ms |
Breathe | breathe | 1 | 3000 ms |
Heartbeat | heartbeat | 1 | 1200 ms |
Strobe | strobe | 1 | 120 ms |
Rainbow | rainbow | 0 (automatic) | 6000 ms |
Cycle | cycle | 2 | 2000 ms |
Candle | candle | 1 | 1000 ms |
Police | police | 2 | 800 ms |
Sos | sos | 1 | 200 ms per dot |
Sunrise | sunrise | 0 (automatic) | 60000 ms |
Alarm | alarm | 1 | 400 ms |
Over the network
| Where | How |
|---|---|
| Local HTTP | GET /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. |
| Flows | The 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.
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
| Parameter | Type | Default / range | Meaning |
|---|---|---|---|
Relay(id, title): id | const char* | "relay", at most 15 characters | The prefix of the widget ids. It must outlive the object: use a string literal. |
Relay(id, title): title | const char* | "Relays" | The title of the module, also a literal. |
channel(int pin, const char* name = nullptr, Type type = Type::ActiveHigh): pin | int | GPIO; -1 = not wired yet | Adds a channel (before begin()). A channel without a pin does nothing. At most 16 channels. |
channel(...): name | const char* | "Relay <n>" | The label of the toggle. |
channel(...): type | Type | ActiveHigh | ActiveHigh, ActiveLow (a low-level trigger board) or Latching. |
latching(int setPin, int resetPin, const char* name = nullptr) | int, int | required | A bistable relay with two coils. A coil gets a 50 ms pulse. |
Settings of the channel added last
| Call | Meaning |
|---|---|
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
| Call | Meaning |
|---|---|
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.
| Parameter | Type | Default / range | Meaning |
|---|---|---|---|
pin | int | required | The pin of the valve. |
id | const char* | "valve" | The widget id prefix (the toggle is valve_1). |
name | const char* | "Valve" | The label. |
maxOnSeconds | uint32_t | 60 | Closes by itself after this long. |
minOffSeconds | uint32_t | 2 | Rest time before it can open again. |
type | Type | ActiveHigh | As for a relay channel. |
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.
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
| Class | Constructor | What it is |
|---|---|---|
Dht | Dht(int pin, Type type = Type::Dht22, const char* id = "dht") | Temperature and humidity, DHT11 or DHT22, one pin. Type is Dht11 or Dht22. |
Ds18b20 | Ds18b20(int pin, const char* id = "ds18b20") | Temperature, one DS18B20 on a 1-Wire pin (4.7 k pull-up to 3.3 V). |
Ultrasonic | Ultrasonic(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. |
AnalogSensor | AnalogSensor(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). |
DigitalSensor | DigitalSensor(int pin, const char* id, const char* title) | An on/off input: float switch, water leak, flame, door. |
Mhz19 | Mhz19(int rxPin, int txPin, HardwareSerial& port = Serial2, const char* id = "co2") | CO2, MH-Z19 on a UART at 9600 baud. |
Pzem | Pzem(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. |
Ina219 | Ina219(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
| Class | Widgets (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>_pf | 2000 / 1000 ms |
Ina219 | <id>_v V (gauge 0 to 32), <id>_a A, <id>_w W | 1000 / 100 ms |
Builders and readings of each class
| Class | Members |
|---|---|
Dht | temperature() and humidity() return the last valid value (NaN when there is none). |
Ds18b20 | temperature() |
Ultrasonic | airTemperature(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(). |
AnalogSensor | map(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(). |
DigitalSensor | activeLow(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(). |
Mhz19 | ppm() returns -1 when there is no valid reading. |
Pzem | volts(), amps(), watts(). The other readings are value(3) (kWh), value(4) (Hz) and value(5) (power factor). |
Ina219 | volts(), amps(), watts() |
Members every sensor has
| Call | Meaning |
|---|---|
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). |
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().
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 %.
| Parameter | Type | Default / range | Meaning |
|---|---|---|---|
pwmPin | int | required | The enable or speed input of the bridge. |
in1Pin | int | required | A direction input. |
in2Pin | int | -1 | The second direction input. With -1 only one direction pin is used (forward = high). |
id | const char* | "motor" | The widget id prefix. |
title | const char* | "DC motor" | The title of the module. |
| Call | Meaning |
|---|---|
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 %.
| Parameter | Type | Default / range | Meaning |
|---|---|---|---|
pin | int | required | The signal pin of the ESC. |
id | const char* | "esc" | The widget id prefix. |
title | const char* | "Brushless motor" | The title of the module. |
| Call | Meaning |
|---|---|
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().
| Parameter | Type | Default / range | Meaning |
|---|---|---|---|
stepPin | int | required | The step pulse pin. |
dirPin | int | required | The direction pin. |
enablePin | int | -1 | The driver’s enable pin; -1 = none. |
id | const char* | "stepper" | The widget id prefix. |
title | const char* | "Stepper" | The title of the module. |
| Call | Meaning |
|---|---|
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).
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.
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
| Feature | Lowest edition | Default |
|---|---|---|
flows | Pro | off |
flowsRtos | Enterprise | off |
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
| Category | Block | Settings | Outputs |
|---|---|---|---|
| Trigger | trigger.manual | none (the Run button) | then |
| Trigger | trigger.boot | none (once, when the app is ready) | then |
| Trigger | trigger.interval | every ms, default 1000; 50 or more | then |
| Trigger | trigger.widget | widget; when any, on, off, above, below; value | then |
| Trigger | trigger.mqtt | topic, default flyght/cmd ({base} allowed) | then |
| Trigger | trigger.http | name, default doorbell (POST /flows/hook/<name>) | then |
| Trigger | trigger.aperture | feed people or ppe; camera (empty = any); fire changes or every update | then |
| Trigger | trigger.button | pin; edge press, release, change; pullup (default true) | then |
| Logic | logic.delay | ms, default 1000 | then |
| Logic | logic.if | op ==, !=, >, <, contains, is on, is off; value | yes, no |
| Logic | logic.repeat | times, default 3 | each, done |
| Logic | logic.split | mode parallel or serial | 1, 2, 3 |
| Logic | value.set | value, default {value} | then |
| Action | action.log | message | then |
| Action | widget.set | widget, value | then |
| Action | gpio.write | pin (default 2); level high, low, toggle | then |
| Action | mqtt.publish | topic (default {base}/event), payload (default {value}), retain | then |
| Action | http.request | method GET or POST; url; body | ok, failed (value = status) |
| Device | light.set | light, power on, off, toggle, keep; color; brightness | then |
| Device | light.effect | light, effect, speed ms (0 = default), color, color2 | then |
| Device | lcd.print | row (default 0), text | then |
| Device | tft.text | x, y, text, color, size, clear | then |
| Device | mcu.send | line, 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
| What | Limit |
|---|---|
| Flows on a board | 8 |
| Blocks per flow / wires per flow | 40 / 80 |
| Runs in flight per flow | 16 |
| Block id / flow name / a setting | 1 to 12 characters / 40 / 200 |
| Body of a save | 16384 bytes |
| Work per step | 48 block runs, so a loop without a Wait cannot freeze the board |
Flow data and the API
{ "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"] ] }| Call | Meaning |
|---|---|
GET /fn/api/v1/flows | The 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>/run | Run 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.