Onboard your first device
By the end of this tutorial you will have registered a device with Beacon Tower, activated it, fetched its connection settings the way the device itself would, and watched telemetry arrive. It takes about 20 minutes.
You will use one simulated device and a shared key. Every value below is fixed — copy the commands as written.
Before you start
You need:
curl,jq, and Python 3.9 or later withpaho-mqttinstalled (pip install paho-mqtt)- A Beacon Tower access token — see Authentication
- An organization id and an asset model id from your tenant
- The hostname of your provider's MQTT broker
Set these once:
export API="https://api.example.com/api"
export TOKEN="YOUR_ACCESS_TOKEN"
export ORG_ID="YOUR_ORGANIZATION_ID"
export MODEL_ID="YOUR_MODEL_ID"
export BROKER_HOST="YOUR_BROKER_HOST"
Step 1 — Create a routing target
A routing target answers two questions, both asked when a device onboards: where should it connect, and which provider should create it.
deviceEndpoints is the broker address the platform hands to the device — it
fills the {{brokerUrl}} and {{brokerPort}} placeholders that
GET /get_settings returns in step 7. providerId names the provider that
creates the device's records: the provider client, the MQTT user, the broker
ACL and the twin.
It is separate from the enrollment group because several groups, with different attestation rules, can share one broker — and if the broker moves, you change one routing target instead of every group.
List your providers with GET /providers if you do not know the id.
curl -s -X POST "$API/routing-targets" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Tutorial Target",
"deviceEndpoints": [{ "type": "mqtt", "host": "'"$BROKER_HOST"'", "port": 8883 }],
"config": { "transport_mode": "http" },
"providerId": "YOUR_PROVIDER_ID"
}' | tee /tmp/target.json | jq
Save the id:
export TARGET_ID=$(jq -r .id /tmp/target.json)
echo "$TARGET_ID"
You should see a UUID.
Step 2 — Create an enrollment group
curl -s -X POST "$API/enrollment-groups" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Tutorial Sensors",
"routingTargetId": "'"$TARGET_ID"'",
"organizationId": "'"$ORG_ID"'",
"modelId": "'"$MODEL_ID"'",
"workflows": ["device-activation"],
"attestationType": "sharedKey",
"operationalCredential": "symmetricKey",
"responseTemplate": {
"mqtt_host": "{{brokerUrl}}",
"mqtt_port": "{{brokerPort}}",
"device_id": "{{deviceId}}",
"primary_key": "{{primaryKey}}"
}
}' | tee /tmp/group.json | jq
export GROUP_ID=$(jq -r .id /tmp/group.json)
echo "$GROUP_ID"
The response echoes "workflows": ["device-activation"]. That is the group's runnable set.
Step 3 — Generate a shared key
curl -s -X POST "$API/enrollment-groups/$GROUP_ID/shared-keys/generate" \
-H "Authorization: Bearer $TOKEN" | tee /tmp/sharedkey.json | jq
export PRIMARY_KEY=$(jq -r .primaryKey /tmp/sharedkey.json)
{ "primaryKey": "<44-character key>", "secondaryKey": null }
Keep this key. A shared-key device authenticates to /get_settings with it in
step 7.
Step 4 — Register a device
curl -s -X POST "$API/devices/register" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"deviceId": "tutorial-sensor-001",
"enrollmentGroupId": "'"$GROUP_ID"'"
}' | tee /tmp/device.json | jq
{
"deviceId": "tutorial-sensor-001",
"attestationType": "sharedKey",
"enrollmentGroupId": "...",
"secret": null,
"sharedKeyReference": "enrollment-group:<group-id>:primary"
}
For a shared-key group secret is null. The device proves membership
with the group's shared key from step 3, which is what sharedKeyReference
names — so that is what you use in step 7:
export DEVICE_SECRET="$PRIMARY_KEY" # the group shared key from step 3
A per-device secret is issued only by the secret attestation type, which is
a different kind of group.
Step 5 — See what activation needs
curl -s "$API/enrollment-groups/$GROUP_ID/workflows/device-activation" \
-H "Authorization: Bearer $TOKEN" | jq '.callerRequiredInputs'
["device.id", "customer.id", "meter.id", "meter.address", "asset.id"]
Those keys are what your run request must carry. The group supplies the rest.
Always read this list rather than copying it — it depends on the group. A group
that sets asset.id itself through workflowInputs will not ask the caller
for it, and a group with no providerTemplateId will also require
provider_template.id.
Step 6 — Activate the device
curl -s -X POST "$API/enrollment-groups/$GROUP_ID/workflows/device-activation/run" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"params": {
"device.id": "tutorial-sensor-001",
"customer.id": "tutorial-customer",
"meter.id": "tutorial-meter-1",
"meter.address": "1 Example Street",
"asset.id": "tutorial-meter-1"
}
}' | jq
{ "deviceId": "tutorial-sensor-001", "created": true }
created: true means the device was newly provisioned.
The run does more than register the device. It creates the provider client, the
MQTT user and its broker ACL, the device twin, and an asset named from
asset.id — then binds that asset to the provider client. One call covers what
"Your First Asset via API" does in four.
Activation is not instant; a run takes tens of seconds. If step 7 answers
403 device_not_provisioned, the run has not finished.
Step 7 — Fetch settings as the device
The device fetches its own connection settings from the device-facing endpoint. This is a different host from the management API:
export DEVICE_API="https://devices.example.com"
curl -s "$DEVICE_API/get_settings" \
-u "tutorial-sensor-001:$DEVICE_SECRET" | tee /tmp/settings.json | jq
{
"mqtt_host": "your-broker-host",
"mqtt_port": 8883,
"device_id": "tutorial-sensor-001",
"primary_key": "..."
}
That JSON is your responseTemplate from step 2, rendered with real values.
Step 8 — Publish telemetry
Save this as sensor.py:
import json, time
import paho.mqtt.client as mqtt
settings = json.load(open("/tmp/settings.json"))
device_id = settings["device_id"]
client = mqtt.Client(client_id=device_id, clean_session=True)
client.username_pw_set(device_id, settings["primary_key"])
client.tls_set() # connecting by hostname sends SNI and verifies it automatically
client.connect(settings["mqtt_host"], settings["mqtt_port"], keepalive=120)
client.loop_start()
client.subscribe(f"device/{device_id}/twin/desired", qos=1)
for i in range(5):
payload = json.dumps({"temperature": 22.5 + i, "humidity": 48.2})
client.publish(f"device/{device_id}/telemetry", payload, qos=1)
print("published", payload)
time.sleep(2)
client.loop_stop()
client.disconnect()
Run it:
python3 sensor.py
published {"temperature": 22.5, "humidity": 48.2}
published {"temperature": 23.5, "humidity": 48.2}
...
Step 9 — Confirm the run was recorded
curl -s "$API/workflow-runs?subjectId=tutorial-sensor-001&limit=1" \
-H "Authorization: Bearer $TOKEN" \
| jq '.items[0] | {runId, workflowId, outcome, finishedAt}'
{
"runId": "0198f3f2-...",
"workflowId": "device-activation",
"outcome": "succeeded",
"finishedAt": "2026-08-14T10:31:04Z"
}
What you built
You now have a routing target, an enrollment group with one runnable workflow, one registered and activated device, and a recorded workflow run proving it. The device holds real broker credentials it fetched itself, and it has published telemetry into the platform.
You also saw the shape of every onboarding operation: discover what a workflow needs, send exactly that, read the result.
Where to go next
- How to run a workflow — deactivation, and running without a group
- How to rotate shared keys — before this key ages out
- How onboarding works — the tiers, and why bootstrap is separate from activation
- MQTT Protocol Reference — topics, payloads, and QoS