FlyghtEdge · Flyght Cloud
Documentation
From installing the library to a device you watch and control from anywhere, step by step.
Local API · 01
Local API: by IP or mDNS
Call the board directly on your network, with HTTP, WebSocket or MQTT.
The board serves a JSON API of its own, with or without the cloud. Reach it by IP (http://192.168.1.42/) or by its mDNS name (http://smart-lamp-c2d3.local/), on port 80. All paths start with /fn/api/v1; responses are JSON with Cache-Control: no-store and CORS open (Access-Control-Allow-Origin: *); errors are {"error": "..."}.
Authentication
- Send the token as
Authorization: Bearer <token>, or as the cookiefn_s, or as?t=<token>(needed for a WebSocket from a browser). - A session token comes from
POST /auth/login(valid 30 days). An API token starts withfn_, is made by an administrator withPOST /auth/tokens(name and role, shown once, at most 8) and is meant for scripts. - Roles: viewer reads, operator also changes widgets, admin also changes settings. No token is 401, too low a role is 403. After the 30 minute evaluation every route except
GET /auth/stateanswers 402.
H=smart-lamp-c2d3.local # or the device IP
curl -s http://$H/fn/api/v1/auth/state # who it is, no login needed
curl -s -c jar -X POST -H "Content-Type: application/json" \
-d '{"password":"secret1"}' http://$H/fn/api/v1/auth/login # -> {"ok":true,"role":"admin","token":"...","exp":...}
curl -s -b jar -X POST -H "Content-Type: application/json" \
-d '{"name":"scripts","role":"operator"}' http://$H/fn/api/v1/auth/tokens # -> {"token":"fn_...", ...} shown once
TOKEN=fn_...Values and widgets
| Call | Role | Meaning |
|---|---|---|
GET /ui | viewer | The dashboard schema: pages and every widget with type, label, unit, min, max, step, options, write role. |
GET /state | viewer | {"values": {id: value}, "ts": unix, "uptime": s}; toggles are booleans, buttons are left out. |
POST /state | widget role | Body {"light": true, "fan": 40}. Every value is checked first, then applied together. 403 role, 404 unknown widget, 422 read-only or bad value. |
POST /ui/w/<id> | widget role | Body {"value": ...}; null or no value toggles a toggle or presses a button. |
PUT /ui/layout, DELETE /ui/layout?page=<id> | admin | Order, sizes (1 to 3) and hidden widgets of a page; the delete resets it (no page resets all). |
curl -s -H "Authorization: Bearer $TOKEN" http://$H/fn/api/v1/state
curl -s -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"light": true, "fan": 40}' http://$H/fn/api/v1/state
curl -s -X POST -H "Authorization: Bearer $TOKEN" -d '{"value": null}' http://$H/fn/api/v1/ui/w/bellLights, flows and the system
| Call | Role | Meaning |
|---|---|---|
GET /lights, POST /lights/<id> | viewer, operator | Read the lights and effects; set {"on": true|false|"toggle", "color": "#rrggbb", "color2", "brightness": 0..100, "effect": "rainbow", "period": ms}. |
GET /flows, GET /flows/<id>, GET /flows/blocks | viewer | List flows, one flow, and the block catalogue. |
PUT /flows/new|<id>, DELETE /flows/<id> | admin | Save or delete a flow (Pro). 403 on Free, 409 when flows are off or 8 exist, 422 with the reason. |
POST /flows/<id>/run, POST /flows/hook/<name> | operator | Run a flow; fire a trigger.http hook. The whole raw body becomes the flow’s {value}. |
GET /sys, GET /sys/health | viewer | Name, model, versions, chip, memory, uptime, IP, MAC; module health. |
GET /sys/logs?since=<seq>, POST /sys/restart | admin | The log lines since a sequence number; restart. |
POST /sys/ota | admin | A .bin as the raw body (1024 bytes or more); the board restarts. |
POST /sys/factory-reset | admin | Body {"confirm": "RESET"}. |
Network, MQTT, webhook and cloud
| Call | Meaning |
|---|---|
GET /wifi, PUT /wifi/networks, POST /wifi/connect, POST /wifi/scan | Wi-Fi status, the saved networks (up to 8, priority 0 to 100), join a network, scan. |
GET /ap, PUT /ap | The setup access point: {ssid, password, mode, channel}. |
GET /mdns, PUT /mdns, POST /mdns/restart | The mDNS name; PUT {"hostname": "x"} (63 characters at most). |
GET /mqtt, PUT /mqtt, POST /mqtt/test | {enabled, uri, user, password, baseTemplate, retain, ha}. |
GET /webhook, PUT /webhook, POST /webhook/test | {url, enabled, onChange, interval, secret}. |
GET /cloud, PUT /cloud | {enabled, site, apiKey, confirm}; the answer has the state, claimed, connected and activateUrl, never the key. |
GET /features, PUT /features | The editions’ features and whether each is on. |
WebSocket: live values
- Connect to
ws://<host>/fn/ws?t=<token>. The board sends no snapshot on connect: readGET /statefirst, then apply what arrives. {"t":"v","v":{"temp":24.5,"light":true}}carries changed widget values (batched every 150 ms);{"t":"layout"}says to fetch/uiagain;{"t":"sys","d":{uptime, heap, rssi, sta, ts}}comes every 5 s;{"t":"x","id":"<topic>","d":{...}}carries a module topic such aslightsorflows.- The only message to send is
{"t":"sub","id":"<topic>"}to receive a module topic; repeat it at least every 8 seconds. To change a widget use HTTP. There is no SSE endpoint.
MQTT on your own broker
The library is an MQTT client only (there is no broker in the board). Set dev.mqtt().broker("mqtt://host:1883") or PUT /mqtt; the base topic defaults to flyght/{id} with {id} the 12 digit device id, and the client id is the hostname.
| Topic | Direction | Payload |
|---|---|---|
<base>/status | device → | online / offline (retained, QoS 1, last will) |
<base>/info | device → | {id, name, model, fw, fn, ip, url} (retained, QoS 1) |
<base>/state/<widget> | device → | ON/OFF, a number as text, or text; buttons are not published |
<base>/set/<widget> | → device | the same, plus toggle and PRESS (QoS 1, 2048 bytes at most) |
<base>/light/<id>/set | → device | ON, OFF, TOGGLE, #rrggbb, an effect id, or a JSON patch |
<base>/light/<id>/state | device → | the light’s state as JSON (retained) |
With homeAssistant(true) the board also publishes Home Assistant discovery for its widgets (switch, number, button, select, text, sensor). Flows can listen with trigger.mqtt and publish with mqtt.publish; your own code can use dev.mqtt().subscribe(topic, cb) and publish(topic, payload, retain, qos).