Skip to content

Gateway API ​

Development Preview

This page is written against the routes and parsers actually registered at commit b1a16cbc (ApiRouter plus the individual RouteGroups); it does not carry over endpoint counts or unimplemented fields from the project's older documentation. A route's existence does not mean the end-to-end workflow is complete, especially driver registration, MQTT reverse control, factory reset, and OTA.

1. Base URL and Responses ​

Default base URL:

text
http://<gateway-ip>:8080

Except for explicitly noted endpoints such as Prometheus metrics, JSON responses are uniformly wrapped as:

json
{
  "code": 200,
  "msg": "ok",
  "data": {}
}

Successful creation typically uses HTTP 201 with msg: "created"; errors use the corresponding HTTP status code and msg (400 bad parameters / 401 unauthorized / 404 not found / 409 conflict / 500, 502, 503 server errors). GET /api/metrics returns text/plain metrics directly, without the JSON wrapper above.

2. Login and Token ​

POST /api/auth/login requires no existing token. Request:

json
{
  "username": "admin",
  "password": "<changed-password>"
}
bash
curl -fsS http://127.0.0.1:8080/api/auth/login \
  -H 'Content-Type: application/json' \
  -d '{"username":"admin","password":"<changed-password>"}'

On success, data contains token, username, role, createdAt, and expiresAt. Protected routes use:

text
Authorization: Bearer <token>

The initial default password is admin123 and must be changed immediately; the current middleware verifies token presence and validity, so do not claim that role-level authorization is enforced on every route.

Endpoints that require no token (authentication whitelist and unauthenticated endpoints):

MethodPathDescription
POST/api/auth/loginLog in and obtain a token
POST/api/auth/logoutLog out (on the whitelist)
GET/api/healthProcess health, version, uptime, MQTT and Tag counts
GET/api/metricsPrometheus text metrics

Exposure of these unauthenticated endpoints should be restricted by network boundaries.

3. Overview API ​

MethodPathCurrent behavior
GET/api/healthHealth check (unauthenticated): status, version, uptime, MQTT connection, Tag count
GET/api/overview/statusSystem status: CPU/memory/temperature/disk usage and timestamp
GET/api/overview/devicesInternal device total/online/offline statistics
GET/api/overview/trafficMQTT byte, message, publish, subscribe, and reconnect statistics

4. Device and Tag Management API ​

MethodPathCurrent behavior
GET/api/devicesSub-device list
POST/api/devicesAdd a sub-device; success returns 201; a duplicate ID returns 409
PUT/api/devices/:idReplace the device model; the route ID overrides the request ID; not found returns 404
DELETE/api/devices/:idDelete the device and clean up its associated Tags in the TagEngine
GET/api/devices/:id/tagsTag list of the specified device
POST/api/devices/:id/tagsAdd a Tag; the route device ID overrides the request device ID
PUT/api/devices/:id/tags/:tagIdModify a Tag; the route ID overrides the request ID
DELETE/api/devices/:id/tags/:tagIdDelete a Tag

Device creation example:

json
{
  "deviceId": "modbus-dev-001",
  "productId": "demo-product",
  "deviceNum": "modbus-001",
  "deviceName": "Modbus development device 001",
  "protocolType": "modbus"
}

Tag creation example:

json
{
  "id": "holding-0",
  "name": "Holding register 0",
  "sourceType": 0,
  "slaveAddr": 1,
  "registerAddr": 0,
  "registerCount": 1,
  "scale": 1,
  "offset": 0,
  "pollIntervalMs": 1000,
  "reportOnChange": false,
  "enabled": true
}

sourceType: 0 is Modbus, and register addresses are zero-based. The request parser does not read dataType, functionCode, or byte-order fields; see Configuration. Successfully creating a device or Tag does not mean the driver has been registered; see the current blockers in Quick Start.

5. GPIO API ​

MethodPathCurrent behavior
GET/api/gpio/diDI channel state list (channel/name/state/changed/timestamp)
GET/api/gpio/doDO channel state list
POST/api/gpio/do/:channelDO control; request body {"state": true}
GET/api/gpio/aiAI channel values (rawValue/engValue/unit)

Real GPIO depends on the compile-time flag FASTBEE_ENABLE_GPIO=ON and libgpiod; the default build uses the simulated backend.

6. MQTT API ​

MethodPathCurrent behavior
GET/api/mqtt/configReturns a summary of the connection configuration; active field names include useTls, and keepAlive is also included when the client is initialized
PUT/api/mqtt/configOnly updates broker, port, clientId, username, and password and saves them; does not reconnect
GET/api/mqtt/statusReturns connection state, broker, and message/error/reconnect statistics

The Web UI's "Save and Reconnect" copy and the submitted TLS, KeepAlive, and QoS fields do not mean the active PUT handles these behaviors. A read-only configuration mount can also cause saving to fail.

Note: the source code contains a certificate management route implementation (POST/GET/DELETE /api/mqtt/certificates), but the current registration flow does not mount that route group, so it must not be treated as an available endpoint.

7. System Management API ​

MethodPathNotes
GET/api/system/infoVersion, build time, platform, hostname, and uptime
POST/api/system/rebootExecutes the real system reboot command about 1 second after responding; token and network access must be strictly restricted
POST/api/system/factory-resetPlaceholder: only logs and returns {"resetting":true}; no configuration cleanup is performed
GET/api/system/configExport configuration (via ConfigManager, genuinely functional)
POST/api/system/configImport configuration (via ConfigManager, genuinely functional)
POST/api/system/upgradePlaceholder: only checks the firmware field in the multipart body and returns the file name, size, and uploading; OTA installation, verification, and rollback are not implemented
GET/api/system/timeCurrent time
POST/api/system/time/syncNTP synchronization; accepts server and timeoutMs
GET / POST/api/system/timezoneRead or set the time zone

