Skip to main content

Ingest Streaming Data

This guide walks you through the steps to connect a device or sensor to Digital Harbour for real-time data ingestion. Once connected, your device continuously streams data to the platform, where it is stored and made available for visualization and monitoring.

Real-time ingestion uses a secure mutual Transport Layer Security, TLS (mTLS), enrollment process to authenticate your device and establish a trusted connection. Data is written using the InfluxDB line protocol over HTTPS.

Requirements​

Before you can ingest streaming data into Digital Harbour, you will need the following:

  • A Digital Harbour user account. See Create an Account.
  • An approved and activated organization. See Create an Organization.
  • A platform and instrument created and configured in your organization. See Edit Platforms and Instruments.
  • A device or server capable of running a bash script and sending HTTP requests (e.g., a Linux-based sensor, edge device, or server).

Once your instrument is set up, open the Upload Data dialog by selecting the upload icon on the instrument row in the Manage Platforms view.

Manage Platforms view with upload icon highlighted on an instrument row

This opens the Upload Data dialog box, which asks how you would like to upload data. There are three options:

  • Query API — Stream data in real time via mTLS. Follow this guide for this option.
  • File Upload — Upload historical data from a CSV, XML, or JSON file. See Ingest File Data.
  • Get Help — Contact the Digital Harbour team for assistance.

Select Query API to begin the real-time streaming setup.

Upload Data dialog with Query API option highlighted

Streaming Setup: 3-Step Wizard​

Selecting Query API launches a 3-step wizard: Generate Token → Run Script → Write Data.

Step 1: Generate Token​

Select Get Enrollment Token to generate a short-lived credential used to register your device and provision mTLS certificates.

Upload Data wizard Step 1 — Get Enrollment Token button highlighted

note

Enrollment tokens are temporary and expire after a limited time. The token expiry is shown in Step 3 of the wizard once generated. Generate the token only when you are ready to run the enrollment script on your device.

Once the token is generated, the wizard advances to Step 2 and provides the enrollment script to copy and run on your device.

Step 2: Run Script​

Copy the enrollment script from the wizard and run it on the device that will be sending data. The script registers the device with Digital Harbour and provisions mTLS certificates.

