pumpthreeAIDocsOpen the app

Build

Device protocol

How gateways send readings to PumpThree AI. For hardware builders.

Gateways send batches of messages over HTTPS. Every request is signed with the device's secret, so a stolen address alone cannot send data.

Endpoint POST https://www.pumpthree.com/api/ingest/v1/batch with Content-Type: application/json, at most 512 KB and 1,000 messages per batch.

Headers | Header | Value | |---|---| | X-Device-Id | The device id, e.g. dev_3f9a1c2b7d10 | | X-Timestamp | Unix time in milliseconds. Rejected if more than 5 minutes off. | | X-Nonce | A new random string (8 to 64 characters) for every request. Reuse is rejected. | | X-Signature | hex(HMAC-SHA256(secret, timestamp.nonce.sha256(body))) |

Body

{
  "seq": 42,
  "messages": [
    { "type": "tank_reading", "msg_id": "t1-000123", "ts": "2026-10-21T06:40:00Z", "tank": 1, "product_mm": 1520.4, "water_mm": 4, "temp_c": 24.1 },
    { "type": "nozzle_txn", "msg_id": "p2n1-000981", "ts": "2026-10-21T06:41:10Z", "started_at": "2026-10-21T06:39:55Z", "pump": 2, "nozzle": 1, "volume_l": 38.2, "unit_price": 1.52, "currency": "USD" },
    { "type": "nozzle_txn", "msg_id": "p5n1-000044", "ts": "2026-10-21T06:42:00Z", "pump": 5, "nozzle": 1, "pulses": 3820 },
    { "type": "heartbeat", "msg_id": "hb-000777", "ts": "2026-10-21T06:42:05Z", "rssi": -71, "battery_pct": 92, "power_source": "battery", "sim_slot": 1, "buffer_depth": 0, "fw": "1.4.2" },
    { "type": "sensor_event", "msg_id": "ev-000012", "ts": "2026-10-21T01:12:00Z", "kind": "manhole_open" }
  ]
}

Rules - msg_id must be unique per device. Re-sending a message after a dropped connection is safe; duplicates are counted once. - Send buffered readings in time order. Late data up to 30 days old is accepted. - For pulse sensors send pulses; PumpThree AI divides by the nozzle's pulses-per-litre. - tank is the tank number at the station. A probe claimed to a specific tank may omit it. - Sensor kinds: manhole_open, fill_cap_tamper, pump_cabinet_open, safe_open, vapour_high, smoke, sump_leak, phase_separation. - Probes with a phase-separation float add phase_mm to tank_reading: the height of the ethanol-water layer. Stock is measured above whichever is higher, water or phase. A layer of 2 mm or more on a petrol tank raises a critical alert.

Responses 200 with { accepted, duplicates, rejected: [{ msg_id, reason }], alerts, server_time }. Errors: 401 bad_signature | clock_skew | unknown_device, 409 replayed_nonce, 413 too_large, 429 rate_limited (retry after the Retry-After seconds; 60 requests per minute per device).

Config pull GET /api/ingest/v1/config with the same four headers, signed over an empty body. Call it at boot and every hour. Returns { device_id, assigned, model, config, upload_interval_s, tanks: [{ number, product, capacity_l }], firmware, server_time }. Use server_time to correct your clock. assigned: false means the device has not been claimed to a station yet: keep buffering.

Firmware updates When firmware is not null it holds { version, url, sha256 }. Download over HTTPS, check the SHA-256 before flashing, keep the old image for rollback, then report the new version as fw in the next heartbeat. Admins publish builds and choose targets in Admin, Firmware.

MQTT (EMQX) Gateways that prefer MQTT publish to tw/<device-id>/up. The payload is a signed envelope { "device_id", "ts", "nonce", "sig", "body" }, where body is the batch JSON above as a string and sig is computed exactly as for HTTPS. An EMQX rule forwards it to /api/ingest/v1/emqx with the header X-EMQX-Secret. Because the device signs the body, the broker cannot forge readings.

SMS fallback When mobile data is down, send one SMS to the PumpThree AI short code:

P3|dev_3f9a1c2b7d10|1792400000|9c1e0b7a44d2f810|T1:1520.4:4:24.1;T2:980:0:23.8|H-71,92

Fields: P3, device id, Unix seconds, the first 16 hex characters of HMAC-SHA256(secret, everything after the signature field), then T<tank>:<product_mm>:<water_mm>:<temp_c> per tank separated by ;, and an optional H<rssi>,<battery_pct>. Messages older than 6 hours are rejected. Repeats are counted once.

Reference client scripts/gateway-client.mjs in the source repository signs and sends a batch: node scripts/gateway-client.mjs <url> <device-id> <secret> messages.json.