FlyghtEdge · Flyght Cloud
Documentation
From installing the library to a device you watch and control from anywhere, step by step.
Library · 01
Library: the device
fn::Device, its settings, its names and addresses.
fn::Device is the plug-and-play entry point: it is an fn::App with the usual modules already in place (web server, login, Wi-Fi, the setup access point and captive portal, mDNS, the dashboard, MQTT, webhook, cloud, system). Everything is in namespace fn, and #include <FlyghtEdge.h> brings it in.
#include <FlyghtEdge.h>
fn::Device dev("smart-lamp", "1.0.0"); // slug (AP name, hostname, MQTT) and your firmware version
void setup() {
dev.ap().ssid("{name}-{mac4}").password(""); // setup Wi-Fi: open by default
dev.wifi().add("HomeWiFi", "secret", 80); // saved network, priority 0..100
dev.auth().defaultPassword("change-me"); // skips the first-boot wizard
dev.system().timezone("WIB-7"); // POSIX time zone
dev.mqtt().broker("mqtt://192.168.1.10:1883").homeAssistant(true);
dev.license("fnk_live_..."); // before begin()
dev.cloud().enable(); // optional: Flyght Cloud
dev.begin(); // starts every module in dependency order
}
void loop() { dev.loop(); }Device and App
| Member | Meaning |
|---|---|
Device(const char* name, const char* version = "1.0.0") | name is the product slug (AP name, hostname, MQTT {name}, model); version is your firmware version, shown in the dashboard and the mDNS record. |
Page& page(const char* name, const char* icon = "layout-grid") | A dashboard page; the same name twice gives the same page. Same as ui().page(...). |
App& license(const char* key) | The license key, before begin(). Without a valid key the device runs in evaluation mode. |
void begin() / void loop() | begin() adds the preset modules and starts them in dependency order; loop() runs posted jobs, the scheduler and the modules. |
App& use(Module&) | Add a module that is not in the preset (flows, lights, relays, sensors, motors). Before begin(); after it the call is ignored. |
bool post(std::function<void()>) | Run a function on the loop task from another task or an interrupt (queue of 32; false when full). |
deviceId(), name(), version(), displayName(), hostname() | deviceId() is 12 upper-case hex digits of the factory MAC. setDisplayName(s) (40 characters) and setHostname(s) change the names. |
sched().every(ms, fn, runNow = false), after(ms, fn), cancel(id) | A scheduler that runs on the loop task. |
bus().on(fn::ev::StaGotIp, [](const fn::Event& e){}) | Events: AppReady, StaConnected, StaGotIp, StaDisconnected, ApStarted, ApStopped, MdnsReady, MqttConnected, MqttDisconnected, WidgetChanged, ConfigChanged, Login, TimeSynced. |
restart(reason, delayMs = 800), factoryReset(), uptimeSec() | Lifecycle helpers. |
Settings (code values are the first-boot defaults)
Settings made in the dashboard are saved in the board and win over the code afterwards.
| Module | Builders | Default |
|---|---|---|
ap() | ssid(tpl), password(p), mode(ApMode::Always|Fallback|Off), ip(IPAddress), channel(n), maxClients(n) | SSID {name}-{mac4}, open, always on, 192.168.4.1, channel 1, 4 clients. A password needs 8 characters or more, else the AP stays open. |
captive() | mode(CaptiveMode::UntilLogin|Always) | Until login. A DNS catch-all (UDP 53) while the AP is up, and the operating systems’ connectivity checks are answered so the phone opens the page. |
wifi() | add(ssid, pass, priority = 50), connectTimeout(sec), backoff(baseSec, maxSec), connectNow(ssid, pass), reconnect(), connected(), ssid() | Up to 8 saved networks, higher priority first; connect timeout 15 s, retry backoff 15 to 900 s. |
mdns() | service(name, proto, port), refreshEvery(minutes), restart(reason), ready() | Hostname from dev.setHostname(s) or PUT /fn/api/v1/mdns; refresh every 15 minutes. |
auth() | defaultPassword(p), allowAnonymous(on, role = Role::Viewer), sessionDays(n) | No fixed password: the first boot runs a setup wizard (6 characters or more), or defaultPassword skips it. Sessions last 30 days. Five wrong logins lock for 30 s, doubling. |
ui() | accent(cssColor), pushInterval(ms) | Changes are pushed every 150 ms. |
mqtt() | broker(uri), credentials(user, pass), baseTopic(tpl), homeAssistant(on), publish(topic, payload, retain, qos), subscribe(topic, cb) | Off until a broker is set. Base topic flyght/{id}. URIs: mqtt, mqtts, ws, wss. |
webhook() | url(u), secret(s), interval(sec), caCert(pem), send(event, extra) | Interval 0 is off (5 to 86400 s from HTTP). |
system() | ntp(server1, server2), timezone(posixTz) | pool.ntp.org, UTC0; for Indonesia west WIB-7. |
cloud() | enable(on = true), site(url), apiKey(key), state(), connected(), activateUrl() | Off by default. The key defaults to the one given to license(). States: Off, NoNetwork, NeedKey, Claiming, Fetching, Connecting, Online, Retry, Stopped. |
Names and addresses
| What | Value |
|---|---|
| Setup Wi-Fi (access point) | {name}-{mac4}, for example smart-lamp-C2D3 (mac4 in upper case); the board is at http://192.168.4.1/. |
| mDNS hostname | {name}-{mac4} made lowercase, letters and digits with single dashes, at most 63 characters: http://smart-lamp-c2d3.local/. Change it with dev.setHostname() or PUT /fn/api/v1/mdns. |
| mDNS services | _http._tcp and _flyght._tcp, both on port 80. The _flyght._tcp record carries id (device id), model, fw, fn (library version), api (1) and mods (running modules), so a script can discover every board on the network. |
| By IP | The station IP is on the Wi-Fi page, in GET /fn/api/v1/sys (net.staIp) and in the MQTT info message. |
| Port | HTTP and WebSocket on 80 only (the Device preset cannot change it; use fn::App with fn::Web web(8080)). There is no HTTPS server on the board. |
Library · 02
Library: widgets and values
Every widget with its parameters, and how to push and read values.
A widget is one line on a page. Each method returns the page, so calls chain, and a modifier after a widget applies to that widget. Widget ids are unique and, for the cloud, 1 to 32 characters of letters, digits, _ and -.
Widget methods
| Method | Value | Notes |
|---|---|---|
toggle(id, label, cb(bool) = nullptr) | on or off | Writable. The callback receives the new state. |
button(id, label, cb()) | none (MQTT payload PRESS) | Writable; the callback is required. Never published as a state. |
slider(id, label, min, max, step = 1, cb(float) = nullptr) | number, clamped and snapped to step | Writable. Decimals: 0 when step is 1 or more, 1 from 0.1, else 2. |
gauge(id, label, unit, min, max) | number | Read-only (a write answers 422). |
value(id, label, unit = "") | number or text | Read-only. NaN shows as no value. |
chart(id, label, unit = "", points = 60) | number, with history | Read-only. points is the history length (10 or more); sampling period 1000 ms, change with .every(ms). |
select(id, label, {"A","B"}, cb(const String&) = nullptr) | one of the options | Writable; only the listed options are accepted, the first is the start value. |
text(id, label, cb(const String&) = nullptr) | text up to 128 characters | Writable. |
Modifiers (apply to the widget added last)
| Modifier | Meaning |
|---|---|
size(cols) | Width in columns, 1 to 3. |
icon(name) | An icon: 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), decimals(d) | The unit text; digits after the point (6 at most). |
role(Role::Viewer|Operator|Admin) | The lowest role that may change it. Default Operator. |
every(ms) | Sampling period of a chart. |
device(deviceId) | Marks the widget as belonging to a pin device, so its card menu offers pin settings. |
dev.page("Garden", "sprout")
.toggle("pump", "Pump", [](bool on) { digitalWrite(PUMP, on); }).icon("droplet")
.slider("fan", "Fan", 0, 100, 5, [](float v) { analogWrite(FAN, v * 2.55); }).unit("%")
.select("mode", "Mode", {"Auto", "Manual", "Away"}, [](const String& m) { /* ... */ })
.gauge("soil", "Soil moisture", "%", 0, 100)
.chart("temp", "Temperature", "°C", 120).every(5000).size(2)
.button("ring", "Ring", [] { /* ... */ })
.text("note", "Note", [](const String& t) { /* ... */ });Push and read values (from loop())
| Call | Meaning |
|---|---|
dev.ui().set(id, value) | Set a widget from the sketch (double, float, int, bool, text). It is pushed live to browsers, MQTT, the webhook and the cloud. It does not call the widget’s callback. |
dev.ui().number(id), flag(id), text(id) | Read the current value. |
bool apply(id, raw, Source src, String* err) | Parse a text ("on", "42", "toggle") and run the callback, as if a user had changed it. Source is Code, Web, Mqtt, Http or Cloud. |
dev.ui().listen([](const Widget& w, Source s){}) | Called after every change, from any source. |
Lights and effects
fn::Led led(2, "led"); // pin, id, activeHigh = true, pwm = true
fn::RgbLed pixel(48, "rgb"); // one addressable (WS2812) pin
fn::RgbLed strip(25, 26, 27, "strip"); // three PWM pins (r, g, b, id, commonAnode = false)
dev.use(led).use(pixel); // before dev.begin()
pixel.color(0x2563eb).brightness(60).effect(fn::Fx::Breathe, 3000);| Call | Meaning |
|---|---|
on(v = true), off(), toggle() | Switch the light. |
color(0xRRGGBB), color(r, g, b) | Set the colour and turn on. |
brightness(percent) | 0 to 100, gamma corrected. |
effect(Fx, periodMs = 0, color2 = 0xFFFFFFFF) | Start an effect; period 0 is the effect’s default; effect(id, periodMs) takes the id as text. |
apply(json patch) | {on, color, color2, brightness, effect, period, order} in one call. |
colorOrder(ColorOrder) | GRB (default), RGB, BRG, RBG, GBR, BGR, for addressable lights. |
| Effect | Colours | Default period |
|---|---|---|
| solid, blink, strobe, candle, alarm, sos | 1 | 1000, 1000, 120, 1000, 400, 200 ms |
| breathe, heartbeat | 1 | 3000, 1200 ms |
| cycle, police | 2 | 2000, 800 ms |
| rainbow, sunrise | automatic | 6000, 60000 ms |
Library · 03
Library: flows, pins and modules
Visual flows, RTOS flows, what is bound to a pin, and the ready-made modules.
Visual flows (Pro)
A flow is a small program drawn as blocks and wires: a trigger starts it, logic blocks decide, action blocks do things. You draw it on the device’s own web page (Devices › Flows: palette, drag blocks, wire the dots, Run) or send it as data with PUT /fn/api/v1/flows/new. There is no C++ call that defines a flow: flows are data, saved on the board.
fn::Flows flows;
dev.license(FN_LICENSE_KEY); // a Pro key
dev.features().defaultOn("flows"); // switch it on at first boot (it is off by default)
dev.use(flows); // before dev.begin()| Edition | What the flow engine gives |
|---|---|
| Free | You can list flows (GET /flows says not allowed); no editing. |
| Pro | Visual flows: up to 8 flows, 40 blocks and 80 wires each, switched on in Settings or by features().defaultOn("flows"). |
| Enterprise | Flows on their own RTOS thread (next section). |
| Block | Parameters | Outputs |
|---|---|---|
trigger.manual, trigger.boot | none (Run button; once at start-up) | then |
trigger.interval | every in ms (50 or more) | then |
trigger.widget | widget, when (any, on, off, above, below), value | then |
trigger.mqtt, trigger.http | topic ({base} allowed); name of the hook | then |
trigger.button | pin, edge (press, release, change), pullup | then |
trigger.aperture | feed (people, ppe), camera, fire | then |
logic.delay | ms | then |
logic.if | op (==, !=, >, <, contains, is on, is off), value | yes, no |
logic.repeat | times | each, done |
logic.split | mode (parallel, serial) | 1, 2, 3 |
value.set | value ({value} is the value in flight) | then |
action.log, widget.set | message; widget, value | then |
gpio.write | pin, level (high, low, toggle) | then |
mqtt.publish | topic, payload, retain | then |
http.request | method (GET, POST), url, body | ok, failed |
light.set, light.effect | light, power, color, brightness; effect, speed, color2 | then |
lcd.print, tft.text, mcu.send | row, text; x, y, text, color, size; line | then |
{ "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"] ] }- A wire is
[fromBlockId, outputIndex, toBlockId]. Several wires from one output run in parallel;logic.splitwithserialruns its outputs one after another. - A flow step may run 48 blocks at most, so a loop without a wait cannot freeze the board.
- Pins are checked when you save: flash pins, USB pins and pins a module already uses are refused, and so are input-only pins for
gpio.write. - Your own blocks:
fn::flowNode(NodeDef)with a result ofnext(out),wait(ms, out),stop()or async.
RTOS flows (Enterprise)
On an Enterprise key with the flowsRtos feature on, a flow can be given its own FreeRTOS task: set "rtos": true in the flow (the editor has a switch). Its logic blocks (Wait, If, Repeat, Split, Set value) then run on that task and wait there, so a long Wait in one flow never holds up the main loop or another flow.
- The task is created by the library with a 6144 byte stack at priority 1, not pinned to a core, and loops every 5 ms. There is no setting for these.
- Only logic blocks run on the flow’s task. Action and device blocks (gpio, light, mqtt, widget) are handed to the main loop, so pin and light changes still happen there.
http.requestruns on its own task and resumes the flow. - Without the Enterprise edition the flag is reset and the flow runs on the main loop.
What is bound to a pin
| Module | Signature | What it gives |
|---|---|---|
| Relay | fn::Relay r; r.channel(pin, name, Type::ActiveHigh|ActiveLow|Latching); latching(setPin, resetPin, name); per channel bootOn(), maxOn(sec), pulse(ms), interlock(group), minOff(sec); set(ch, on), isOn(ch) | Up to 16 channels. Each channel makes a toggle widget <id>_<n> (for example relay_1) bound to its pin, with no callback to write, safe limits, and the same control from the dashboard, HTTP, MQTT, flows and the cloud. |
| Solenoid | fn::Solenoid(pin, id, name, maxOnSeconds = 60, minOffSeconds = 2, Type) | A one-channel relay with safe limits. |
| Led, RgbLed | fn::Led(pin, id, activeHigh, pwm), fn::RgbLed(dataPin, id), fn::RgbLed(r, g, b, id, commonAnode) | The module drives the pin(s): PWM dimming, colours and effects. |
| Sensors | Dht(pin, type, id), Ds18b20(pin, id), Ultrasonic(trig, echo, id), AnalogSensor(adc1Pin, id, title, unit), DigitalSensor(pin, id, title), Mhz19, Pzem, Ina219 | The pin is read and published for you as widgets <id>_<reading>. Common calls: every(ms), staleAfter(ms), page(name), alarm(high, low, cb). |
| Motors | DcMotor(pwmPin, in1, in2, id, title), Esc(pin, id, title), Stepper(step, dir, enable, id, title) | Speed, throttle or position cards with a Stop button and safe ramps. |
| Other devices | Bno055, LcdI2c, SdCard, TftSpi + Tft, Gps(rx, tx, baud), McuLink(rx, tx, baud) | IMU, LCD, SD card, display, GPS (map, track) and a serial link to another microcontroller. |
fn::Relay relay("relay", "Pumps");
relay.channel(26, "Pump A").maxOn(600); // toggle widget "relay_1"
relay.channel(27, "Pump B", fn::Relay::Type::ActiveLow); // toggle widget "relay_2"
dev.use(relay); // before dev.begin()Pins can also be moved while the board runs: an administrator opens the card’s menu › Settings, or sends PUT /fn/api/v1/devices/<id>/pins with {"pins": {"<key>": 4}, "confirm": "<device name>"} (confirmation is needed when the device switches a load). GPIO pins apply at once; UART and I2C pins from the next boot. The pin rules refuse flash and USB pins, input-only pins for outputs, and anything but ADC1 for analogue reads.