API reference: Difference between revisions

From bcmeter.org
Jump to navigation Jump to search
Restructure: platform separation (ESP32 commercial prioritised, Raspberry Pi DIY in own section); verified against firmware/Pi source; complete serial command list
Keep Raspberry Pi notes focused on differences in operation.
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
== API Reference ==
== Local HTTP API ==


The bcMeter exposes a REST API on port 80. All endpoints are accessible without authentication when connected to the device network. CORS is enabled for all responses (<code>Access-Control-Allow-Origin: *</code>).
The ESP32 bcMeter serves its 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 the assembled instrument), and the build environment in <code>env</code>.


The device identifies its platform via the <code>"env"</code> field in <code>/api/status</code>: <code>"env": "esp32"</code> for bcMeter (commercial) and <code>"env": "pi"</code> for bcMeter (DIY / Raspberry Pi).
Raspberry Pi examples apply to the current DIY software.


The software is source-available — freely available for private, educational and research use (CC BY-NC 4.0): [https://github.com/dahljo/bcmeter-pi github.com/dahljo/bcmeter-pi] (Pi / DIY version).
=== Connecting ===


=== Status & Diagnostics ===
Replace the example hostname with the hostname or LAN IP shown by your device.


{| class="wikitable"
<pre>
! Method !! Endpoint !! Description !! Platforms
device='http://bcmeter-XXXX.local'
|-
curl --fail --show-error -H 'X-bcMeter-Client: bcmctl' "$device/api/status"
| GET || <code>/api/status</code> || Current measurement state, last sensor readings (BC, ATN, sensor/reference voltages, flow, filter loading), error codes, sample count, session active, WiFi mode/SSID/RSSI, internet flag, firmware version, OTA result flag, time-sync state. || Both
</pre>
|-
| GET || <code>/api/system</code> || Hardware info: IP, MAC address, heap and PSRAM usage, flash usage, modem status and signal, GPS detail, barometric altitude, geolocation source, current time, cycle timing statistics. || Both
|-
| GET || <code>/api/logs</code> || Structured health report as JSON with sections: <code>hardware</code>, <code>measurement</code>, <code>system</code>, <code>network</code>, <code>incidents</code>. Each entry has <code>{k, v, s}</code> (key, value, status: ok/warn/error/info). || Both
|-
| GET || <code>/api/debug_mobile/status</code> || Returns modem debug email send progress (from email handler). || Both
|}


=== Measurement Control ===
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.


All control is dispatched through a single endpoint with an <code>action</code> query parameter:
Use the device password to sign each owner request.


{| class="wikitable"
# 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.
! Method !! Endpoint !! Description !! Platforms
# 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 <code>X-bcMeter-Nonce</code>, <code>X-bcMeter-Body-SHA256</code> and <code>X-bcMeter-Proof</code> on the intended request. To check a proof without changing settings, sign <code>GET /api/auth/verify</code> and look for <code>"authorized":true</code>. Obtain a fresh nonce for the next owner request.
| GET || <code>/api/control?action=start</code> || Begin measurement session. Returns 409 if time not synced, 423 if never calibrated, 424 if calibration stale (>28 days). Add <code>&force=1</code> to override preflight checks. Optional <code>&indoor=0|1</code> for one-shot indoor/outdoor override. || Both
|-
| GET || <code>/api/control?action=stop</code> || Stop measurement and finalise session file. || Both
|-
| GET || <code>/api/control?action=calibrate</code> || Start optical calibration routine (returns 202 immediately — poll <code>/api/calibration</code> for progress). Requires sampling to be stopped. || Both
|-
| GET || <code>/api/calibration</code> || Calibration status: <code>{running, done, ok, elapsed_ms, log}</code>. || Both
|-
| GET || <code>/api/control?action=clear_error</code> || Reset error state to ERR_NONE. || Both
|-
| GET || <code>/api/control?action=identify</code> || Triggers LED identify blink pattern (Morse code "bcmeter", ~30 seconds). Useful for locating a specific device when multiple units are deployed. || Both
|-
| GET || <code>/api/control?action=debug_mobile</code> || Triggers modem debug email via Lambda. Requires modem present. Returns 409 if modem unavailable or already running. || Both
|-
| GET || <code>/api/control?action=synctime&ts=EPOCH&tz=IANA</code> || Sync device clock. <code>ts</code> = Unix timestamp, <code>tz</code> = IANA timezone string (e.g. <code>Europe/Berlin</code>). || Both
|-
| GET || <code>/api/control?action=cleardata</code> || Delete all stored log files. || Both
|-
| GET || <code>/api/control?action=reboot</code> || End session and reboot the device. || Both
|-
| GET || <code>/api/control?action=shutdown</code> || Safely shut down the device. || Both
|-
| GET || <code>/api/control?action=factory_reset</code> || Permanently erase all logs, WiFi credentials, calibration data, and settings. Reboots into factory state. || Both
|}


=== Configuration ===
<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>For bcMeter V1 and Raspberry Pi DIY User</strong>


{| class="wikitable"
Request the protected <code>GET /api/maintenance-logs</code> ZIP when you need a support bundle. Review it before sharing since it can include recent measurement logs.
! Method !! Endpoint !! Description !! Platforms
</div>
|-
| GET || <code>/api/config</code> || All settings as JSON. Each parameter includes type, value, label, tab, and description. || Both
|-
| POST || <code>/api/config</code> || Update settings. JSON body with key-value pairs. Accepts <code>{key: value}</code> or <code>{key: {value: ...}}</code> format. Only changed values need to be sent. || Both
|-
| POST || <code>/api/device/rename</code> || Set device name. Body: <code>{"name": "bcmeter-A3AB"}</code> (1–32 chars). Updates mDNS/hostname accordingly. || Both
|-
| GET || <code>/api/ap-security</code> || Hotspot security settings: <code>{secured: bool, password: str}</code>. || Both
|-
| POST || <code>/api/ap-security</code> || Update hotspot password. Body: <code>{"secured": true, "password": "..."}</code> (min 8 chars). || Both
|-
| POST || <code>/api/email/validate</code> || Validate email API key against the Lambda endpoint. Body: <code>{"api_key": "..."}</code>. Returns <code>{valid: bool, error: str}</code>. || Both
|}


=== WiFi Management ===
=== Measurement and configuration ===


{| class="wikitable"
{| class="wikitable"
! Method !! Endpoint !! Description !! Platforms
! Request !! Result
|-
| GET || <code>/api/wifi/scan</code> || List nearby networks: <code>{scanning: bool, networks: [{ssid, rssi, secure}]}</code>. Add <code>?refresh=1</code> to trigger a new background scan. || Both
|-
|-
| GET || <code>/api/wifi/status</code> || Current connection: <code>{mode, status, ssid, ip, rssi, quality (0-4), internet, timeSynced}</code>. || Both
| <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.
|-
|-
| POST || <code>/api/wifi</code> || Save WiFi credentials. Body: <code>{"ssid": "...", "pass": "..."}</code> (password min 8 chars). Initiates reconnect. || Both
| <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.
|-
|-
| POST || <code>/api/wifi/connect</code> || Save credentials and initiate background connection attempt (returns 202). Password must be 8–63 chars. Body: <code>{"ssid": "...", "pass": "..."}</code>. || Both
| <code>GET /api/control?action=synctime&amp;ts=EPOCH&amp;tz=Europe/Berlin</code> || Set the clock using Unix time in seconds. Use the timezone for the measurement site.
|-
|-
| GET || <code>/api/wifi/connect/status</code> || Connection progress: <code>{state: 0-3, elapsed, log, mode, ip, ssid, device_name, hostname}</code>. States: 0=idle, 1=connecting, 2=success, 3=failed. Poll after POST to <code>/api/wifi/connect</code>. || Both
| <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>&amp;indoor=1</code> or <code>&amp;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.
|-
| POST || <code>/api/wifi/delete</code> || Delete credentials and switch to AP mode (deferred 2s background switch). || Both
|-
| POST || <code>/api/wifi/scan/refresh</code> || Explicitly trigger a new WiFi scan (returns 202, or 409 if already scanning). || Both
|}
 
=== Data Management ===
 
{| class="wikitable"
! Method !! Endpoint !! Description !! Platforms
|-
|-
| GET || <code>/api/csv</code> || Current session CSV data. Returns header-only if no active session. Add <code>?file=FILENAME</code> for archived files. || Both
| <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.
|-
|-
| GET || <code>/api/files</code> || List stored CSV logs: <code>[{name, size, lines, date}]</code> sorted newest first. Add <code>?name=FILENAME</code> to download a specific file. || Both
| <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.
|}
|}


=== Firmware Updates ===
<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.


{| class="wikitable"
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.
! Method !! Endpoint !! Description !! Platforms
|-
| GET || <code>/api/ota/status</code> || Check if update available: <code>{available, version, notes, apply_state, apply_progress, apply_error}</code>. || Both
|-
| POST || <code>/api/ota/check</code> || Force check for new firmware. || Both
|-
| POST || <code>/api/ota/skip</code> || Skip current available update. || Both
|-
| POST || <code>/api/ota/apply</code> || Download and apply firmware update. Returns 409 if none pending. || Both
|-
| POST || <code>/api/update</code> || Direct firmware upload. ESP32: accepts a raw <code>.bin</code> file, flashes to the OTA partition, reboots. Pi: accepts a <code>.tar.gz</code> or <code>.zip</code> archive, extracts over the code directory, restarts the <code>bcMeter.service</code>. || Both
|}


=== Captive Portal ===
<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>For bcMeter V1 and Raspberry Pi DIY User</strong>


These endpoints handle captive portal detection on mobile devices and redirect to the main interface in AP mode:
The <code>factory_reset</code> action requires an owner proof and <code>confirm=factory-reset</code>. It stops sampling and restores settings, including the device password and last calibration date. Measurement files, saved Wi-Fi connections and the device-specific correction factor remain. The Pi stays running. Unsupported control actions return HTTP 400.
</div>


{| class="wikitable"
=== Downloading data ===
! Endpoint !! Purpose
|-
| <code>/generate_204</code> || Android captive portal check
|-
| <code>/hotspot-detect.html</code> || Apple captive portal check
|-
| <code>/canonical.html</code> || Firefox captive portal check
|-
| <code>/ncsi.txt</code> || Windows captive portal check
|-
| <code>/success.txt</code> || Generic connectivity probe (returns <code>"success"</code>)
|}


=== Static Routes ===
<pre>
curl --fail --show-error -H 'X-bcMeter-Client: bcmctl' "$device/api/files"
</pre>


{| class="wikitable"
<code>GET /api/files</code> lists session files as a JSON array. Select a returned <code>name</code>. <code>GET /api/csv?file=FILENAME</code> and <code>GET /api/files?name=FILENAME</code> retrieve the selected CSV. For example, set <code>file</code> to a name from the list and run:
! Path !! Description
|-
| <code>/</code> || Serves the SPA frontend
|-
| <code>/discover</code> || Standalone device discovery page
|-
| <code>/current_log.csv</code> || Legacy redirect to <code>/api/csv</code>
|}


=== bcMeter (DIY) — Raspberry Pi OS-level extras ===
<pre>
curl --fail --show-error -H 'X-bcMeter-Client: bcmctl' --get \
  --data-urlencode "file=$file" "$device/api/csv" -o measurement.csv
</pre>


The following endpoints exist '''only on the Raspberry Pi''' version. They use Linux system commands and are not applicable to the ESP32.
<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&amp;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>.


{| class="wikitable"
<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.
! Method !! Endpoint !! Description
|-
| GET || <code>/api/maintenance-logs</code> || Downloads a zip bundle containing: rotating bcmeter.log files, syslog, 10 newest CSV sessions, dmesg, journalctl output for bcmeter and pigpiod services, config JSON, incident log. Uses <code>journalctl</code> and <code>dmesg</code> — Linux only.
|}


Additionally, on the Pi:
<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>For bcMeter V1 and Raspberry Pi DIY User</strong>


* <code>/api/control?action=reboot</code> runs <code>sudo reboot</code> (Pi: <code>routes_control.py:151</code>)
Use <code>GET /api/csv?view=chart</code> to retrieve chart data with precise coordinates removed. For raw CSV, send the local client header. Omit the filename to select the active session, the newest saved session, or a header when there are no logs.
* <code>/api/control?action=shutdown</code> runs <code>sudo shutdown -h now</code> (Pi: <code>routes_control.py:161</code>)
</div>
* <code>/api/control?action=synctime</code> sets the timezone via <code>sudo timedatectl set-timezone</code> (Pi: <code>routes_control.py:276</code>)
* <code>/api/device/rename</code> calls <code>sudo hostnamectl set-hostname</code> and restarts avahi (Pi: <code>bcmeter/identity.py:41</code>)
* <code>/api/update</code> runs <code>sudo systemctl restart bcMeter.service</code> after extracting the archive (Pi: <code>routes_update.py:134</code>)


The following endpoints exist only on the Pi and have no ESP32 equivalent:
=== Wi-Fi and firmware updates ===


{| class="wikitable"
{| class="wikitable"
! Method !! Endpoint !! Description
! Request !! Result
|-
|-
| GET || <code>/api/qc/pi/report</code> || Pi QC test report as JSON.
| <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.
|-
|-
| GET || <code>/api/qc/pi/report.html</code> || Pi QC test report as HTML.
| <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.
|-
|-
| POST || <code>/api/qc/pi/start</code> || Start the Pi QC test sequence.
| <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>.
|-
|-
| GET || <code>/api/qc/pi/status</code> || Pi QC test status.
| <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>.
|-
|-
| GET || <code>/api/lab/run</code> || Lab/engineering raw ADC capture (Pi equivalent of ESP32 serial LAB mode).
| <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.
|-
|-
| GET || <code>/api/lab/info</code> || Lab session status.
| <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. 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.
|}
|}


The following endpoints exist only on the '''ESP32''' and have no Pi equivalent:
<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>For bcMeter V1 and Raspberry Pi DIY User</strong>
 
<code>GET /api/ap-security</code> reports that the setup hotspot is locked open. Apply an offered update with <code>POST /api/ota/apply?confirm=ota-apply</code>. To install a local archive, upload it to <code>POST /api/update</code> as multipart data with an owner proof and the <code>X-Firmware-SHA256</code> header. Use <code>.tar.gz</code>, <code>.tgz</code> or <code>.zip</code> and wait for the web interface to reconnect.
</div>
 
=== Location, cloud sharing and optical diagnostics ===


{| class="wikitable"
{| class="wikitable"
! Method !! Endpoint !! Description
! Request !! Result
|-
| GET || <code>/api/sdfiles</code> || List CSV files on the SD card.
|-
| GET || <code>/api/crash</code> || Last crash/reset report from CrashReport module.
|-
| GET || <code>/api/coredump</code> || Stream the raw ELF coredump from the coredump flash partition. Add <code>?erase=1</code> to erase after download.
|-
| GET || <code>/api/modem/test</code> || Run modem AT diagnostic and return results as JSON.
|-
| POST || <code>/api/lab/start</code> || Start a lab ADC capture session (params: <code>led_ch</code>, <code>led_duty</code>, <code>pump_duty</code>, <code>pump_hz</code>).
|-
|-
| POST || <code>/api/lab/stop</code> || Stop the lab capture session.
| <code>GET /api/location</code> · <code>POST /api/location</code> || Read <code>available</code>, <code>timezone</code> and the coordinates/source when available. Supply <code>lat</code> and <code>lon</code> as JSON numbers to set a location, with optional IANA <code>timezone</code>. Set <code>next_session_only</code> to true to stage a position for the next session. An active session blocks changes to its current position.
|-
|-
| GET || <code>/api/lab/status</code> || Lab session status: active, pairs captured, LED/pump settings.
| <code>POST /api/location/discover</code> || Request location discovery. Availability depends on location settings, network access and available positioning hardware.
|-
|-
| POST || <code>/api/raw_capture/enable</code> || Toggle raw ADC sample capture ring buffer (param: <code>on=0|1</code>).
| <code>GET /api/cloud/status</code> · <code>POST /api/cloud/consent</code> || Check local sharing, server consent and any pending change. Use <code>?local=1</code> 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.
|-
|-
| GET || <code>/api/raw_capture/read</code> || Drain the raw capture ring buffer as binary float32 pairs (8 bytes each). <code>X-Dropped</code> header reports overflow count.
| <code>POST /api/cloud/upload</code> · <code>GET /api/cloud/upload/status</code> || Request a cellular upload with owner proof and JSON <code>{"transport":"cellular"}</code>. A 202 response includes a <code>request_id</code>. Read the owner-protected status endpoint for the outcome. Cloud sharing and an available cellular data path are required.
|-
|-
| GET || <code>/api/qc/sensors</code> || Live SPS30 + env-sensor read for QC (409 while sampling).
| <code>POST /api/optical_diagnostic/start</code> · <code>GET /api/optical_diagnostic/status</code> · <code>POST /api/optical_diagnostic/cancel</code> || Owner proof is required for all three calls. Start takes an empty body and requires <code>?resume_after=0</code> or <code>?resume_after=1</code> to specify whether to resume an eligible measurement. A 202 response contains <code>run_id</code>. Poll for <code>state</code>, <code>stage</code> and <code>active</code>.
|-
| GET || <code>/api/qc/diag</code> || Passive diagnostic snapshot: heap, PSRAM, uptime, reset reason, WiFi, modem state. No AT calls.
|-
| GET || <code>/api/qc/pump_ramp/status</code> || QC pump ramp test status.
|-
| GET || <code>/api/qc/led_880/status</code> || QC LED stability test status.
|}
|}


=== Example: Start a Measurement ===
For column names, units and file versions, see [[CSV data format]]. For filter changes and calibration, see [[Maintenance]].
 
<pre>
# Sync time first
curl "http://bcmeter-XXXX.local/api/control?action=synctime&ts=$(date +%s)&tz=Europe/Berlin"
 
# Start measurement
curl "http://bcmeter-XXXX.local/api/control?action=start"
 
# Poll status
curl "http://bcmeter-XXXX.local/api/status"
 
# Download current data
curl "http://bcmeter-XXXX.local/api/csv" -o measurement.csv
</pre>

Latest revision as of 14:01, 27 November 2026

Local HTTP API

The ESP32 bcMeter serves its local API over HTTP on port 80. GET /api/status reports the installed firmware in version, the platform in platform ("esp32" on the assembled instrument), and the build environment in env.

Raspberry Pi examples apply to the current DIY software.

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.

  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.

For bcMeter V1 and Raspberry Pi DIY User

Request the protected GET /api/maintenance-logs ZIP when you need a support bundle. Review it before sharing since it 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.

For bcMeter V1 and Raspberry Pi DIY User

The factory_reset action requires an owner proof and confirm=factory-reset. It stops sampling and restores settings, including the device password and last calibration date. Measurement files, saved Wi-Fi connections and the device-specific correction factor remain. The Pi stays running. 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.

For bcMeter V1 and Raspberry Pi DIY User

Use GET /api/csv?view=chart to retrieve chart data with precise coordinates removed. For raw CSV, send the local client header. Omit the filename to select the active session, the newest saved session, or a header when there are 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.

For bcMeter V1 and Raspberry Pi DIY User

GET /api/ap-security reports that the setup hotspot is locked open. Apply an offered update with POST /api/ota/apply?confirm=ota-apply. To install a local archive, upload it to POST /api/update as multipart data with an owner proof and the X-Firmware-SHA256 header. Use .tar.gz, .tgz or .zip and wait for the web interface to reconnect.

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.