Skip to content

External devices

Integration guide for partners and device makers: how to send readings from your own device to Lutra. In the portal, Settings > API and integrations links here, also to the sample clients; you add the devices themselves per pool, under Devices.

On this page: what you need, registering the device, the message format, sending over HTTPS and MQTT, the sample clients and a security summary.

Lutra can log readings from measuring equipment that is not a Lutra box: your own controller, a PLC, a probe with a network connection. Running your own PLC? See Connecting a PLC for a PLC-specific outline. Once connected, the readings show up in the pool in the Lutra portal with history, charts, alerts, the water profile and the owner view, marked as "Own device (logging only)".

Write only. Your device can only send readings. Lutra never sends anything to it: no commands, no settings, no updates. The device's certificate does not allow it to subscribe or receive, so even a mistake on our side cannot reach your equipment.

1. What you need

  • A device that can make a TLS 1.2 connection with a client certificate (mTLS) to port 8883 (MQTT) or 8443 (HTTPS).
  • OpenSSL (or any tool that can make an EC P-256 key and a certificate signing request, CSR) on that device.
  • An administrator of your Lutra partner account who adds the device to a pool in the portal. See Team and administration.

2. Register the device

  1. In the portal, open the pool, go to Devices > Own devices and choose Add own device. Give it a name and, optionally, the make or model. The portal shows a device ID such as lutra-ext-0a1b2c3d4e5f.
  2. On the device itself, create a key and a CSR whose common name (CN) is exactly that device ID:

    openssl ecparam -name prime256v1 -genkey -noout -out lutra.key
    openssl req -new -key lutra.key -subj "/CN=lutra-ext-0a1b2c3d4e5f" -out lutra.csr
    

    The key (lutra.key) never leaves the device. Do not paste it anywhere, do not email it.

  3. Paste the contents of lutra.csr in the portal and choose Create certificate. Download the certificate (lutra.crt) and the settings file (lutra-extern.json: endpoint, device ID, topic).

  4. Download the AWS root CA: https://www.amazontrust.com/repository/AmazonRootCA1.pem.

Lost the key, or replacing the device? Revoke it in the portal and add a new one. A revoked certificate stops working: new connections and HTTPS requests are refused. The history of the pool stays.

3. Message format

One JSON object per message, UTF-8, at most 4 KB:

{"v": 3, "ts": 1795242969, "seq": 42, "pts": {"ph": 7.2, "orp": 720, "water_temp": 27.5, "pump_running": true}}
Field Required Meaning
v yes always 3
ts yes time of the reading, whole seconds since 1970 (UTC). At most 7 days old and at most 2 minutes in the future
pts yes readings: {quantity: value}, 1 to 40 entries
seq no your own message counter (whole number), helps us spot gaps
boot no your own restart counter (whole number)
units no {quantity: unit} as a check; must be the Lutra unit (see below). Lutra never converts
fw no your software version (text)

Anything else in the message, or a field thing, makes Lutra drop the message.

Quantities and units (selection; the full list is in Quantities):

Quantity Unit Range Type
ph pH 0 to 14 number
orp mV -1500 to 1500 number
free_cl, combined_cl mg/l 0 to 20 number
salt g/l 0 to 60 number
water_temp °C (or C) -5 to 60 number
air_temp, outdoor_temp °C -40 to 70 (outdoor_temp -40 to 60) number
flow_rate m3/h 0 to 500 number
filter_pressure kPa 0 to 1000 number
pump_speed % 0 to 100 number
pump_running, flow, heater_on, light true or false
cover_state open, closed, moving, unknown

A reading with an unknown quantity, the wrong type, or a value outside the range is dropped; the rest of the message is kept. Need a quantity that is not in the list? Ask us; we add it for everyone rather than allowing free names.

Rate: at most 12 messages per minute per device; more are dropped. Every 1 to 5 minutes, plus on a clear change, is plenty.

Keep sending when there is nothing to measure: after 30 minutes without a message Lutra reports the device offline. Many installations only measure water with the pump running (no flow, no valid pH or temperature), so a planned pump pause would look like a dead device. Send the pump state as well (pump_running, flow, and where known pump_speed and flow_rate); those are valid during a pause, so every message still has at least one reading. Silence then really means the device, its source, or the network is down.

4. Sending over HTTPS (port 8443)

Endpoint for all devices: iot.lutrapool.com (HTTPS 8443, MQTT 8883). The settings file from the portal has it too.

The topic goes URL-encoded in the path (/ becomes %2F):

curl --tlsv1.2 --cacert AmazonRootCA1.pem --cert lutra.crt --key lutra.key \
  -H 'content-type: application/json' \
  --data '{"v":3,"ts":1795242969,"pts":{"ph":7.2,"water_temp":27.5}}' \
  'https://iot.lutrapool.com:8443/topics/lutra%2Fv1%2Flutra-ext-0a1b2c3d4e5f%2Ftelemetry?qos=1'

HTTP 200 means AWS IoT accepted the message. It does not mean every reading was valid (see Message format). HTTP 403 means the certificate is not (or no longer) allowed to publish to this topic: check the device ID in the URL and that the device was not revoked.

Python without extra libraries:

import http.client, json, ssl, time, urllib.parse

THING = "lutra-ext-0a1b2c3d4e5f"
ctx = ssl.create_default_context(cafile="AmazonRootCA1.pem")
ctx.load_cert_chain("lutra.crt", "lutra.key")
c = http.client.HTTPSConnection("iot.lutrapool.com", 8443, context=ctx, timeout=10)
path = "/topics/" + urllib.parse.quote(f"lutra/v1/{THING}/telemetry", safe="") + "?qos=1"
body = json.dumps({"v": 3, "ts": int(time.time()), "pts": {"ph": 7.2}})
c.request("POST", path, body=body, headers={"content-type": "application/json"})
print(c.getresponse().status)

5. Sending over MQTT (port 8883)

The MQTT client ID must be exactly the device ID. Publish with QoS 1 to lutra/v1/<device ID>/telemetry. Do not subscribe to anything: it is refused.

import json, time
import paho.mqtt.client as mqtt  # paho-mqtt 2.x

THING = "lutra-ext-0a1b2c3d4e5f"
c = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, client_id=THING)
c.tls_set(ca_certs="AmazonRootCA1.pem", certfile="lutra.crt", keyfile="lutra.key")
c.connect("iot.lutrapool.com", 8883)
c.loop_start()
msg = {"v": 3, "ts": int(time.time()), "pts": {"ph": 7.2, "water_temp": 27.5}}
c.publish(f"lutra/v1/{THING}/telemetry", json.dumps(msg), qos=1).wait_for_publish()
c.disconnect()

6. Sample clients

The snippets in sections 4 and 5 are the smallest working clients: an HTTPS request with curl or plain Python, and an MQTT publish with Python and paho-mqtt. For a device that should keep sending, there is a complete reference client in Python.

Reference client. Download lutra_extern.py (Python 3, standard library only for HTTPS; paho-mqtt 2.x only if you send over MQTT). Start from the settings file lutra-extern.json from step 2 and add where the readings come from (source) and how they map to Lutra quantities (fields); the full list of settings is at the top of the script. Use it as it is, or as an example for a client in another language: the message format is all a client needs to follow.

lutra_extern.py reads a status file or a local status URL of your controller (read only: one file read or one HTTP GET per round; a local API token can be read from a file with "token_file" and is sent as X-Api-Token, never logged), maps fields to Lutra quantities and sends them over HTTPS (or MQTT with paho-mqtt). A failure on either side is logged and skipped; it never touches your controller.

Stale values. Many controllers keep the last reading in their status after a sensor or bus failure. Sent on, that looks like a fresh measurement, which is worse than no value. A field in fields can therefore be an object instead of a path, with conditions; if one fails, that quantity is left out of the message (the rest is sent):

"fields": {
  "water_temp": "devices.pool_water_temp.values.temp_C",
  "ph": {"path": "devices.elite.values.ph",
         "only_if": "devices.elite.values.online",
         "time": "devices.elite.values.last_ok", "max_age_s": 120}
}
Key Meaning
path path to the value (required)
only_if path to a flag that must be exactly true (not 1, not "true"); missing counts as false
time + max_age_s path to the time of the last good reading (seconds since 1970) and the maximum age in seconds; missing, not a number, too old or more than 2 minutes in the future counts as stale. Always together
python3 lutra_extern.py --config /etc/lutra-extern/config.json --once --dry-run   # print one message
python3 lutra_extern.py --config /etc/lutra-extern/config.json                    # run

Example systemd unit (/etc/systemd/system/lutra-extern.service), as its own user with read access to the status file only:

[Unit]
Description=Send pool readings to Lutra (write only)
After=network-online.target

[Service]
User=lutra-extern
ExecStart=/usr/bin/python3 /opt/lutra-extern/lutra_extern.py --config /etc/lutra-extern/config.json
Restart=always
RestartSec=30
NoNewPrivileges=true
ProtectSystem=strict
ReadOnlyPaths=/

[Install]
WantedBy=multi-user.target

7. Security summary

Identity one X.509 certificate per device, key made on the device, signed by AWS IoT Core
Allowed connect as itself; publish to its own lutra/v1/<device ID>/telemetry
Not allowed subscribe, receive, device shadow, jobs, retained messages, any other topic
Where the data goes only to the pool the device was added to, from the moment its certificate was created
Revoking in the portal (administrator); the certificate is deactivated at AWS IoT and detached from the device, and readings no longer reach the pool

Last reviewed: 2026-11-25. Applies to Lutra Lite 0.4.1.