bash <(curl -fsSL https://covedigitalharbour.com/app/device-enroll.sh) \
-t <your-enrollment-token> \
-n "<your-device-name>" \
-u https://covedigitalharbour.com/api/enrollInstrument

Where:

  • -t is your enrollment token
  • -n is the name you want to assign to this device and certificate CN. Quote it if it contains spaces.
  • -u is the enrollment API endpoint

During the script, you will be prompted to choose where to store the certificate and private key:

Where would you like to store the certificate and private key?
Certificate directory [/home/<user>/.local/share/certs]:

Press Enter to accept the default location (~/.local/share/certs) or enter a custom path. The script will then generate a private key, create a certificate signing request (CSR), and download a signed client certificate for mTLS authentication.

Once the script completes, the following certificate files will be saved to your chosen directory:

FileDescription
dh_client.crtThe device's mTLS certificate
dh_client.keyThe device's private key

Keep the private key secure and do not share it.

Step 3: Write Data​

Once enrolled, the wizard displays the Write Data step with a pre-built curl command you can copy and run immediately. It also shows the token generation time and expiry.

Upload Data wizard Step 3 — Write Data showing curl command and token expiry

Sending Data to Digital Harbour​

Data is written to the Digital Harbour ingestion endpoint using the InfluxDB line protocol over HTTPS with your mTLS certificates.

Ingestion Endpoint​

POST https://data.cove-digital-harbour.com/api/v2/write

Data Format​

<device-name> <field1>=<value1>,<field2>=<value2> <timestamp_nanoseconds>

For example:

my-sensor temperature=21.5,salinity=34.2 1711324800000000000

Where:

  • my-sensor is the device name used during enrollment
  • temperature=21.5 and salinity=34.2 are field key-value pairs matching your instrument's configured variables
  • 1711324800000000000 is the timestamp in nanoseconds since Unix epoch. Omit the timestamp to use server time instead.

Example curl Write Request​

# Without timestamp (uses server time):
curl -X POST "https://data.cove-digital-harbour.com/api/v2/write" \
--cert ~/.local/share/certs/dh_client.crt \
--key ~/.local/share/certs/dh_client.key \
--data-binary 'my-sensor temperature=21.5,salinity=34.2'

# With explicit nanosecond timestamp:
curl -X POST "https://data.cove-digital-harbour.com/api/v2/write" \
--cert ${CERT_FILE} \
--key ${KEY_FILE} \
--data-binary "${DEVICE_NAME} temperature=21.5,salinity=34.2 ${TIMESTAMP}"

Continuous Streaming​

For ongoing real-time ingestion, run a persistent script or service on the device that receives the live sensor data. In this guide, that process is split into two files:

  • read_buoy.py connects to the data source and translates raw sensor output into clean JSON.
  • push-stream-to-influx.sh reads that JSON, converts it into InfluxDB line protocol, and uploads it securely to Digital Harbour.

Jump to a specific section:

Full Ingestion Process​

The complete ingestion flow has two parts:

  1. A buoy reader collects raw sensor values, normalizes them, and prints one JSON object per timestamp.
  2. The uploader reads those JSON objects from standard input, converts them to InfluxDB line protocol, and sends them to Digital Harbour over HTTPS with mTLS.

In plain terms, the process works like this:

  • Your buoy, buoy gateway, or vendor software produces live sensor data.
  • read_buoy.py connects to that source, translates the raw data into a clean JSON format, and prints it one line at a time.
  • push-stream-to-influx.sh takes each JSON line, converts it into the format Influx expects, and uploads it securely to Digital Harbour.
  • Digital Harbour stores the data and makes it available in the platform for plotting, monitoring, and alerts.

Nothing in this example sends raw buoy packets directly to Influx. The reader script is the translator between the buoy's data format and the standardized format the uploader expects.

In other words:

python3 read_buoy.py | ~/dh-ingest/push-stream-to-influx.sh

The uploader file usually stays the same. What normally changes from one deployment to another is the connection and parsing logic inside read_buoy.py.

Running as a Persistent Service​

The pipe command does not run on its own — it must be started and kept running by a process supervisor. Once it is running and your buoy is sending data to the configured address and port, the pipeline will ingest data to Digital Harbour automatically without any further intervention.

To run the ingestion pipeline as a systemd service that starts on boot and restarts automatically if it stops, create the following unit file on your device:

[Unit]
Description=Digital Harbour stream ingestion
After=network.target

[Service]
User=<your-user>
ExecStart=/bin/bash -c '/home/<your-user>/dh-ingest/read_buoy.py | /home/<your-user>/dh-ingest/push-stream-to-influx.sh'
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

Save it as /etc/systemd/system/dh-ingest.service, then enable and start it:

sudo systemctl daemon-reload
sudo systemctl enable dh-ingest
sudo systemctl start dh-ingest

To check whether it is running and see recent log output:

sudo systemctl status dh-ingest
sudo journalctl -u dh-ingest -f

Example Upstream Buoy Reader​

read_buoy.py is the script that connects directly to your buoy or buoy gateway and translates its raw output into a standardized JSON format that the uploader can process. It does not poll or wait — it is driven by the live data stream itself. As long as the buoy is sending data and the script is running, it reads each incoming message, normalizes it, and passes it to the uploader through the pipe. It only needs to be customized in the connection block at the bottom, which changes depending on how your buoy communicates. See Sensor Connection Types for connection-specific examples.

Save it as ~/dh-ingest/read_buoy.py:

#!/usr/bin/env python3
import json
import re
import time


INSTRUMENT = "my-sensor"


def sanitize_field_name(name):
"""Convert sensor names into Influx-safe field keys."""
name = str(name).strip().lower()
name = re.sub(r"\s+", "_", name)
name = name.replace(",", "_").replace("=", "_")
name = re.sub(r"[^a-z0-9_]", "_", name)
name = re.sub(r"_+", "_", name).strip("_")
return name


def convert_gateway_message(line):
"""
Convert one raw gateway message into the normalized JSON shape expected by
the uploader.
"""
raw = json.loads(line)

ts_ns = raw.get("timestamp_ns", time.time_ns())
fields = {}
for key, value in raw.items():
if key == "timestamp_ns":
continue
if isinstance(value, (int, float)):
fields[sanitize_field_name(key)] = value

return {
"instrument": INSTRUMENT,
"ts_ns": ts_ns,
"fields": fields,
}


# This portion will change relative to your connection type.
# See Sensor Connection Types for more examples.

This reader script does the following:

  • Connects to the buoy or buoy gateway using the connection block at the bottom of the script.
  • Reads incoming data one message at a time, driven by the live feed.
  • Converts each message into a normalized JSON object for one timestamp.
  • Sanitizes field names before they reach the uploader. Field names must match the variable names defined on the instrument — for example, a variable named Water Temperature is sent as water_temperature.
  • Keeps only numeric values.
  • Emits one JSON object per line to standard output.

Important assumptions for this example:

  • INSTRUMENT must match the enrolled device name exactly.
  • Raw sensor names can include spaces or punctuation, but they are normalized before they are sent to the uploader.
  • The reader keeps only numeric telemetry values.
  • Each message should represent one complete sample timestamp for the buoy.

The JSON output from this script should look like this:

{"instrument":"my-sensor","ts_ns":1711324800000000000,"fields":{"water_temperature":21.5,"salinity":34.2,"battery_voltage":12.7}}

To prepare and run the reader by itself:

mkdir -p ~/dh-ingest
chmod +x ~/dh-ingest/read_buoy.py
~/dh-ingest/read_buoy.py

Where to put and run it:

  • Put the script on the buoy computer, edge device, gateway, or server that can reach the live buoy gateway over the network.
  • Run it on the same machine as the uploader when possible, so the JSON stream can be piped directly into push-stream-to-influx.sh.
  • Keep it running as a long-lived process if you need continuous ingestion.

What users may need to change in read_buoy.py:

  • Update INSTRUMENT to match your enrolled device name exactly.
  • Adjust sanitize_field_name() only if your organization needs a different field naming convention.
  • Update convert_gateway_message() if your gateway sends a different JSON structure or uses different timestamp keys.
  • Replace the connection block at the bottom with the appropriate pattern for your connection type. See Sensor Connection Types for examples.
  • Outside the script: make sure the sanitized field names match the instrument variables configured in Digital Harbour.

Example Uploader Script​

Save the following uploader as ~/dh-ingest/push-stream-to-influx.sh:

#!/usr/bin/env bash
set -euo pipefail

usage() {
cat <<'EOF'
Stream Upload Helper

Reads newline-delimited JSON from stdin, converts each JSON object into one
InfluxDB line protocol point, and uploads it to the Digital Harbour write
endpoint using mTLS.
EOF
}

URL="https://data.cove-digital-harbour.com/api/v2/write"
CERT="${HOME}/.local/share/certs/dh_client.crt"
KEY="${HOME}/.local/share/certs/dh_client.key"
DRY_RUN=0

require_command() {
command -v "$1" >/dev/null 2>&1 || {
echo "Required command not found: $1" >&2
exit 1
}
}

while [[ $# -gt 0 ]]; do
case "$1" in
-u) URL="$2"; shift 2 ;;
-c) CERT="$2"; shift 2 ;;
-k) KEY="$2"; shift 2 ;;
--dry-run) DRY_RUN=1; shift ;;
-h|--help) usage; exit 0 ;;
*) echo "Unknown argument: $1" >&2; usage; exit 1 ;;
esac
done

