API reference: Difference between revisions
Document local API access, measurement, file export and firmware updates by device version. |
Describe current behavior using the software versions listed on the home page. |
||
| Line 1: | Line 1: | ||
== Local HTTP API == | == Local HTTP API == | ||
bcMeter Kit and Complete instruments serve | bcMeter Kit and Complete instruments serve their local API over HTTP on port 80. <code>GET /api/status</code> reports the installed firmware in <code>version</code>, the platform in <code>platform</code> (<code>"esp32"</code> on Kit and Complete), and the build environment in <code>env</code>. | ||
=== Connecting === | === Connecting === | ||
Replace the example hostname with the hostname or LAN IP shown by your device | Replace the example hostname with the hostname or LAN IP shown by your device. | ||
<pre> | <pre> | ||
| Line 12: | Line 12: | ||
</pre> | </pre> | ||
For local status, CSV and routine controls, send <code>X-bcMeter-Client: bcmctl</code>. These requests do not require the device password. Browser clients must use the device's own origin. Owner operations, including Wi-Fi credential changes, require a separate device-password proof for each request. | |||
Use the device password to sign each owner request. | |||
# Fetch <code>GET /api/auth/challenge</code> with the client header. The returned <code>nonce</code> is single-use, bound to the requesting client and valid for 30 seconds. | # Fetch <code>GET /api/auth/challenge</code> with the client header. The returned <code>nonce</code> is single-use, bound to the requesting client and valid for 30 seconds. | ||
| Line 23: | Line 23: | ||
<strong>heads up for raspberry pi bcmeters</strong> | <strong>heads up for raspberry pi bcmeters</strong> | ||
The Pi | The Pi uses the same client header for local control requests. <code>GET /api/maintenance-logs</code> downloads a protected ZIP of operating-system and device diagnostics, which can include recent measurement logs. | ||
</div> | </div> | ||
| Line 31: | Line 31: | ||
! Request !! Result | ! Request !! Result | ||
|- | |- | ||
| <code>GET /api/status</code> || JSON including <code>status</code> (0 idle, 1 starting, 2 sampling, 3 stopped with an error), <code>session</code> (whether a log session is open), <code>error</code>, <code>error_msg</code>, <code>bc</code>, <code>atn</code>, <code>flow</code> (L/min), <code>time_synced</code> and <code>version</code>. | | <code>GET /api/status</code> || JSON including <code>status</code> (0 idle, 1 starting, 2 sampling, 3 stopped with an error), <code>session</code> (whether a log session is open), <code>error</code>, <code>error_msg</code>, <code>bc</code>, <code>atn</code>, <code>flow</code> (L/min), <code>time_synced</code> and <code>version</code>. When <code>stop_pending</code> is true, finalization is still running. | ||
|- | |- | ||
| <code>GET /api/system</code> · <code>GET /api/logs</code> || System reports device, storage and network information. | | <code>GET /api/system</code> · <code>GET /api/logs</code> || System reports device, storage and network information. Some fields such as the MAC address are blank in ordinary reads. Use an owner-signed <code>GET /api/system?private=1</code> for private system details. The logs endpoint returns a structured health report including hardware, measurement, system and network sections. | ||
|- | |- | ||
| <code>GET /api/control?action=synctime&ts=EPOCH&tz=Europe/Berlin</code> || Set the clock using Unix time in seconds. Use the timezone for the measurement site. | | <code>GET /api/control?action=synctime&ts=EPOCH&tz=Europe/Berlin</code> || Set the clock using Unix time in seconds. Use the timezone for the measurement site. | ||
|- | |- | ||
| <code>GET /api/control?action=start</code> · <code>GET /api/control?action=stop</code> || Start a session or request a stop. For a one-session indoor/outdoor selection append <code>&indoor=1</code> or <code>&indoor=0</code> to start. Start can return 409 for an unsynchronized clock, 423 for missing calibration or 424 for calibration older than 28 days. | | <code>GET /api/control?action=start</code> · <code>GET /api/control?action=stop</code> || Start a session or request a stop. For a one-session indoor/outdoor selection append <code>&indoor=1</code> or <code>&indoor=0</code> to start. Start can return 409 for an unsynchronized clock, 423 for missing calibration or 424 for calibration older than 28 days. A 202 stop response means cleanup continues. Wait for <code>stop_pending=false</code> and <code>session=false</code> before treating the file as final. | ||
|- | |- | ||
| <code>GET /api/control?action=calibrate</code> · <code>GET /api/calibration</code> || Install a clean filter and stop sampling before starting calibration. The start call returns 202 when accepted. Poll the second endpoint for <code>running</code>, <code>done</code>, <code>ok</code>, <code>elapsed_ms</code> and <code>log</code>. A finished, successful run has <code>done=true</code> and <code>ok=true</code>. Use the setup wizard for first calibration. | | <code>GET /api/control?action=calibrate</code> · <code>GET /api/calibration</code> || Install a clean filter and stop sampling before starting calibration. The start call returns 202 when accepted. Poll the second endpoint for <code>running</code>, <code>done</code>, <code>ok</code>, <code>elapsed_ms</code> and <code>log</code>. A finished, successful run has <code>done=true</code> and <code>ok=true</code>. Use the setup wizard for first calibration. | ||
|- | |- | ||
| <code>GET /api/config</code> · <code>POST /api/config</code> || Read a JSON object keyed by setting. | | <code>GET /api/config</code> · <code>POST /api/config</code> || Read a JSON object keyed by setting. Entries have <code>value</code>, <code>type</code>, <code>description</code> and <code>parameter</code> (settings group). Send only edited fields as JSON, for example <code>{"sample_time":300}</code> for a 300-second sampling interval. Apply acquisition changes while idle. Owner settings require a proof. A redacted value is unsuitable for copying into a write. | ||
|} | |} | ||
<code>GET /api/control?action=identify</code> flashes the device indicator. <code>GET /api/control?action=clear_error</code> clears the recorded measurement error. <code>GET /api/crash</code> reports the last reset. | <code>GET /api/control?action=identify</code> flashes the device indicator. <code>GET /api/control?action=clear_error</code> clears the recorded measurement error. <code>GET /api/crash</code> reports the last reset. Its ordinary response contains a summary. | ||
Reboot and shutdown require a <code>confirm</code> query parameter matching the action. Erasing stored logs and factory reset require both matching confirmation and an owner proof. A missing confirmation returns 428. Use the device interface for these actions. | |||
<div class="bcmeter-pi-note" role="note" style="border-left:4px solid #356481;background:#eef5f8;color:#162c39;padding:0.7em 1em;margin:1em 0;"> | <div class="bcmeter-pi-note" role="note" style="border-left:4px solid #356481;background:#eef5f8;color:#162c39;padding:0.7em 1em;margin:1em 0;"> | ||
<strong>heads up for raspberry pi bcmeters</strong> | <strong>heads up for raspberry pi bcmeters</strong> | ||
On the Pi, <code>factory_reset</code> stops sampling and resets device settings, including the device password and last calibration date. Stored measurement files, saved Wi-Fi connections and the device-specific correction factor remain. The Pi stays running. Use this action only to restore settings. Unsupported control actions return HTTP 400. | |||
</div> | </div> | ||
| Line 67: | Line 67: | ||
</pre> | </pre> | ||
<code>GET /api/csv</code> without a filename uses the session selected on the device. | <code>GET /api/csv</code> without a filename uses the session selected on the device. It falls back to the newest stored log if the selected session file is unavailable. An idle instrument can therefore return a previous session. If the device has no log to return, the response contains only the CSV header. <code>GET /api/files?name=FILENAME&manifest=1</code> retrieves the session's JSON manifest when available. The list reports <code>manifest_available</code> and <code>active</code>. For SD-card logs use <code>GET /api/sdfiles</code>. | ||
<code>POST /api/files/upload</code> with <code>{"name":"FILENAME"}</code> asks the device to upload the named, completed session. A 202 response means queued. A 422 response can indicate disabled sharing, missing location or provisional timestamps. <code>DELETE /api/files</code> takes the <code>name</code> query parameter, owner proof and <code>confirm=delete_log</code>. The device rejects deletion of its active session with 409. | |||
<div class="bcmeter-pi-note" role="note" style="border-left:4px solid #356481;background:#eef5f8;color:#162c39;padding:0.7em 1em;margin:1em 0;"> | <div class="bcmeter-pi-note" role="note" style="border-left:4px solid #356481;background:#eef5f8;color:#162c39;padding:0.7em 1em;margin:1em 0;"> | ||
<strong>heads up for raspberry pi bcmeters</strong> | <strong>heads up for raspberry pi bcmeters</strong> | ||
Pi | The Pi provides <code>GET /api/csv?view=chart</code> for chart data with precise coordinates removed. A raw CSV download uses the local client header. Without a filename, the Pi serves the active session, the newest stored session, or a header if it has no logs. | ||
</div> | </div> | ||
| Line 84: | Line 84: | ||
| <code>GET /api/wifi/scan?refresh=1</code> · <code>GET /api/wifi/status</code> || Request a scan and read cached results in <code>networks</code> (SSID, RSSI and security flag). Poll <code>/api/wifi/scan</code> while <code>scanning</code> is true. The status endpoint reports the current connection. | | <code>GET /api/wifi/scan?refresh=1</code> · <code>GET /api/wifi/status</code> || Request a scan and read cached results in <code>networks</code> (SSID, RSSI and security flag). Poll <code>/api/wifi/scan</code> while <code>scanning</code> is true. The status endpoint reports the current connection. | ||
|- | |- | ||
| <code>POST /api/wifi/connect</code> · <code>GET /api/wifi/connect/status</code> || Submit JSON with <code>ssid</code> and <code>pass</code> (8–63 characters). After a 202 response, poll connection status for <code>state</code>, <code>log</code> and <code>ip</code>. | | <code>POST /api/wifi/connect</code> · <code>GET /api/wifi/connect/status</code> || Submit JSON with <code>ssid</code> and <code>pass</code> (8–63 characters). After a 202 response, poll connection status for <code>state</code>, <code>log</code> and <code>ip</code>. This operation requires owner access after setup. | ||
|- | |- | ||
| <code>POST /api/wifi</code> · <code>POST /api/wifi/delete</code> || Save Wi-Fi credentials and request reconnection, or forget credentials and return to hotspot mode. The save accepts JSON with <code>ssid</code> and <code>pass</code>. | | <code>POST /api/wifi</code> · <code>POST /api/wifi/delete</code> || Save Wi-Fi credentials and request reconnection, or forget credentials and return to hotspot mode. The save accepts JSON with <code>ssid</code> and <code>pass</code>. Deletion requires owner proof and <code>?confirm=wifi-delete</code>. | ||
|- | |- | ||
| <code>GET /api/ap-security</code> · <code>POST /api/device/password</code> || | | <code>GET /api/ap-security</code> · <code>POST /api/device/password</code> || The first call reports <code>secured</code> and <code>password_set</code>. Its <code>password</code> field is empty. After onboarding, use the second call with the current owner's proof to change the device password. Use the setup wizard to establish the first password. The wizard uses <code>GET</code> and <code>POST /api/onboarding/setup</code> and <code>POST /api/onboarding/claim</code>. | ||
|- | |- | ||
| <code>POST /api/device/rename</code> || Change the device name and local hostname. Send JSON with a <code>name</code> field containing 1–32 characters. | | <code>POST /api/device/rename</code> || Change the device name and local hostname. Send JSON with a <code>name</code> field containing 1–32 characters. This requires owner proof. | ||
|- | |- | ||
| <code>GET /api/ota/status</code> · <code>POST /api/ota/check</code> · <code>POST /api/ota/skip</code> || Read update availability, advertised version and progress, request a new check, or skip the offered version. After requesting a check, read status again. | | <code>GET /api/ota/status</code> · <code>POST /api/ota/check</code> · <code>POST /api/ota/skip</code> || Read update availability, advertised version and progress, request a new check, or skip the offered version. After requesting a check, read status again. | ||
|- | |- | ||
| <code>POST /api/ota/apply</code> · <code>POST /api/update</code> || Apply the update offered by the device or supply a compatible firmware image as a raw binary body. | | <code>POST /api/ota/apply</code> · <code>POST /api/update</code> || Apply the update offered by the device or supply a compatible firmware image as a raw binary body. Applying an offered update requires <code>?confirm=ota_apply</code>. Direct binary upload requires the <code>X-Firmware-SHA256</code> header containing the image digest. A successful update reboots the device. | ||
|} | |} | ||
| Line 100: | Line 100: | ||
<strong>heads up for raspberry pi bcmeters</strong> | <strong>heads up for raspberry pi bcmeters</strong> | ||
The Pi | The Pi setup hotspot stays open. <code>GET /api/ap-security</code> reports that the setting is locked. An offered Pi software update uses <code>POST /api/ota/apply?confirm=ota-apply</code>. A local upload to <code>POST /api/update</code> uses a multipart <code>.tar.gz</code>, <code>.tgz</code> or <code>.zip</code> software archive, an owner proof and the <code>X-Firmware-SHA256</code> header. After installation, the Pi restarts its software service. | ||
</div> | </div> | ||
=== Location, cloud sharing and optical diagnostics | === Location, cloud sharing and optical diagnostics === | ||
{| class="wikitable" | {| class="wikitable" | ||
Revision as of 12:52, 27 November 2026
Local HTTP API
bcMeter Kit and Complete instruments serve their local API over HTTP on port 80. GET /api/status reports the installed firmware in version, the platform in platform ("esp32" on Kit and Complete), and the build environment in env.
Connecting
Replace the example hostname with the hostname or LAN IP shown by your device.
device='http://bcmeter-XXXX.local' curl --fail --show-error -H 'X-bcMeter-Client: bcmctl' "$device/api/status"
For local status, CSV and routine controls, send X-bcMeter-Client: bcmctl. These requests do not require the device password. Browser clients must use the device's own origin. Owner operations, including Wi-Fi credential changes, require a separate device-password proof for each request.
Use the device password to sign each owner request.
- Fetch
GET /api/auth/challengewith the client header. The returnednonceis single-use, bound to the requesting client and valid for 30 seconds. - Compute the lowercase hexadecimal SHA-256 digest of the exact request body, using the empty byte string for a bodyless request. Join the nonce, uppercase HTTP method, exact path including its query string, and body digest with one newline between fields. Compute HMAC-SHA256 over this string with the device password as the key and encode the result in lowercase hexadecimal.
- Send the client header plus
X-bcMeter-Nonce,X-bcMeter-Body-SHA256andX-bcMeter-Proofon the intended request. To check a proof without changing settings, signGET /api/auth/verifyand look for"authorized":true. Obtain a fresh nonce for the next owner request.
heads up for raspberry pi bcmeters
The Pi uses the same client header for local control requests. GET /api/maintenance-logs downloads a protected ZIP of operating-system and device diagnostics, which can include recent measurement logs.
Measurement and configuration
| Request | Result |
|---|---|
GET /api/status |
JSON including status (0 idle, 1 starting, 2 sampling, 3 stopped with an error), session (whether a log session is open), error, error_msg, bc, atn, flow (L/min), time_synced and version. When stop_pending is true, finalization is still running.
|
GET /api/system · GET /api/logs |
System reports device, storage and network information. Some fields such as the MAC address are blank in ordinary reads. Use an owner-signed GET /api/system?private=1 for private system details. The logs endpoint returns a structured health report including hardware, measurement, system and network sections.
|
GET /api/control?action=synctime&ts=EPOCH&tz=Europe/Berlin |
Set the clock using Unix time in seconds. Use the timezone for the measurement site. |
GET /api/control?action=start · GET /api/control?action=stop |
Start a session or request a stop. For a one-session indoor/outdoor selection append &indoor=1 or &indoor=0 to start. Start can return 409 for an unsynchronized clock, 423 for missing calibration or 424 for calibration older than 28 days. A 202 stop response means cleanup continues. Wait for stop_pending=false and session=false before treating the file as final.
|
GET /api/control?action=calibrate · GET /api/calibration |
Install a clean filter and stop sampling before starting calibration. The start call returns 202 when accepted. Poll the second endpoint for running, done, ok, elapsed_ms and log. A finished, successful run has done=true and ok=true. Use the setup wizard for first calibration.
|
GET /api/config · POST /api/config |
Read a JSON object keyed by setting. Entries have value, type, description and parameter (settings group). Send only edited fields as JSON, for example {"sample_time":300} for a 300-second sampling interval. Apply acquisition changes while idle. Owner settings require a proof. A redacted value is unsuitable for copying into a write.
|
GET /api/control?action=identify flashes the device indicator. GET /api/control?action=clear_error clears the recorded measurement error. GET /api/crash reports the last reset. Its ordinary response contains a summary.
Reboot and shutdown require a confirm query parameter matching the action. Erasing stored logs and factory reset require both matching confirmation and an owner proof. A missing confirmation returns 428. Use the device interface for these actions.
heads up for raspberry pi bcmeters
On the Pi, factory_reset stops sampling and resets device settings, including the device password and last calibration date. Stored measurement files, saved Wi-Fi connections and the device-specific correction factor remain. The Pi stays running. Use this action only to restore settings. Unsupported control actions return HTTP 400.
Downloading data
curl --fail --show-error -H 'X-bcMeter-Client: bcmctl' "$device/api/files"
GET /api/files lists session files as a JSON array. Select a returned name. GET /api/csv?file=FILENAME and GET /api/files?name=FILENAME retrieve the selected CSV. For example, set file to a name from the list and run:
curl --fail --show-error -H 'X-bcMeter-Client: bcmctl' --get \ --data-urlencode "file=$file" "$device/api/csv" -o measurement.csv
GET /api/csv without a filename uses the session selected on the device. It falls back to the newest stored log if the selected session file is unavailable. An idle instrument can therefore return a previous session. If the device has no log to return, the response contains only the CSV header. GET /api/files?name=FILENAME&manifest=1 retrieves the session's JSON manifest when available. The list reports manifest_available and active. For SD-card logs use GET /api/sdfiles.
POST /api/files/upload with {"name":"FILENAME"} asks the device to upload the named, completed session. A 202 response means queued. A 422 response can indicate disabled sharing, missing location or provisional timestamps. DELETE /api/files takes the name query parameter, owner proof and confirm=delete_log. The device rejects deletion of its active session with 409.
heads up for raspberry pi bcmeters
The Pi provides GET /api/csv?view=chart for chart data with precise coordinates removed. A raw CSV download uses the local client header. Without a filename, the Pi serves the active session, the newest stored session, or a header if it has no logs.
Wi-Fi and firmware updates
| Request | Result |
|---|---|
GET /api/wifi/scan?refresh=1 · GET /api/wifi/status |
Request a scan and read cached results in networks (SSID, RSSI and security flag). Poll /api/wifi/scan while scanning is true. The status endpoint reports the current connection.
|
POST /api/wifi/connect · GET /api/wifi/connect/status |
Submit JSON with ssid and pass (8–63 characters). After a 202 response, poll connection status for state, log and ip. This operation requires owner access after setup.
|
POST /api/wifi · POST /api/wifi/delete |
Save Wi-Fi credentials and request reconnection, or forget credentials and return to hotspot mode. The save accepts JSON with ssid and pass. Deletion requires owner proof and ?confirm=wifi-delete.
|
GET /api/ap-security · POST /api/device/password |
The first call reports secured and password_set. Its password field is empty. After onboarding, use the second call with the current owner's proof to change the device password. Use the setup wizard to establish the first password. The wizard uses GET and POST /api/onboarding/setup and POST /api/onboarding/claim.
|
POST /api/device/rename |
Change the device name and local hostname. Send JSON with a name field containing 1–32 characters. This requires owner proof.
|
GET /api/ota/status · POST /api/ota/check · POST /api/ota/skip |
Read update availability, advertised version and progress, request a new check, or skip the offered version. After requesting a check, read status again. |
POST /api/ota/apply · POST /api/update |
Apply the update offered by the device or supply a compatible firmware image as a raw binary body. Applying an offered update requires ?confirm=ota_apply. Direct binary upload requires the X-Firmware-SHA256 header containing the image digest. A successful update reboots the device.
|
heads up for raspberry pi bcmeters
The Pi setup hotspot stays open. GET /api/ap-security reports that the setting is locked. An offered Pi software update uses POST /api/ota/apply?confirm=ota-apply. A local upload to POST /api/update uses a multipart .tar.gz, .tgz or .zip software archive, an owner proof and the X-Firmware-SHA256 header. After installation, the Pi restarts its software service.
Location, cloud sharing and optical diagnostics
| Request | Result |
|---|---|
GET /api/location · POST /api/location |
Read available, timezone and the coordinates/source when available. Supply lat and lon as JSON numbers to set a location, with optional IANA timezone. Set next_session_only to true to stage a position for the next session. An active session blocks changes to its current position.
|
POST /api/location/discover |
Request location discovery. Availability depends on location settings, network access and available positioning hardware. |
GET /api/cloud/status · POST /api/cloud/consent |
Check local sharing, server consent and any pending change. Use ?local=1 for local status. The operator must explicitly accept the current privacy notice to enable sharing, or confirm pausing it. Changes can return 202 while synchronization is pending. Pausing stops uploads locally and preserves stored data.
|
POST /api/cloud/upload · GET /api/cloud/upload/status |
Request a cellular upload with owner proof and JSON {"transport":"cellular"}. A 202 response includes a request_id. Read the owner-protected status endpoint for the outcome. Cloud sharing and an available cellular data path are required.
|
POST /api/optical_diagnostic/start · GET /api/optical_diagnostic/status · POST /api/optical_diagnostic/cancel |
Owner proof is required for all three calls. Start takes an empty body and requires ?resume_after=0 or ?resume_after=1 to specify whether to resume an eligible measurement. A 202 response contains run_id. Poll for state, stage and active.
|
For column names, units and file versions, see CSV data format. For filter changes and calibration, see Maintenance.