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.

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 cookie fn_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 with fn_, is made by an administrator with POST /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/state answers 402.
Terminal
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

CallRoleMeaning
GET /uiviewerThe dashboard schema: pages and every widget with type, label, unit, min, max, step, options, write role.
GET /stateviewer{"values": {id: value}, "ts": unix, "uptime": s}; toggles are booleans, buttons are left out.
POST /statewidget roleBody {"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 roleBody {"value": ...}; null or no value toggles a toggle or presses a button.
PUT /ui/layout, DELETE /ui/layout?page=<id>adminOrder, sizes (1 to 3) and hidden widgets of a page; the delete resets it (no page resets all).
Terminal
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/bell

Lights, flows and the system

CallRoleMeaning
GET /lights, POST /lights/<id>viewer, operatorRead 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/blocksviewerList flows, one flow, and the block catalogue.
PUT /flows/new|<id>, DELETE /flows/<id>adminSave 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>operatorRun a flow; fire a trigger.http hook. The whole raw body becomes the flow’s {value}.
GET /sys, GET /sys/healthviewerName, model, versions, chip, memory, uptime, IP, MAC; module health.
GET /sys/logs?since=<seq>, POST /sys/restartadminThe log lines since a sequence number; restart.
POST /sys/otaadminA .bin as the raw body (1024 bytes or more); the board restarts.
POST /sys/factory-resetadminBody {"confirm": "RESET"}.

Network, MQTT, webhook and cloud

CallMeaning
GET /wifi, PUT /wifi/networks, POST /wifi/connect, POST /wifi/scanWi-Fi status, the saved networks (up to 8, priority 0 to 100), join a network, scan.
GET /ap, PUT /apThe setup access point: {ssid, password, mode, channel}.
GET /mdns, PUT /mdns, POST /mdns/restartThe 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 /featuresThe 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: read GET /state first, 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 /ui again; {"t":"sys","d":{uptime, heap, rssi, sta, ts}} comes every 5 s; {"t":"x","id":"<topic>","d":{...}} carries a module topic such as lights or flows.
  • 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.

TopicDirectionPayload
<base>/statusdevice →online / offline (retained, QoS 1, last will)
<base>/infodevice →{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>→ devicethe same, plus toggle and PRESS (QoS 1, 2048 bytes at most)
<base>/light/<id>/set→ deviceON, OFF, TOGGLE, #rrggbb, an effect id, or a JSON patch
<base>/light/<id>/statedevice →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).