Postlad/Guides/Send sensor data over HTTP

Send sensor data over HTTP from any language

Anything that can make a web request can log a reading: a shell script, a Python job, a Node service, a PowerShell task or a MicroPython board. This page has the same one-line request in each of them, copy-and-paste ready, plus what every reply means.

One request, one readingA script or board sends GET /u with a write key and fields to api.postlad.com, which answers ok 1 and adds the point to a live chart that can be shared.your scriptcurl, Python, Node,PowerShell, MicroPythonGET /u?k=…&f1=23.5ok 1api.postladstores, never dropslive chart
The device only ever talks to api.postlad.com. Viewers open the chart’s share link; they never need the write key.

Every snippet on this page was run against a local copy of the Postlad ingest service on 2026-11-06, and the replies shown are the replies it gave. The MicroPython program was run under desktop Python with stand-ins for its two board modules, not on a board.

The one line

A reading is one GET request. The write key says which stream it belongs to; the fields carry the numbers.

text
http://api.postlad.com/u?k=YOUR_KEY&f1=23.5&f2=61

The reply is plain text. ok 1 means stored, and the number counts the readings your account has stored this month. Anything that was not stored gets an HTTP status of 400 or above and one sentence that says what to do next.

ParameterWhat it isRequired
kThe stream's write key, from the stream's page in the dashboardYes
f1 to f16Up to sixteen numbers. Plain decimals: 23.5, -4, 2.3e-3At least one field or a status
tWhen the reading was taken, as Unix seconds or milliseconds, within 7 days of now. Leave it out and the server's clock is usedNo
statusA short text note, up to 120 bytes, such as batt=3.7V. Only the latest one is keptNo
fmtjson for a JSON reply instead of plain textNo

Those five names are the whole vocabulary. A parameter Postlad does not know is refused rather than ignored, so a typo cannot produce a stream that says ok and stays empty:

text
error unknown_param: "temp" is not a parameter Postlad understands. Valid: k, f1..f16, t, status, fmt. Did you mean f1=?

curl: the first reading

Create a stream, copy its write key, and paste this into a terminal. It works the same on Linux, macOS and Windows 10 or later, which all ship curl.

bash
curl "http://api.postlad.com/u?k=YOUR_KEY&f1=23.5&f2=61"
text
ok 1

Open the stream's page and the point is on the chart. When a value has characters that need escaping, such as the comma and spaces in a status note, let curl encode it:

bash
curl -G "http://api.postlad.com/u" \
  --data-urlencode "k=YOUR_KEY" \
  --data-urlencode "f1=20.5" \
  --data-urlencode "status=batt=3.7V, rssi=-71"

Python, with no packages

The standard library is enough. This works on Python 3.8 or later, including on a Raspberry Pi.

python
# send.py - one reading to Postlad, Python 3 standard library only
import urllib.error
import urllib.parse
import urllib.request

POSTLAD_URL = "http://api.postlad.com/u"
WRITE_KEY = "YOUR_KEY"

def send(**fields):
    query = urllib.parse.urlencode({"k": WRITE_KEY, **fields})
    try:
        with urllib.request.urlopen(f"{POSTLAD_URL}?{query}", timeout=10) as reply:
            print(reply.status, reply.read().decode().strip())
            return True
    except urllib.error.HTTPError as err:
        # Postlad answers every refusal with one sentence that says what to do.
        print(err.code, err.read().decode().strip())
        return False

send(f1=23.5, f2=61)
text
200 ok 2

urlencode takes care of escaping. A refusal raises HTTPError, whose body is the sentence explaining it, which is why the program prints it instead of a stack trace. For a long-running logger with buffering and a systemd service, see the Raspberry Pi data logger guide.

Node.js

Node 18 and later have fetch built in. Save as send.mjs and run node send.mjs.

js
// send.mjs - one reading to Postlad, Node.js 18+ (built-in fetch)
const POSTLAD_URL = "http://api.postlad.com/u";
const WRITE_KEY = "YOUR_KEY";

