In The Things Stack console, generate API credentials for your application: create an API key with the traffic:read permission under Applications > your-app > API keys; use this key as the MQTT password
Connect your MQTT client to the regional cluster endpoint (e.g., eu1.cloud.thethings.network) on port 8883 with TLS; set Username to <application-id>@<tenant-id> (for The Things Network the tenant is 'ttn') and Password to the API key
Subscribe to the uplink topic v3/<application-id>@<tenant-id>/devices/+/up to receive uplinks from all devices; the + wildcard covers all device IDs within the application
Parse the JSON uplink message: the decoded payload is in uplink_message.decoded_payload if a payload formatter is configured; raw bytes are in uplink_message.frm_payload as a base64-encoded string
To send a downlink, publish a JSON message to v3/<app-id>@<tenant-id>/devices/<device-id>/down/push with {"downlinks":[{"f_port":1,"frm_payload":"<base64>","priority":"NORMAL"}]}; use /down/replace to overwrite the downlink queue
Monitor gateway metadata in the uplink JSON (rx_metadata array) for RSSI, SNR, and gateway IDs; use this to diagnose coverage issues and identify devices with weak signal margins
Known gotchas
LoRaWAN downlinks are subject to regional duty cycle regulations and the network server will queue them; a downlink is not sent immediately but waits for the next receive window (RX1 or RX2) after an uplink — do not expect sub-second command delivery
The base64-encoded frm_payload is the encrypted frame payload; it is only decryptable by the network server and application server — what you receive as decoded_payload has already been decrypted and decoded by the configured payload formatter
The Things Stack MQTT broker does not support QoS 2; publish downlinks at QoS 0 or QoS 1 — the network server handles delivery guarantees at the LoRaWAN MAC layer independently of MQTT QoS
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp