Appearance
HTTP
Post the same payload as MQTT to:
POST https://app.kealink.co.nz/api/v1/machines/<machine-id>/data| Header | Value |
|---|---|
Authorization | HTTP Basic. Username: the machine id itself, the same string as in the address. Password: the machine's password. |
Content-Type | application/json |
The body is one JSON object, or an array of up to 200 objects for buffered readings, up to 16 KB.
Example
sh
curl -u '<machine-id>:<password>' -H 'content-type: application/json' \
-d '{"spindle_temp": 40.1, "running": true}' \
https://app.kealink.co.nz/api/v1/machines/<machine-id>/dataReply
202 Accepted means Kealink took the readings. They are stored a moment later and checked for alerts on the way.
json
{
"accepted": 2,
"unknownKeys": [],
"nonNumericKeys": [],
"duplicateKeys": [],
"timestampsReplaced": 0
}| Field | Meaning |
|---|---|
accepted | Values that will be stored |
unknownKeys | Keys that match no reading of this machine |
nonNumericKeys | Keys whose value had the wrong type for its reading |
duplicateKeys | Keys that named the same reading as an earlier key in the same entry, differing only by case |
timestampsReplaced | Entries whose ts was more than 24 hours old or 5 minutes ahead, so arrival time was used |
hints | Only when there are unknown keys Kealink can explain. A list of { "key", "hint" }. |
Hints point out common mistakes: a key such as timestamp or time that should be ts, a key such as machine_id that is not needed, and a key within two typing mistakes of a real one.
json
{
"accepted": 1,
"unknownKeys": ["machine_id", "timestamp"],
"hints": [
{ "key": "machine_id", "hint": "the machine is already identified by its credentials and its address, so this is not needed." },
{ "key": "timestamp", "hint": "the reading time goes in \"ts\", as Unix milliseconds. Under any other name it is read as a measurement." }
]
}For other status codes see Errors.
Node-RED
Three nodes: inject, a function that builds the payload, then http request. Put a debug node on the output to read the reply.
In the http request node:
- Method POST, URL the address above.
- Tick Use authentication, type basic authentication, with the machine id as the username and its password.
- Return a parsed JSON object.
The body is whatever msg.payload holds:
js
msg.payload = {
ts: Date.now(),
spindle_temp: 40.1,
running: true
};
return msg;Python
python
import os, time, requests
machine_id = os.environ["KEALINK_MACHINE_ID"]
r = requests.post(
f"https://app.kealink.co.nz/api/v1/machines/{machine_id}/data",
auth=(machine_id, os.environ["KEALINK_PASSWORD"]),
json={"ts": int(time.time() * 1000), "spindle_temp": 40.1},
timeout=15,
)
print(r.status_code, r.json())Retrying
On a 503 or a network error, keep the readings with their ts and send them again later, as an array if there are several. Do not retry a 400, 401, 413 or 422 unchanged: the reply says what to fix.