API reference

From bcmeter.org
Revision as of 12:11, 27 November 2026 by Bcmwiki (talk | contribs) (Document local API access, measurement, file export and firmware updates by device version.)
Jump to navigation Jump to search

Local HTTP API

bcMeter Kit and Complete instruments serve the API on the device’s own network over HTTP, port 80. The examples below use ESP32 firmware 1.5.361 and 1.5.681. Read GET /api/status first and use the returned version. Firmware 1.5.681 also returns "platform":"esp32". On 1.5.361 the platform field is absent. On both versions env identifies the build environment.

Connecting

Replace the example hostname with the hostname or LAN IP shown by your device. This read-only example works with both versions.

device='http://bcmeter-XXXX.local'
curl --fail --show-error -H 'X-bcMeter-Client: bcmctl' "$device/api/status"

On the ESP32 market build at 1.5.681, status, CSV and routine controls accept local requests carrying the client header without a 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. On 1.5.361 the local API uses the earlier access model without these proofs.

For an owner request on 1.5.681:

  1. Fetch GET /api/auth/challenge with the client header. The returned nonce is single-use, bound to the requesting client and valid for 30 seconds.
  2. 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.
  3. Send the client header plus X-bcMeter-Nonce, X-bcMeter-Body-SHA256 and X-bcMeter-Proof on the intended request. To check a proof without changing settings, sign GET /api/auth/verify and look for "authorized":true. Obtain a fresh nonce for the next owner request.

heads up for raspberry pi bcmeters

The Pi notes on this page apply to runtime 1.6.15. Check version on your device. Local control requests use the same client header. 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. On 1.5.681, stop_pending means finalization is still running.
GET /api/system · GET /api/logs System reports device, storage and network information. On 1.5.681 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. On 1.5.681, 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. On 1.5.681 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. On 1.5.681 its ordinary response contains a summary.

On 1.5.681, 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

In Pi runtime 1.6.15, 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. On 1.5.681 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. On 1.5.681 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.

On 1.5.681, 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

Pi 1.6.15 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. On 1.5.681 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. On 1.5.681 deletion requires owner proof and ?confirm=wifi-delete.
GET /api/ap-security · POST /api/device/password On 1.5.681 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. On 1.5.681 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. On 1.5.681 apply 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 1.6.15 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 (1.5.681)

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.