require_command jq
require_command curl

if [[ "$DRY_RUN" -eq 0 ]]; then
[[ -f "$CERT" ]] || { echo "Certificate not found: $CERT" >&2; exit 1; }
[[ -f "$KEY" ]] || { echo "Private key not found: $KEY" >&2; exit 1; }
fi

while IFS= read -r line; do
[[ -n "$line" ]] || continue

payload=$(printf '%s\n' "$line" | jq -er '
.instrument as $instrument
| .ts_ns as $ts_ns
| .fields as $fields
| ($fields | to_entries | map("\(.key)=\(.value)") | join(",")) as $field_string
| "\($instrument) \($field_string) \($ts_ns)"
')

echo "$payload"

if [[ "$DRY_RUN" -eq 0 ]]; then
curl --silent --show-error --fail \
-X POST "$URL" \
--cert "$CERT" \
--key "$KEY" \
--data-binary "$payload" >/dev/null
fi
done

This uploader script does four things:

  • Reads one JSON object per line from standard input.
  • Treats each line as one timestamped measurement for one instrument.
  • Converts the fields object into a comma-separated InfluxDB field list.
  • Uploads the resulting line protocol point to Digital Harbour with curl and mTLS.

Important assumptions for this example:

  • Field names inside fields should already be sanitized for InfluxDB line protocol before they reach this uploader.
  • Field values inside fields should be numeric.

Input messages should look like this:

{"instrument":"my-sensor","ts_ns":1711324800000000000,"fields":{"temperature":21.5,"salinity":34.2,"battery_voltage":12.7}}

To prepare the uploader:

mkdir -p ~/dh-ingest
chmod +x ~/dh-ingest/push-stream-to-influx.sh

Dry Run​

Before sending any data to Digital Harbour, run the uploader with --dry-run to validate your pipeline without making any network requests. In dry-run mode, the script reads from standard input, converts each JSON line to InfluxDB line protocol, and prints the resulting line to the terminal — but skips the curl upload entirely. No certificates are required and nothing is written to Digital Harbour.

cat stream.jsonl | ~/dh-ingest/push-stream-to-influx.sh --dry-run

Use the output to confirm that field names, values, and timestamps are formatted correctly before running live ingestion.

Run​

Once you have verified the output looks correct, run without --dry-run to upload data to Digital Harbour:

cat stream.jsonl | ~/dh-ingest/push-stream-to-influx.sh

To run the complete live ingestion flow:

~/dh-ingest/read_buoy.py | ~/dh-ingest/push-stream-to-influx.sh

Where to put and run it:

  • Put the script on the buoy computer, edge device, gateway, or server that receives the live sensor feed.
  • Run it on the same machine that stores dh_client.crt and dh_client.key, or pass custom certificate paths with -c and -k.
  • Pipe the output of your real sensor-reading process into this script.
  • Run it under systemd, a container, or another supervisor if you need uninterrupted ingestion.

What users may need to change in push-stream-to-influx.sh:

  • Uploader lines 11-13: change the default URL, CERT, or KEY values if your endpoint or certificate paths differ from the defaults.
  • Uploader lines 23-31: use the -u, -c, -k, or --dry-run options instead of editing the script when you only need different runtime settings.
  • Uploader lines 40-45: if your sensor emits a different JSON shape, update the jq expression that maps the input JSON into Influx line protocol.
  • Uploader lines 50-54: modify the curl request only if you need different transport behavior, such as a different write URL or certificate/key locations.
  • Outside the script: make sure instrument matches the enrolled device name exactly, the keys inside fields match your configured instrument variables, and all field values are numeric.

Sensor Connection Types​

Jump to a specific integration pattern:

Serial Port​

  • This process is used when the buoy, logger, or sensor is physically attached to the computer by USB, serial, or RS-232/RS-485.
  • In plain terms, the computer opens a device path such as /dev/ttyUSB0 and listens for live messages coming directly from the instrument.
  • The reader script would replace the socket connection block with pyserial code that opens the serial port, reads each line or packet, and passes that raw message into the conversion function.
  • read_buoy.py changes in two places: the bottom connection block changes from a network socket to a serial read loop, and the conversion function changes only if the serial message format is different.
  • push-stream-to-influx.sh usually does not change at all.
  • Example process: sensor sends serial data -> read_buoy.py reads /dev/ttyUSB0 -> script builds JSON -> uploader converts JSON to line protocol -> uploader sends HTTPS write request to Digital Harbour.

Example script portion that would change in read_buoy.py:

import serial


SERIAL_PORT = "/dev/ttyUSB0"
BAUD_RATE = 9600


def convert_gateway_message(line):
raw = json.loads(line)
ts_ns = raw.get("timestamp_ns", time.time_ns())
fields = {}
for key, value in raw.items():
if key == "timestamp_ns":
continue
if isinstance(value, (int, float)):
fields[sanitize_field_name(key)] = value
return {"instrument": INSTRUMENT, "ts_ns": ts_ns, "fields": fields}


with serial.Serial(SERIAL_PORT, BAUD_RATE, timeout=1) as ser:
while True:
line = ser.readline().decode("utf-8").strip()
if not line:
continue
message = convert_gateway_message(line)
print(json.dumps(message), flush=True)

TCP UDP Socket​

  • This process is used when the buoy or buoy gateway publishes live telemetry over the local network instead of a direct cable.
  • In plain terms, the computer connects to the buoy gateway's IP address and port, then waits for live messages to arrive over TCP or UDP.
  • The example read_buoy.py in this guide already shows the TCP version of this pattern.
  • For TCP, the script opens a connection and reads a continuous stream of newline-delimited messages.
  • For UDP, the script would use a UDP receive loop instead of a TCP stream, but the message-conversion logic usually stays in the same place.
  • read_buoy.py changes in two places: the HOST and PORT settings near the top, and the parsing logic in convert_gateway_message() if the gateway payload format differs.
  • push-stream-to-influx.sh usually does not change at all.
  • Example process: buoy gateway sends telemetry over the network -> read_buoy.py receives the packet or line -> script builds JSON -> uploader converts JSON to line protocol -> uploader sends HTTPS write request to Digital Harbour.

Example script portion that would change in read_buoy.py:

import socket


HOST = "192.168.1.50"
PORT = 5000


def convert_gateway_message(line):
raw = json.loads(line)
ts_ns = raw.get("timestamp_ns", time.time_ns())
fields = {}
for key, value in raw.items():
if key == "timestamp_ns":
continue
if isinstance(value, (int, float)):
fields[sanitize_field_name(key)] = value
return {"instrument": INSTRUMENT, "ts_ns": ts_ns, "fields": fields}


with socket.create_connection((HOST, PORT)) as sock:
stream = sock.makefile("r")
for line in stream:
line = line.strip()
if not line:
continue
message = convert_gateway_message(line)
print(json.dumps(message), flush=True)

UDP version of the connection block:

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(("0.0.0.0", PORT))

while True:
packet, _addr = sock.recvfrom(8192)
line = packet.decode("utf-8").strip()
if not line:
continue
message = convert_gateway_message(line)
print(json.dumps(message), flush=True)

API or SDK​

  • This process is used when the buoy vendor does not expose raw serial or socket messages directly, but instead provides an HTTP API, local software API, or vendor SDK.
  • In plain terms, read_buoy.py asks another piece of software for the latest sample instead of listening to a cable or socket itself.
  • With an API, the reader usually runs a timed loop that makes a request such as GET /latest-sample, then converts the response into the standard JSON shape.
  • With an SDK, the reader imports the vendor library, calls the library's read function, and converts the returned object into the standard JSON shape.
  • read_buoy.py changes in two places: the connection block becomes an API polling loop or SDK call loop, and the conversion function changes to map the API or SDK response fields into instrument, ts_ns, and fields.
  • push-stream-to-influx.sh usually does not change at all.
  • Example process: vendor API or SDK returns the latest measurement -> read_buoy.py normalizes it into JSON -> uploader converts JSON to line protocol -> uploader sends HTTPS write request to Digital Harbour.

Example script portion that would change in read_buoy.py for an HTTP API:

import requests


API_URL = "http://buoy-gateway.local/latest-sample"
POLL_INTERVAL_SECONDS = 30


def convert_gateway_message(raw):
ts_ns = raw.get("timestamp_ns", time.time_ns())
fields = {}
for key, value in raw.items():
if key == "timestamp_ns":
continue
if isinstance(value, (int, float)):
fields[sanitize_field_name(key)] = value
return {"instrument": INSTRUMENT, "ts_ns": ts_ns, "fields": fields}


while True:
response = requests.get(API_URL, timeout=10)
response.raise_for_status()
raw = response.json()
message = convert_gateway_message(raw)
print(json.dumps(message), flush=True)
time.sleep(POLL_INTERVAL_SECONDS)

Example script portion that would change in read_buoy.py for a vendor SDK:

from vendor_sdk import BuoyClient


client = BuoyClient(host="buoy-gateway.local")


def convert_gateway_message(raw):
ts_ns = raw.get("timestamp_ns", time.time_ns())
fields = {}
for key, value in raw.items():
if key == "timestamp_ns":
continue
if isinstance(value, (int, float)):
fields[sanitize_field_name(key)] = value
return {"instrument": INSTRUMENT, "ts_ns": ts_ns, "fields": fields}


while True:
raw = client.read_latest_sample()
message = convert_gateway_message(raw)
print(json.dumps(message), flush=True)
time.sleep(30)

MQTT / Message Broker​

  • This process is used when the buoy or gateway publishes telemetry to a message broker instead of exposing a direct socket, file, or API.
  • In plain terms, read_buoy.py subscribes to a topic, receives each published message, and converts it into the standard JSON format used by the uploader.
  • MQTT is only the transport between the buoy and your reader process. Digital Harbour still receives data through the same HTTPS mTLS uploader shown in this guide.
  • read_buoy.py changes in two places: the connection block becomes an MQTT subscription loop, and the conversion function changes to map each broker message into instrument, ts_ns, and fields.
  • push-stream-to-influx.sh usually does not change at all.
  • Example process: buoy publishes telemetry to MQTT -> read_buoy.py subscribes and receives the message -> script builds JSON -> uploader converts JSON to line protocol -> uploader sends HTTPS write request to Digital Harbour.

Example script portion that would change in read_buoy.py:

import paho.mqtt.client as mqtt


BROKER_HOST = "mqtt.local"
BROKER_PORT = 1883
TOPIC = "buoy/telemetry"


def convert_gateway_message(payload):
raw = json.loads(payload)
ts_ns = raw.get("timestamp_ns", time.time_ns())
fields = {}
for key, value in raw.items():
if key == "timestamp_ns":
continue
if isinstance(value, (int, float)):
fields[sanitize_field_name(key)] = value
return {"instrument": INSTRUMENT, "ts_ns": ts_ns, "fields": fields}


def on_message(client, userdata, msg):
message = convert_gateway_message(msg.payload.decode("utf-8"))
print(json.dumps(message), flush=True)


client = mqtt.Client()
client.on_message = on_message
client.connect(BROKER_HOST, BROKER_PORT, 60)
client.subscribe(TOPIC)
client.loop_forever()

For more robust deployments, run both processes under systemd, a container, Telegraf, or another supervisor that can restart them automatically if they stop.

File or Logger Output​

note

This pattern is not real-time ingestion. It tails a file written by a logger or acquisition service, so data only reaches Digital Harbour after the logger has already written it to disk. If you have a complete or historical log file you want to upload rather than tail, the Ingest File Data guide is a simpler option for that use case.

  • This process is used when another program on the buoy computer or gateway already writes sensor samples to a local file.
  • In plain terms, read_buoy.py watches that file for new lines and converts each new record into the standard JSON format used by the uploader.
  • This is common when a vendor logger or acquisition service is already running and you do not want to replace it.
  • read_buoy.py changes in two places: the connection block becomes a file-tail loop, and the conversion function changes to map each new line into instrument, ts_ns, and fields.
  • push-stream-to-influx.sh usually does not change at all.
  • Example process: logger writes a new sample to a file -> read_buoy.py reads the new line -> script builds JSON -> uploader converts JSON to line protocol -> uploader sends HTTPS write request to Digital Harbour.

Example script portion that would change in read_buoy.py:

LOG_FILE = "/var/log/buoy/latest.jsonl"


def convert_gateway_message(line):
raw = json.loads(line)
ts_ns = raw.get("timestamp_ns", time.time_ns())
fields = {}
for key, value in raw.items():
if key == "timestamp_ns":
continue
if isinstance(value, (int, float)):
fields[sanitize_field_name(key)] = value
return {"instrument": INSTRUMENT, "ts_ns": ts_ns, "fields": fields}


with open(LOG_FILE, "r", encoding="utf-8") as f:
f.seek(0, 2)
while True:
line = f.readline()
if not line:
time.sleep(1)
continue
message = convert_gateway_message(line.strip())
print(json.dumps(message), flush=True)

Verifying Data Ingestion​

After sending data, verify it has been received by navigating to your instrument in Digital Harbour and checking the data preview, or use the Plot Utility to visualize the incoming data stream.

tip

If data is not appearing, confirm that:

  • The device name in the write request matches the name used during enrollment.
  • The timestamp is provided in nanoseconds (or omitted to use server time).
  • The mTLS certificates (dh_client.crt and dh_client.key) have not expired.

Next Steps​