REST API¶
All endpoints are on port 80. Base URL: http://<device-ip>/api
The API Reference lists every route with its parameters and response schemas, from
the machine-readable openapi.json (OpenAPI 3.1). Try any request in the
API explorer, where the demo answers it in your browser. This
page covers what the reference can't: behaviour, the password and limits.
Conventions¶
- Keys are camelCase. Timestamps are Unix seconds (
timestamp,time.epoch),0until the device's clock is set;isostrings are for display only. Readings use the same names and units as/ws/sensorsand MQTT<base>/state. - Success is a 2xx status. Actions return
{"success": true, ...}: 200 when done, 202 when queued. - Failure is a 4xx or 5xx status with
{"error": "message"}: 400 bad request, 401 unauthorised, 403 not allowed, 404 not found, 409 conflict, 500 device failure, 502 a sensor or broker didn't answer. - Endpoints that change something need the password when protection is on.
The same in every language
The UI language never changes the API. Numbers are JSON numbers with . as the decimal point and no thousands separators (12.1, never "12,1"). Units (°C, %, hPa, lux, mag/arcsec², m/s, mm, mm/h), field names and values such as status, event and reason are never translated, and timestamps are Unix seconds or ISO 8601. Text for people to read - reasons, rulesNotInEffect, alert title and message, description, error - is English and may be reworded between releases: key on reasonFlags, safe and the alert event instead.
Endpoints¶
GET /api/status¶
Firmware, memory, flash, partitions, time, WiFi, MQTT, Bluetooth, darkness, sensor health and diagnostics.
{
"uptime": 3600,
"configRevision": 3,
"freeHeap": 128728,
"firmware": { "name": "SQMeter", "version": "0.3.0", "buildDate": "Oct 8 2026", "buildTime": "12:00:00", "variant": "standard", "layout": "l2" },
"time": { "epoch": 1791494565, "iso": "2026-10-08T22:22:45+0100", "timezone": "GMT0BST,M3.5.0/1,M10.5.0" },
"wifi": { "connected": true, "ssid": "MyNetwork", "ip": "192.168.1.42", "rssi": -62, "mac": "AA:BB:CC:DD:EE:FF", "connectPending": false, "apMode": false, "hostname": "sqmeter", "mdns": true, "ipv6": { "enabled": true, "addresses": [{ "address": "fe80::a00:27ff:fe4e:66a1", "scope": "link-local" }, { "address": "2a02:8010:abcd:1:a00:27ff:fe4e:66a1", "scope": "global" }] } },
"sky": { "locationSource": "manual", "nightKnown": true, "latitude": 51.4779, "longitude": -0.0015, "isNight": false, "sunAltitudeDeg": 19.4 },
"alerts": { "armed": true, "armWithAlpaca": true, "mode": "whileConnected", "reason": "client-connected", "since": "2026-10-08T20:58:02Z", "sinceAgeMs": 412000, "recentRevision": 7 },
"alpaca": {
"enabled": true,
"clients": {
"safetymonitor": { "connected": true, "watching": true, "silent": false, "lastCheckedAgeMs": 2100, "clientId": 4021 },
"observingconditions": { "connected": true, "watching": true, "silent": false, "lastCheckedAgeMs": 41000, "clientId": 4021 }
}
},
"sensors": {
"light": { "status": "ok", "ageMs": 400 },
"environment": { "status": "ok", "ageMs": 3100 },
"infrared": { "status": "ok", "ageMs": 3100 },
"rain": { "status": "ok", "ageMs": 40 },
"wind": { "status": "ok", "ageMs": 900, "vaneStatus": "ok" }
},
"diagnostics": {
"light": { "rollingVisible": 3.1, "correctedVisible": 3.1, "darkVisibleOffset": 0, "sampleCount": 150, "windowSamples": 150, "nightMode": true, "rejectedSamples": 0, "consecutiveSaturatedSamples": 0, "consecutiveLowSamples": 0 },
"rain": { "state": "online", "uartOpened": true, "rxPin": 18, "txPin": 19, "baudRate": 9600, "uartPort": 1, "lastCommand": "R", "lastResponse": "Acc 0.01 mm, ...", "timeouts": 0, "parseErrors": 0, "successfulReads": 1424, "lastPollAgeMs": 40, "lastResponseAgeMs": 40, "lastSuccessfulReadAgeMs": 40 }
},
"mqtt": { "enabled": true, "connected": true, "state": 0, "lastPublish": 3541200, "lastReconnectAttempt": 12400, "broker": "192.168.1.10", "port": 1883, "topic": "sqmeter", "availabilityTopic": "sqmeter/availability", "clientId": "SQMeter-A1B2C3" },
"connections": { "tcpLimit": 20, "liveUpdates": { "sensors": 1, "status": 1, "limitPerEndpoint": 3, "replaced": 0, "stalledClosed": 0 }, "alpacaRestoredAfterRestart": false }
}
The rest of the document, for diagnostics:
| Field | Meaning |
|---|---|
uptime |
Seconds since the restart |
freeHeap, minFreeHeap, maxAllocHeap, heapSize |
Free heap now, its lowest since the restart, the largest block that can be allocated, and the heap's size (bytes) |
heapStages |
Free heap (free) and largest block (largest) at each start-up stage (config loaded, wifi, ... setup complete) |
stackFree |
Stack never used (bytes) by the web server task (asyncTcp) and the main loop |
cpuFreqMHz, flashSize, sketchSize, freeSketchSpace |
CPU clock, flash chip size, the running firmware's size and the space for the next one (bytes) |
fsTotal, fsUsed |
The web UI filesystem (LittleFS), bytes |
partitions |
runningSlot, runningAddress, runningSize, bootSlot (the slot the next boot uses), nextSlot, nextSize (where an update goes), fsAddress, fsSize, and nvs (settings storage: usedEntries, freeEntries, totalEntries, namespaceCount) |
resetReason |
Why the device last restarted, ESP-IDF's esp_reset_reason_t (1 power on, 3 software restart, 4 crash, 5-7 watchdog, 8 deep sleep, 9 brownout) |
bootCount |
Starts since the last power-up (kept across restarts and deep sleep, not a power cut) |
sensorSnapshotBytes |
Size of the internal readings snapshot, for development |
ntp |
Time sync: enabled, synced, status (0 not synced, 1 in progress, 2 synced, 3 failed), lastSync (uptime ms of the last sync), nextSync (ms until the next one, 0 when not synced or due), drift (always 0), server, activeSource (0 none, 1 NTP, 2 GPS), gpsEnabled, gpsHasFix, gpsTimeUTC, gpsSatellites |
ble |
Bluetooth: available (the Bluetooth build), active (running), clients (connected now) and the phone alarm - see Bluetooth |
mqtt |
state is the MQTT library's connection state (0 connected, negative: not connected, positive: refused by the broker); lastPublish and lastReconnectAttempt are uptime ms (0 never) |
connections shows who holds the device's TCP connections: the live-update clients per endpoint (/ws/sensors, /ws/status), the most each takes, and how many were closed since the restart because a newer one replaced them (replaced) or they stopped reading (stalledClosed). alpacaRestoredAfterRestart is true when an imaging app's connection was kept across a restart the device caused itself. See N.I.N.A. loses the Safety Monitor.
connections.tcp and connections.stalls are web server diagnostics, in /api/status only (not the /ws/status pushes):
"tcp": { "listen": 1, "established": 2, "timeWait": 6, "total": 8, "listenBacklog": 0, "accepted": 41210,
"peak": { "established": 1, "finWait2": 9, "timeWait": 6, "total": 16, "listenBacklog": 5, "uptimeMs": 3512000, "epoch": 1791494565 } },
"stalls": { "count": 1, "ongoing": false, "recent": [
{ "startEpoch": 1791494560, "startUptimeMs": 3507000, "durationMs": 21000, "resumed": true,
"atDetection": { "listen": 1, "finWait2": 9, "timeWait": 6, "total": 15, "listenBacklog": 5 },
"worst": { "listen": 1, "established": 1, "finWait2": 9, "timeWait": 6, "total": 16, "listenBacklog": 5 },
"minFreeHeap": 151000, "asyncTcpStackFree": 960, "samples": 16, "asyncTcpIdle": 14 } ] }
tcp counts the TCP connections by lwIP state now (listen, synRcvd, established, finWait1, finWait2, closeWait, closing, lastAck, timeWait, ...; states with none are left out). total is every connection but listeners, out of tcpLimit; listenBacklog is handshakes not yet taken by the server (at most 5); accepted is connections accepted since the restart. peak is the moment with the highest total since the restart (uptimeMs, epoch, 0 if the clock wasn't set).
A stall is no new connection for 5 s while an imaging app polled Alpaca in the last minute; the device checks once a second. stalls.count is stalls since the restart and recent the last 8, newest first: when the last connection before it was accepted (startEpoch, startUptimeMs), how long until the next one (durationMs; resumed: false means given up after 60 s, e.g. the app went away), the connections when it was detected and at their most (atDetection, worst), the lowest free heap, the async_tcp task's stack headroom, and in how many of the samples that task was waiting for work (asyncTcpIdle).
alerts is the /api/alerts/armed object, plus recentRevision, which goes up whenever /api/alerts/recent would answer differently. configRevision goes up whenever the settings are saved. Both only say that something changed, so a page fetches the details then; they restart from 0 after a restart. alpaca.clients says, per Alpaca device, whether an imaging app has it connected, whether one is watching (connected, or polling since the restart), whether it has gone silent (no request for the alert's Silent for time), how long ago it last checked (lastCheckedAgeMs, null if never since the restart) and the last Alpaca clientId (null if none); the web UI's own requests aren't counted (The imaging app).
time.epoch is Unix seconds like every other timestamp (0 until the clock is set); time.iso is the device's local time with its UTC offset, for display.
sensors lists the built-in sensors (light, environment, infrared) and, when enabled, gps, rain and wind. status is ok, missing, error or stale. diagnostics.rain is only present while the rain sensor is enabled. Readings are in /api/sensors.
sensors.light and diagnostics.light are the authoritative sky sensor (sky.authoritative). skySensors has an entry per sky sensor that is switched on (spec 030), and is left out when neither is:
"skySensors": {
"sqm": { "status": "ok", "ageMs": 412, "detected": true, "gain": "MAX", "integrationMs": 600,
"saturated": false, "nightMode": true, "sampleCount": 150, "windowSamples": 150, "darkVisibleOffset": 0.0 },
"sqml": { "status": "missing", "detected": false }
}
detected means found and answering (ok or stale); the gain and calibration fields are only there while it is. ageMs is left out while missing.
display is the optional OLED display, always present:
battery is the travel board's pack (spec 032): the same object as in /api/sensors, plus shutdownInSeconds while the device is about to sleep. With a fuel gauge, sensors.battery has its health (status, ageMs) and diagnostics.battery the raw gauge registers (version, vcellRaw, socRaw, crateRaw, statusRaw), resetSeen, estimating, the charger pin levels (charger: {stat1, stat2, pg}, true = high, null without the pins), gaugeAlert, the power policy (normal, saving, shutdown) and currentMa (with a pack capacity set). See Battery.
"battery": { "present": true, "status": "ok", "ageMs": 1200, "estimating": false, "percent": 4.2, "voltage": 3.412,
"ratePercentPerHour": -6.2, "state": "discharging", "usbPower": false, "fault": null,
"timeToEmptyMinutes": 41, "timeToFullMinutes": null, "powerSaving": true, "shutdownInSeconds": 18 }
enabled is the setting; detected means a display answered at 0x3C (always false while it is off in settings, since it isn't probed then); on means it is lit now; page is the page shown (sky, environment, cloud, safety, gps, battery, network), null while it is off; nightMode means the night layout and minimum brightness are in use (at night, or while night can't be worked out).
GET /api/sensors¶
The current readings plus the safety verdict. The document is the same as /ws/sensors and MQTT <base>/state; see MQTT → Readings for every field.
{
"timestamp": 1791401772,
"timeValid": true,
"dataAgeMs": 412,
"dataStale": false,
"light": { "status": "ok", "ageMs": 400, "lux": 0.0003, "visible": 307, "infrared": 47, "full": 357, "gain": "MAX", "gainFactor": 9876, "integrationMs": 600, "saturated": false, "nightMode": true },
"sky": { "status": "ok", "source": "sqm", "sqm": 21.48, "rawSqm": 21.41, "nelm": 6.2, "bortle": 2, "description": "Typical truly dark site", "calibrated": false, "averagingWindowSeconds": 90 },
"skySensors": {
"sqm": { "status": "ok", "ageMs": 400, "sqm": 21.48, "rawSqm": 21.41, "nelm": 6.2, "bortle": 2, "description": "Typical truly dark site", "calibrated": false, "averagingWindowSeconds": 90, "lux": 0.000301, "gain": "MAX", "integrationMs": 600, "saturated": false, "nightMode": true },
"sqml": { "status": "ok", "ageMs": 380, "sqm": 21.73, "...": "the same fields" },
"deltaSqm": 0.25
},
"environment": { "status": "error", "ageMs": 61000 },
"infrared": { "status": "ok", "ageMs": 3100, "skyTemperature": -24.7, "ambientTemperature": 12.4 },
"clouds": { "status": "ok", "coverPercent": 3, "condition": "clear", "description": "Clear", "temperatureDelta": -37.1, "correctedDelta": -33.0, "humidity": 53, "humiditySource": "assumed" },
"battery": { "present": false },
"safety": { "safe": true, "rawSafe": true, "reasons": [], "reasonFlags": 0, "secondsUntilSafe": 0, "secondsUntilUnsafe": 0, "rulesNotInEffect": [], "alpacaEnabled": true, "evaluatedAgeMs": 412, "changedAgeMs": 3600000 }
}
battery is always there: {"present": false} on a board without a fuel gauge (as above), the full group with one (MQTT → Readings, Battery).
A group whose sensor isn't ok carries only status and ageMs - just status when missing (like environment above).
light and sky are the authoritative sky sensor; sky.source (sqm or sqml) says which. If it is switched off or not answering they report that sensor's state, never the other sensor's reading. skySensors (two sky sensors, spec 030) has each sensor that is switched on under its own name, with the same rules, and deltaSqm (SQM-L − SQM) while both are ok.
POST /api/sensors/tsl2591/calibrate-dark¶
Stores the current rolling TSL2591 visible count as the dark visible offset. Cover the aperture with an opaque cap, wait for the rolling window to fill, then call this endpoint. ?sensor=sqm (the default) calibrates the SQM and writes skyCalibration; ?sensor=sqml calibrates the SQM-L and writes skyCalibrationL only. Any other sensor is refused with 400 {"error": "Unknown sky sensor"}.
{
"success": true,
"sensor": "sqml",
"darkVisibleOffset": 1.5,
"sampleCount": 138,
"darkCalibratedAt": 1778171234
}
It's refused with 409 {"error": "..."} while it can't give a good offset: the sensor is switched off or not found, no light-sensor readings yet, the sensor isn't in night mode (it's seeing light), or the averaging window isn't full - then the body also has sampleCount and windowSamples. /api/status → skySensors.<sensor> (or diagnostics.light for the authoritative one) shows sampleCount, windowSamples and nightMode so you can wait for it. darkCalibratedAt is Unix seconds, or uptime milliseconds if the clock wasn't set.
POST /api/sensors/rg15/test¶
Trigger a manual RG-15 read and return communication diagnostics.
When HTTP auth is enabled, this endpoint requires credentials.
Success is 200 {"success": true, "command": "R", "bytesWritten": 2, "elapsedMs": 140, "rawResponse": "Acc 0.00 mm, ...", "ack": "R", "online": true, "lastSuccessfulReadAgeMs": 40}. With no valid reply it's 502 with error and a wiring hint, plus the same diagnostic fields.
POST /api/sensors/rg15/reset-total, POST /api/sensors/rg15/reboot¶
Send the RG-15 its O (reset total accumulation) or K (reboot) command. Returns {"success": true, "command": "O", "message": "..."}, or 502 with {"error": "..."} if the sensor didn't take it. Requires HTTP auth when enabled. See RG-15.
GET /api/config¶
Read the full device configuration. Password fields are returned as ******** when a stored password exists.
LAN-sensitive endpoint
Password fields are redacted in this response, but the endpoint is still unauthenticated and returns operational configuration. Treat /api/config as LAN-sensitive and do not expose the device to guest networks or the public internet.
POST /api/config¶
Update configuration. Partial updates are supported — only the fields you send are changed.
curl -X POST http://sqmeter.local/api/config \
-H "Content-Type: application/json" \
-d '{"deviceName": "backyard-sqm", "sensor": {"readIntervalMs": 10000}}'
Masked or empty password fields preserve the existing stored password. Send null for wifi.password, mqtt.password, or ota.password only when you intentionally want to clear that password.
Every value must have the setting's type: text for names and addresses, true/false for switches, numbers for numbers. A value of the wrong type, null included (other than null to clear a password), is rejected with 400 and an error naming the setting, e.g. {"error": "Settings: wifi.ssid must be a string"}; it is never replaced by a default. A setting you leave out keeps its current value.
While the device has a WiFi network saved, wifi.ssid can't be set to "": the save is rejected with "WiFi network can't be blank; use WiFi setup to change networks", so a settings save never takes the device off its network. Join a different network with POST /api/wifi/connect (or pick it in Settings → Network); there is no endpoint that forgets the network.
Successful saves return:
Note
POST is the primary method. The firmware also accepts PUT for compatibility with full-resource settings clients.
For example, turning on Rain needs cloud with rain confirmed at 15% cloud:
curl -X POST http://sqmeter.local/api/config \
-H "Content-Type: application/json" \
-d '{"alpaca": {"rainNeedsCloud": true, "rainNeedsCloudPercent": 15}}'
rainNeedsCloudPercent must be a whole number from 1 to 100 (400 "Safety: cloud to confirm rain must be 1 to 100%" otherwise). Every setting is listed in the configuration reference.
A setting whose dependency is off is saved as sent and reported inactive by GET /api/settings/effective; it isn't rejected. Only combinations that can never work are refused, with the reason in error (see Settings dependencies).
POST /api/backup¶
The settings backup file (format): a header and every setting as GET /api/config shows it. With {"passphrase": "..."} (8 characters or more) the passwords, keys and tokens are added encrypted (AES-256-GCM, PBKDF2-HMAC-SHA256, 20,000 iterations); without one the file holds no secret. An empty body is fine. Needs the password when protection is on.
curl -X POST http://sqmeter.local/api/backup -H "Content-Type: application/json" \
-d '{"passphrase": "correct horse battery"}' -o backup.json
The key derivation takes a second or two, in a background task: the web server keeps answering. One backup or preview runs at a time (409, "code": "busy"). Refusals add a code: passphrase-short (400), too-large (413, bodies over 20,480 bytes).
POST /api/backup/preview¶
What restoring a backup would save. Nothing is applied.
{
"token": "4f1c0d7e9a2b3c4d5e6f708192a3b4c5",
"backup": { "format": 1, "firmware": "0.3.4-beta.1", "board": "esp32", "build": "ble", "deviceName": "backyard-sqm", "createdAt": "2026-10-18T21:04:05Z" },
"settings": { "deviceName": "backyard-sqm", "wifi": { "ssid": "Observatory", "password": "********" } },
"secrets": { "state": "restored", "changed": ["wifi.password"], "unchanged": ["mqtt.password"] },
"notApplicable": [ { "path": "gps.rxPin", "value": 44, "reason": "pin" } ],
"restart": ["wifi"]
}
settings is what applying saves, masked like GET /api/config (shortened above). secrets.state is restored (passphrase right), kept (the file has secrets, no passphrase given: this device keeps its own) or none. notApplicable lists settings this board can't use (pin, analog, bluetooth, pushover-keys); they keep this device's values. restart says why applying restarts the device (empty: it doesn't). The web UI works out the per-setting differences from settings.
Refused with 400 and a code: not-backup, damaged, newer-format, wrong-passphrase (also when the encrypted part was changed), or invalid with the same message a settings save gives. A new preview replaces the previous one.
POST /api/backup/apply¶
Saves exactly what the preview with this token showed, as one settings save.
curl -X POST http://sqmeter.local/api/backup/apply -H "Content-Type: application/json" \
-d '{"token": "4f1c0d7e9a2b3c4d5e6f708192a3b4c5"}'
With restarting, the device restarts about 2 s later. 409 with "code": "stale" when the token was already used or replaced, is more than 10 minutes old, or the settings changed after the preview: preview again.
GET /api/secrets¶
The MQTT password, ntfy token and Pushover keys as stored, for a paired device such as RoofRoof that copies SQMeter's site settings (password sharing). Always needs the username and password.
{ "mqtt": { "password": "broker-pass" }, "alerts": { "ntfy": { "token": "tk_abc123" }, "pushover": { "userKey": "uQiRzpo4DXghDmr9QzzfQu27cmVRsG", "appToken": "azGDORePK8gMaC0QOYAMyEEuzJnyUi" } } }
Every key is always there; a value that isn't set is "". Nothing else is ever included. Checked in this order:
| Status | When | error |
|---|---|---|
| 403 | Share passwords is off (sharing.secrets) |
Password sharing is off in SQMeter |
| 403 | Password protection is off, or has no password | Set a web password in SQMeter before sharing passwords |
| 429 | Five wrong logins in a row (Basic credentials that don't match; a request without credentials doesn't count), the last less than a minute ago. Retry-After gives the seconds. The lock is for the device, not per client; ten minutes without a wrong login clear the count. It throttles this request only, not guesses at the password on other routes |
Too many failed logins; try again in a minute |
| 401 | No username and password, or wrong ones | (the usual login challenge) |
| 200 | Otherwise |
The 200, 403 and 429 answers carry Cache-Control: no-store; the 401 is the device's standard login challenge and carries nothing secret. The device logs which address the passwords went to, never the values. This is plain HTTP: anyone who can watch the network traffic can read the values, and anything with the device password can ask for them.
GET /api/settings/effective¶
Whether each setting that depends on another setting, on hardware or on the network is actually in effect. Settings are reported as saved; this says what the device does with them. Read-only, no secrets.
{
"facts": { "wifiConnected": true, "mqttConnected": false, "clockSet": true, "gpsRunning": false, "gpsFix": false,
"bluetoothBuild": false, "bluetoothRunning": false, "pairedPhones": 0,
"lightDetected": true, "sqmDetected": true, "sqmlDetected": false, "infraredDetected": true, "environmentDetected": true,
"languageInstalled": false, "displayDetected": false, "batteryDetected": false },
"settings": [
{ "id": "D-01", "setting": "alerts.mqtt.enabled", "state": "inactive", "reason": "mqtt-off", "text": "MQTT is off", "fix": "network#mqtt" },
{ "id": "D-15", "setting": "alpaca.rainUnsafeEnabled", "state": "inactive", "reason": "rain-off", "text": "Rain sensor is off", "fix": "sensors#rain", "unmet": "inactive" },
{ "id": "D-28", "setting": "ntp.enabled", "state": "active" }
]
}
| Field | Meaning |
|---|---|
facts |
What the device knows at run time: network, broker, clock, GPS, Bluetooth, which sensors answer (lightDetected is the authoritative sky sensor, sqmDetected/sqmlDetected each one), whether the language file is installed, and whether an OLED display and a fuel gauge were found |
id |
Catalogue entry that decides the state (the first unmet one when inactive) |
setting |
Path of the setting in /api/config (a few are derived, e.g. alerts.wakePhones: an event at Wake me) |
state |
off (switched off), active, or inactive (on, but something it needs is missing) |
reason, text, fix |
Why it's inactive and where it's fixed (tab#section in Settings, or restart) |
unmet |
Safety rules only: inactive (ignored, listed in rulesNotInEffect) or fail-safe (the verdict reports unsafe) |
neutral |
Inactive by default and harmless (e.g. publishing rain with no rain sensor) |
GET /api/wifi/scan¶
Scan for nearby WiFi networks (needs the password when protection is on, like /api/wifi/connect). The scan runs in the background: the first call starts it and returns 202 with "scanning": true; call again (about once a second) until "scanning": false and the list arrives.
{
"success": true,
"scanning": false,
"networks": [
{ "ssid": "MyNetwork", "rssi": -55, "encryption": "secured" },
{ "ssid": "Guest", "rssi": -80, "encryption": "open" }
]
}
POST /api/wifi/connect¶
Join a network - what the WiFi setup screen (/wifi) uses. Returns 202 at once; the attempt takes up to 10 seconds. Poll GET /api/status: wifi.connectPending is true while it's trying; afterwards wifi.connected and wifi.ssid tell you whether it worked. On success the credentials are saved and the device restarts onto the network 15 seconds later.
curl -X POST http://sqmeter.local/api/wifi/connect \
-H "Content-Type: application/json" \
-d '{"ssid": "MyNetwork", "password": "hunter2"}'
400 {"error": "Missing SSID or password"} if either field is absent (send "" for an open network).
POST /api/restart¶
Restart the device.
POST /api/display/wake, POST /api/display/blank¶
Wake the OLED display for its switch-off time, or blank it until the next wake (a restart, a wake request or the wake button). No body; answers 200 {"success": true} and the display follows within one loop pass. Requires HTTP auth when enabled.
409 {"error": "Display is off in settings"}, 409 {"error": "Display not detected"}, or (wake only, with power saving from spec 032) 409 {"error": "Display is off to save power"}.
POST /api/update¶
OTA firmware update. Send a raw .bin file as multipart/form-data.
Returns 200 {"success": true} and reboots; 400 {"error": "..."} when the file isn't for this device's partition layout or build (spec 027; nothing was changed); or 500 {"error": "..."} (for example "Could not activate partition") and keeps the running firmware.
POST /api/update/fs¶
OTA filesystem update. Send a LittleFS image as multipart/form-data.
Use this endpoint for web UI assets only. It does not update firmware and does not erase NVS configuration. The image must fill the web UI partition exactly; one for a different layout gets 400 before anything is erased. Responses are as for /api/update.
Both upload endpoints need the password when protection is on. Keep SQMeter on a trusted network and don't port-forward it.
POST /api/mqtt/test¶
Tries to connect to a broker with the given details, without saving them: {"broker": "192.168.1.10", "port": 1883, "username": "", "password": "", "clientId": "SQM-Test"}. Returns 200 {"success": true, "message": "Connection successful"}, or 502 {"error": "Connection timeout", "state": -4}.
A password of ******** (what GET /api/config returns for a saved password) or an empty one means "the saved password", so testing an unchanged form works. The saved password is only used when broker, port and username match the saved settings; a masked password for any other broker returns 400 {"error": "Type the MQTT password to test a broker other than the saved one"}, so a saved secret is never sent to another host.
GET /api/updates/check¶
Checks GitHub Releases for the given track and returns matched firmware+filesystem asset pairs. See OTA Updates for the full flow.
[
{
"tag": "v0.3.0",
"name": "SQMeter v0.3.0",
"prerelease": false,
"publishedAt": "2026-11-01T17:35:57Z",
"firmwareAssetUrl": "https://github.com/DeanJ87/SQMeter/releases/download/v0.3.0/sqmeter-l2-firmware-v0.3.0.bin",
"firmwareAssetSize": 1532128,
"fsAssetUrl": "https://github.com/DeanJ87/SQMeter/releases/download/v0.3.0/sqmeter-l2-littlefs-v0.3.0.bin",
"fsAssetSize": 458752
}
]
track is stable (default) or beta, mapped directly from GitHub's prerelease flag. A release without both a firmware file for this build (sqmeter-l2-firmware-*.bin, or sqmeter-l2-ble-firmware-*.bin on the Bluetooth build) and a sqmeter-l2-littlefs-*.bin file is omitted entirely - so releases for the old partition layout (v0.2) aren't listed.
Errors: 502 {"error": "..."} when GitHub can't be reached or its answer can't be read (a dropped
connection is retried once first), 409 while another check is running.
POST /api/updates/apply¶
Starts a self-download-and-flash of a release returned by check, using its asset URLs directly.
curl -X POST http://sqmeter.local/api/updates/apply \
-H "Content-Type: application/json" \
-d '{
"firmwareAssetUrl": "https://github.com/DeanJ87/SQMeter/releases/download/v0.3.0/sqmeter-l2-firmware-v0.3.0.bin",
"firmwareAssetSize": 1532128,
"fsAssetUrl": "https://github.com/DeanJ87/SQMeter/releases/download/v0.3.0/sqmeter-l2-littlefs-v0.3.0.bin",
"fsAssetSize": 458752
}'
Returns immediately with {"success":true,"message":"Update started"} - the download and flash happen on a background task. Progress and errors are pushed over /ws/status as {"type":"ota_progress","progress":N} messages (or {"error":"..."} on failure). The device reboots automatically once both assets are flashed successfully.
400 {"error": "firmwareAssetUrl and fsAssetUrl are required"}; 409 {"error": "Update already in progress"} while another update is running.
Safety¶
GET /api/safe¶
Plain text 1 (safe) or 0 (unsafe) - the SafetyMonitor verdict, for scripts and loggers (curl -s http://sqmeter.local/api/safe).
GET /api/safety¶
The current SafetyMonitor verdict - safe, the same value served to Alpaca clients as IsSafe - with the reasons behind it. The same object is included as safety in every /ws/sensors message.
{
"safe": false,
"rawSafe": false,
"alpacaEnabled": true,
"reasonFlags": 512,
"reasons": ["Rain 0.40 mm/h"],
"secondsUntilSafe": 0,
"secondsUntilUnsafe": 0,
"rulesNotInEffect": [],
"evaluatedAgeMs": 412,
"changedAgeMs": 1260000,
"dewSuspected": false,
"holds": []
}
| Field | Meaning |
|---|---|
safe |
Reported verdict, after the safe and unsafe delays |
rawSafe |
Instantaneous rule evaluation, before the safe and unsafe delays |
reasons / reasonFlags |
Why the raw verdict is unsafe, also while the unsafe delay still reports safe (bit flags: 0 manual override, 1 no data, 2 stale, 3 sensor fault, 4 cloud, 5 SQM, 6 humidity, 7 dew point, 8 humidity sensor fault, 9 rain, 10 rain sensor fault, 11 wind, 12 gust, 13 wind sensor fault, 14 battery below the limit, 15 battery data missing, 16 shutting down: battery empty, 17 a safety hold set by another system). Bit 0 is also the manual hold |
secondsUntilSafe |
Remaining safe-delay countdown while rawSafe is true but safe isn't yet |
secondsUntilUnsafe |
Remaining unsafe-delay countdown while rawSafe is false but safe is still true |
rulesNotInEffect |
Rules switched on but ignored because what they need is off, e.g. "Unsafe while raining" (they are listed only while the rain sensor is off). Rules that can't measure their limit (wind, cloud, SQM, humidity) report unsafe instead |
changedAgeMs |
Time since safe last changed |
dewSuspected / dew |
Rain needs cloud is on and the rain sensor reports rain under a fresh, healthy clear-sky reading: probably dew on the sensor's lens. Not an unsafe reason - safe, reasons and reasonFlags don't change for it. While it is true, dew has rainIntensity (mm/h), cloudCoverPercent and sinceAgeMs (how long dew has been suspected). Older firmware has neither |
holds |
The safety holds in effect, oldest first: id, reason, source, sinceEpoch (Unix seconds; sinceAgeMs instead when it was set before the clock was), and with an expiry expiresEpoch (when known) and expiresInMs. Each hold's reason is also in reasons |
GET /api/safety/history¶
The last 32 safety changes, device restarts and safe/unsafe alerts sent, newest first. Kept in RTC memory, so it survives software restarts, crashes and OTA updates, not power cuts.
{"boot":3,"uptime":4000,"entries":[
{"kind":"alert","boot":3,"uptime":3900,"timestamp":1759500000,"safe":false},
{"kind":"change","boot":3,"uptime":3899,"timestamp":1759499999,"safe":false,"held":false,"reasonFlags":48},
{"kind":"boot","boot":3,"uptime":0,"resetReason":3}]}
held marks unsafe only because of the safe delay. resetReason is ESP-IDF's esp_reset_reason_t (1 power on, 3 software restart, 4 crash, 5-7 watchdog, 9 brownout). timestamp is missing for entries from before the clock was set.
Safety holds add two kinds: holdSet (a hold set while it was already unsafe - a hold set while safe is the change it causes) and holdCleared (cleared, or lifted at its time), each with holdId. holds lists the holds' short names (a hold's reason up to its first colon: "Smoke: neighbour's fire" is "Smoke"); on change and holdSet every hold set by another system, on holdCleared the one cleared. On holdCleared, reasonFlags is what it is still unsafe for, so {"kind":"holdCleared","holdId":"smoke","holds":["Smoke"],"reasonFlags":16} reads "Hold cleared: Smoke (still unsafe: cloud)".
Safety holds¶
Other systems - Home Assistant, a roll-off-roof controller - hold the SafetyMonitor unsafe for a named event and later clear that event only. While any hold exists the verdict is unsafe (at once, past the unsafe delay); clearing a hold never forces safe - the other rules still decide, and the safe delay applies. Holds survive restarts. Force unsafe (Settings → Safety) is the built-in hold manual. See Safety holds for a Home Assistant example.
POST /api/safety/hold sets one:
{"id": "smoke", "reason": "Smoke: neighbour's fire, PM2.5 85 µg/m³", "source": "Home Assistant", "expiresMin": 240}
id: 1-24 charactersa-z,0-9,_,-. Setting an id again replaces its reason, source and expiry, and keepssince.reason: 1-96 characters, shown on the dashboard, inreasons, in alerts and to Alpaca clients' logs.source(optional, up to 32 characters): who set it; else?source=, elseAPI.expiresMin(optional, 1-10080): lifts the hold by itself after that many minutes. With the clock set it lifts at that time, also after a restart; after a restart before the clock is set it lifts once the full time has passed since the restart - never early.
Answers 200 with the hold (as in holds above), or 400 {"error": "..."} for a bad id, reason, source or expiry, or when 8 holds are already set.
DELETE /api/safety/hold/<id> (or POST /api/safety/hold/<id>/clear for clients that can't send DELETE) clears one: 200 {"cleared": true}, or 404 {"cleared": false, "reason": "no such hold"} when there is none (already cleared, never set) - nothing changes. Clearing manual switches Force unsafe off.
curl -X POST http://sqmeter.local/api/safety/hold -H 'Content-Type: application/json' \
-d '{"id":"smoke","reason":"Smoke: PM2.5 85","source":"Home Assistant"}'
curl -X DELETE http://sqmeter.local/api/safety/hold/smoke
Both need the password when protection is on, like every route that changes something. The same over MQTT: <base>/safety/hold/set.
Alerts¶
See Alerts for setup.
POST /api/alerts/test?channel=<mqtt|pushover|ntfy|webhook|all>¶
Queues a test notification on the given (saved and enabled) channel(s). Returns 202 {"success":true}; delivery happens in the background - check /api/alerts/recent for the result. A channel that is switched on but can't deliver right now (MQTT off, no WiFi) is recorded as skipped with the reason, never failed. Requires HTTP auth when enabled.
Add event=<name>&level=<1-4>&sound=<pushover sound> to send a sample of that event (title "Test: ...") at that level and sound instead. event is one of unsafe, safe, rain_started, rain_stopped, sensor_fault, sensor_recovered, dew_risk, clear_sky, clouded_over, client_lost, client_back, client_disconnected, battery_low, battery_critical, battery_shutdown, power_restored, charge_complete, charge_fault. Level 4 (wake me) also rings paired Bluetooth phones; with no push channel enabled, it only rings the phones. title and message (up to 80 / 240 characters) try out custom wording with {variables}, filled in from current readings.
400 {"error": "..."}, nothing sent: Unknown channel (expected mqtt, pushover, ntfy, webhook or all), Unknown event, Level must be 1-4, Sound name too long (over 32 characters), Title is up to 80 characters and message up to 240, or That channel isn't enabled - enable it and save settings first (and no phone would ring).
GET /api/alerts/armed, POST /api/alerts/arm, POST /api/alerts/disarm¶
Whether alerts are being sent (When to send), for automations:
{"armed": false, "armWithAlpaca": true, "mode": "whileConnected", "reason": "client-disconnected", "since": "2026-10-08T05:42:10Z", "sinceAgeMs": 734000}
armed:truesending,falsepaused.mode:anyorwhileConnected(thesendModesetting);armWithAlpacais its older form.reason: why it's sending or paused -user-ui(the web UI's Pause/Resume),user-rest(arm/disarm),user-mqtt(<base>/alerts/armed/set),client-connected,client-disconnected,waiting-for-client(while-connected mode with nothing connected),migrated(paused before an update that added reasons) ornone.since: when it changed, ISO 8601 UTC;nullwithout a clock.sinceAgeMs: milliseconds since, on the uptime clock;nullif it changed before the last restart.
arm (resume) / disarm (pause) return 202 {"success": true, "armed": true|false}, take effect immediately, and the state survives restarts; while paused nothing is sent and paired phones don't ring. The web UI adds ?source=ui. POSTs require HTTP auth when enabled. /api/alerts/recent also carries armed, and /api/status carries the same object as alerts.
POST /api/alerts/clear¶
Empties the recent-alerts list. Requires HTTP auth when enabled.
GET /api/alerts/recent¶
Whether alerts are on, and the last 20 alerts since boot, newest first:
{"enabled":true,"alerts":[{"id":2,"event":"rain_started","title":"Rain detected","message":"The rain sensor reports rain (2.40 mm/h).","level":"wake","ageSeconds":42,"timestamp":1759500000,
"channels":{"pushover":{"status":"sent","detail":"HTTP 200"},"mqtt":{"status":"failed","detail":"MQTT not connected"}}}]}
status is pending, sent, failed or skipped.
sensor_fault and sensor_recovered are sent once a fault or recovery has lasted alerts.sensorFaultDelaySeconds (default 120); several sensors crossing together give one alert ("Sensor fault: several sensors", "Sensors recovered"). A rain_started on the first drops, before the RG-15 reports a rate, reads "The rain sensor reports the first drops of rain."
Language¶
The device-wide language (Settings → Device → Language, language in
/api/config). English is built in; another language's file is downloaded
from the GitHub release that matches the firmware and stored on the device,
which serves it at /lang.json. See Languages.
GET /api/i18n¶
{ "language": "es", "state": "installed", "firmwareVersion": "0.2.1",
"pack": { "lang": "es", "version": "0.2.1", "size": 22515 } }
state is idle, downloading, installed, failed or restoring (after a
firmware update). pack is null when no file is stored; error says why the
last download failed.
POST /api/i18n/install¶
Downloads the configured language's file again: 202 {"started": true}, or
409 {"error": "..."} when the language is English, a firmware update or
another download is running. Requires the password when protection is on.
POST /api/i18n/upload?lang=<code>&version=<version>¶
Stores a language file uploaded by hand (multipart, a sqmeter-i18n-<code>.json.gz
from the release page), for devices without internet. Answers with the
GET /api/i18n document, or 400 {"error": "..."} for a file that isn't
gzip, is over 64 KB or doesn't fit. Requires the password when protection is on.
Bluetooth phone alarm¶
Bluetooth firmware build only. See Bluetooth.
POST /api/ble/ack¶
Acknowledge the ringing phone alarm from the web UI, as if a phone had. 409 if no alarm is active. Requires HTTP auth when enabled.
POST /api/ble/forget-bonds¶
Unpair every phone; they need to pair again (with the passkey) to get alarms. 409 if Bluetooth is off. Requires HTTP auth when enabled.
ASCOM Alpaca API¶
SQMeter can emit itself directly as an ASCOM Alpaca SafetyMonitor and ObservingConditions device - see ASCOM Alpaca for the full setup guide, N.I.N.A. configuration, and safety-rule reference. Summary of the HTTP surface (all under the same port-80 server as the rest of the API, response envelope per the ASCOM Alpaca API spec):
| Endpoint | Purpose |
|---|---|
GET /management/apiversions |
Supported Alpaca API versions |
GET /management/v1/description |
Server description |
GET /management/v1/configureddevices |
Lists the two devices (empty if Alpaca is disabled in settings) |
GET /setup, GET /setup/v1/<devicetype>/0/setup |
Redirects to Settings → ASCOM Alpaca in the web UI |
GET/PUT /api/v1/<device>/0/connected |
Common ASCOM device API. PUT requires a Connected=true\|false form parameter |
PUT /api/v1/<device>/0/connect, disconnect; GET connecting, devicestate |
ASCOM Platform 7 members (SafetyMonitor interface v3, ObservingConditions interface v2). connecting is always false |
GET /api/v1/<device>/0/name, description, driverinfo, driverversion, interfaceversion, supportedactions |
Common ASCOM device API |
PUT /api/v1/<device>/0/action, commandblind, commandbool, commandstring |
Not supported - Alpaca error 0x400 (NotImplemented) |
GET /api/v1/safetymonitor/0/issafe |
true/false from the safety-rule evaluation |
GET /api/v1/observingconditions/0/<property> |
One route per Alpaca property: cloudcover, dewpoint, humidity, pressure, rainrate (RG-15, mm/h), skybrightness, skyquality, skytemperature, temperature, windspeed/windgust (anemometer, m/s), winddirection (vane), averageperiod. starfwhm, and sensors that aren't enabled, return Alpaca error 0x400 (NotImplemented) |
PUT /api/v1/observingconditions/0/averageperiod, refresh |
AveragePeriod must be 0; refresh is a no-op |
GET /api/v1/observingconditions/0/sensordescription, timesincelastupdate |
Require SensorName (a property name; empty = any sensor for timesincelastupdate) |
<device> is safetymonitor or observingconditions. Parameter names (ClientTransactionID, Connected, ...) are case-insensitive, per the Alpaca spec. Any other path under /api/v1/ (unknown device type/number, method, or HTTP verb) returns HTTP 400 with a plain-text message.
A UDP listener on port 32227 answers Alpaca discovery broadcasts (alpacadiscovery1 → {"AlpacaPort":80}) whenever Alpaca is enabled in settings - this requires a device restart to start/stop, unlike the HTTP routes above which reflect the setting live.