The factory-reset and OTA responses must not be taken as evidence of production success.

8. Authentication and User API ​

MethodPathCurrent behavior
POST/api/auth/loginLog in (SHA-256 password hash verification); returns a token
POST/api/auth/logoutInvalidate the current token
GET/api/usersUser list
POST/api/usersAdd a user (username/password/role; roles such as admin/operator/viewer); success returns 201
PUT/api/users/:idModify a user's role, enabled state, or password

The role permission model (admin/operator/viewer) is defined, but the current middleware only verifies the token; route-level role authorization is not complete.

9. Debug API ​

MethodPathCurrent behavior and risks
GET/api/debug/tagsPerforms one full pollOnce() and returns Tag and engine statistics
POST/api/debug/readIgnores the requested device/Tag IDs and performs a full pollOnce()
POST/api/debug/writeCalls TagEngine::writeTag() by tagId and value; a registered driver is still required
POST/api/debug/pingConcatenates host into a system command; command injection risk
GET/api/debug/logsReturns roughly the last 50 entries of the in-memory log

Manual write request:

json
{
  "tagId": "holding-0",
  "value": 1
}

value can be a boolean, integer, float, or string. A stub's success: true may only be a simulated result and does not prove a physical write. Production code does not call subscribeFunction, so this endpoint is not a substitute for MQTT cloud-side reverse control either.

Debug API Security

Do not expose /api/debug/* to untrusted networks. /api/debug/ping in particular carries a command injection risk and should be fixed or isolated first; full reads and writes should also be evaluated for fieldbus load and physical impact.

10. Alerts API ​

Active alert and history endpoints of the AlertManager:

MethodPathCurrent behavior
GET/api/alertsActive alert list
POST/api/alertsManually trigger an alert (source/level/message/extra); success returns 201
POST/api/alerts/:id/ackAcknowledge an alert
POST/api/alerts/:id/silenceSilence an alert
DELETE/api/alerts/:idClear an alert
DELETE/api/alertsClear all acknowledged alerts
GET/api/alerts/historyAlert history; supports ?limit= (default 100)
GET/api/alerts/statsAlert statistics

11. Alarm Engine API (alarms) ​

Industrial alarm rules and active alarm endpoints (note the plural path /api/alarms, unlike /api/alarm in the project's older documentation):

MethodPathCurrent behavior
GET/api/alarms/rulesAlarm rule list
POST/api/alarms/rulesCreate an alarm rule (fields in section 8 of Configuration); success returns 201
PUT/api/alarms/rules/:idUpdate an alarm rule; the ID in the URL takes precedence
DELETE/api/alarms/rules/:idDelete an alarm rule
GET/api/alarms/rules/by-tag/:tagIdQuery rules by Tag
GET/api/alarms/activeActive alarm list
GET/api/alarms/active/by-tag/:tagIdQuery active alarms by Tag
POST/api/alarms/:ruleId/ackAcknowledge an alarm
POST/api/alarms/:ruleId/silenceSilence an alarm
GET/api/alarms/statsAlarm statistics
GET/api/alarms/exportExport all rules
POST/api/alarms/importImport rules (replace controls whether to replace all existing rules)

12. Peripheral Management API (peripherals) ​

Peripheral configuration center endpoints (see Peripherals and Linkage for the peripheral model):

MethodPathCurrent behavior
GET/api/peripheralsPeripheral list
POST/api/peripheralsAdd a peripheral (unique ID, pin conflict validation); success returns 201
PUT/api/peripherals/:idUpdate a peripheral (ID cannot be changed)
DELETE/api/peripherals/:idDelete a peripheral
POST/api/peripherals/:id/enableEnable a peripheral (validates pin conflicts)
POST/api/peripherals/:id/disableDisable a peripheral
POST/api/peripherals/:id/testTest action: DO toggle / LED light-up / buzzer beep; other types return 400
GET/api/peripherals/exportExport peripheral configuration
POST/api/peripherals/importImport peripheral configuration

13. Peripheral Execution Rules API (periph-exec) ​

Linkage rule engine endpoints (see Peripherals and Linkage for the trigger/action model):

MethodPathCurrent behavior
GET/api/periph-execRule list (including last execution time and result)
POST/api/periph-execCreate a rule; success returns 201
PUT/api/periph-exec/:idUpdate a rule
DELETE/api/periph-exec/:idDelete a rule
POST/api/periph-exec/:id/enableEnable/disable (request body {"enabled": false})
POST/api/periph-exec/:id/run-onceRun once manually (optionally with {"value": "..."})
GET/api/periph-exec/resultsRecent execution results
GET/api/periph-exec/exportExport rules
POST/api/periph-exec/importImport rules

14. Driver Health and Tag Aggregation API ​

MethodPathCurrent behavior
GET/api/drivers/healthHealth summary of all drivers (total/healthy/isolated plus per-driver statistics)
GET/api/drivers/:name/healthHealth details of a single driver; not found returns 404
GET/api/aggregator/rulesAggregation rule list
GET/api/aggregator/rules/:id/resultAggregation result (value/sampleCount/lastUpdateMs/valid)

There is currently no registered endpoint for creating aggregation rules; driver health data must be interpreted against the premise that drivers are not yet registered with the TagEngine.

15. Prometheus Metrics API ​

MethodPathCurrent behavior
GET/api/metricsPrometheus text metrics (unauthenticated), including uptime, system resources, Tag count, MQTT statistics, and more

FastBee | fastbee.cn