const url = new URL(POSTLAD_URL);
url.search = new URLSearchParams({ k: WRITE_KEY, f1: 23.5, f2: 61 });

const reply = await fetch(url);
console.log(reply.status, (await reply.text()).trim());

fetch does not throw on a 400 or a 429, so check reply.status: 200 is the only answer that means the reading was stored.

PowerShell on Windows

Works in the PowerShell 5.1 that ships with Windows and in PowerShell 7.

powershell
# send.ps1 - one reading to Postlad, Windows PowerShell 5.1 or PowerShell 7
$WriteKey = "YOUR_KEY"
$Uri = "http://api.postlad.com/u?k=$WriteKey&f1=23.5&f2=61"

try {
    $reply = Invoke-WebRequest -Uri $Uri -UseBasicParsing
    Write-Output "$($reply.StatusCode) $($reply.Content.Trim())"
} catch {
    Write-Output "not stored: $($_.ErrorDetails.Message)"
}

A refused reading lands in the catch block, and ErrorDetails.Message holds Postlad's sentence:

text
not stored: error bad_key: no stream matches that write key. Check k= for a typo, or copy the key again from https://app.postlad.com/streams.

To log something every five minutes, put the script in Task Scheduler with a repeating trigger rather than writing a loop that has to survive restarts.

A shell loop on Linux or a Raspberry Pi

This sends the processor temperature every minute. It is a useful first stream on a Pi because it needs no wiring at all.

bash
#!/bin/sh
# loop.sh - send the CPU temperature of a Linux machine every 60 seconds
WRITE_KEY="YOUR_KEY"

while true; do
  # /sys reports millidegrees: 48312 means 48.312 °C
  CPU=$(awk '{ printf "%.1f", $1 / 1000 }' /sys/class/thermal/thermal_zone0/temp)
  curl -sS --max-time 10 "http://api.postlad.com/u?k=$WRITE_KEY&f1=$CPU"
  sleep 60
done

Or skip the loop and let cron run it once a minute (crontab -e, one line):

text
* * * * * curl -sS --max-time 10 "http://api.postlad.com/u?k=YOUR_KEY&f1=$(awk '{ printf "\%.1f", $1 / 1000 }' /sys/class/thermal/thermal_zone0/temp)" > /dev/null

The % signs are escaped because cron treats a bare % as a newline.

MicroPython on an ESP32 or a Pico W

urequests is included in the standard MicroPython builds for both boards. Save this as main.py on the board.

python
# main.py - MicroPython on an ESP32 or a Raspberry Pi Pico W
import network
import time
import urequests

WIFI_SSID = "YOUR_WIFI_NAME"
WIFI_PASSWORD = "YOUR_WIFI_PASSWORD"
WRITE_KEY = "YOUR_KEY"

wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(WIFI_SSID, WIFI_PASSWORD)
while not wlan.isconnected():
    time.sleep(0.5)
print("Wi-Fi joined:", wlan.ifconfig()[0])

def read_sensor():
    return 23.5  # replace with your sensor's reading

while True:
    url = "http://api.postlad.com/u?k={}&f1={:.2f}".format(WRITE_KEY, read_sensor())
    try:
        reply = urequests.get(url)
        print(reply.status_code, reply.text.strip())
        reply.close()
    except OSError as err:
        print("network error, will try again:", err)
    time.sleep(60)

For a full Pico W project with a real sensor, wiring and a version that uses raw sockets, see the Pico W cloud data logger. For C++ on an ESP32 or ESP8266, start with Send ESP32 data to the cloud, or let the device setup wizard write a complete program for your board and sensor.

POST, JSON and keeping the key out of the URL

The same endpoint accepts POST, either as JSON or as a form. The reply to a JSON request is JSON:

bash
curl -X POST "http://api.postlad.com/u" \
  -H "Content-Type: application/json" \
  -d '{"k":"YOUR_KEY","f1":23.6,"f2":60}'
json
{"ok":true,"stored":1,"month_points":2,"stream":"desk-test","ts":1794024172996}

Proxies and web servers often log full URLs. If yours does, send the key as a header instead, and it stays out of the log line:

bash
curl -H "Authorization: Bearer YOUR_KEY" "https://api.postlad.com/u?f1=20.1"

Timestamps and batches

A reading taken earlier can carry its own time with t, in Unix seconds or milliseconds, up to 7 days back:

bash
# a reading taken an hour ago
curl "http://api.postlad.com/u?k=YOUR_KEY&f1=19.2&t=$(( $(date +%s) - 3600 ))"

A device that was offline can send up to 100 buffered readings in one request to /u/batch. Every point needs a t:

bash
# three readings, two minutes ago, one minute ago and now
NOW=$(date +%s)
curl -X POST "http://api.postlad.com/u/batch" \
  -H "Content-Type: application/json" \
  -d "{\"k\":\"YOUR_KEY\",\"points\":[
        {\"t\":$((NOW - 120)),\"f1\":21.9},
        {\"t\":$((NOW - 60)),\"f1\":22.1},
        {\"t\":$NOW,\"f1\":22.4}]}"
json
{"ok":true,"stored":3,"updated":0,"month_points":11,"stream":"desk-test","first_ts":1794024103000,"last_ts":1794024223000}

Sending the same batch again is safe. A point with a timestamp that is already stored overwrites it instead of being added twice, and the reply says so with "stored":0,"updated":3. The store and forward guide builds a complete buffer around this.

What the replies mean

StatusMeaningWhat your code should do
200StoredCarry on
400The request itself is wrong: a missing key, a field that is not a number, an unknown parameterDo not retry. Print the sentence and fix the code
401, 403The key is wrong, rotated, or the stream is read-onlyDo not retry. Copy the key again from the stream's page
429Too fast for the stream's rate, or the month's allowance is usedWait for the number of seconds in the Retry-After header, then resend
503Postlad could not store it. Our fault, not yoursKeep the reading and retry in 30 seconds

Postlad never answers 200 for a reading it did not store, so a program that treats 200 as the only success can never lose a point without knowing. Every sentence, with its code, is listed in the error catalogue.

How often to send

A stream accepts one reading every 5 seconds on the Free plan. The real limit for continuous logging is the account's monthly allowance of 100,000 readings, shared by all its streams:

One stream sending everyReadings in a 31-day monthFits in Free
5 seconds535,680No, about 6 days' worth
30 seconds89,280Yes
60 seconds44,640Yes, twice over
5 minutes8,928Yes

Up to sixteen fields in one request count as one reading, so send temperature, humidity and pressure together rather than as three requests. On Free, every reading is kept at full detail for 30 days, then an hourly minimum, maximum and average for 12 months. The pricing page has the other plans.

Plain HTTP or HTTPS

Both work, on the same address. Plain http:// is supported on purpose, because the smallest boards have no room for a certificate store, and it never redirects. The trade-off is that anyone who can watch the network can read the reading and the key. Use https:// from anything that can: a computer, a Raspberry Pi, a server. A stream can also be set to refuse plain HTTP altogether.

FAQ

Do I need an SDK, a library or an MQTT broker?

No. A reading is one ordinary HTTP request, so the HTTP client your language already has is enough.

Can I send several values at once?

Yes. Put up to sixteen numbers in f1 to f16 of the same request. They are stored as one reading with one timestamp.

What happens if I send too fast?

The reading is refused with HTTP 429, a Retry-After header and a sentence saying when to resend. It is not stored and not silently dropped, so your code knows to keep it.

Can I name the fields, like temperature instead of f1?

Yes, on the stream's page in the dashboard. Names, units and decimals change the chart, the share page and the CSV export. The device keeps sending f1, f2 and so on.

Can I read the data back from a script?

Yes. Every stream has a JSON read API and a CSV export, documented in the API reference. A read key lets a script read a private stream without being able to write to it.

Get a write key

Create a free account, make a stream, and the first curl line above will put a point on its chart.

Create your free account →

Sources and verification

  • The request, the replies and the error sentences are those of the Postlad ingest service, run locally from the same code that serves api.postlad.com.
  • Full API reference: app.postlad.com/docs/api.