Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/components/HostCode.astro
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* {HTTP_URL_PREFIX} — Protocol + host for descriptive URLs (http(s)://THINGSBOARD_HOST or https://thingsboard.cloud)
* {COAP_HOST_LABEL} — Hostname for descriptive text (THINGSBOARD_HOST or coap.thingsboard.cloud)
* {COAP_URL_PREFIX} — Protocol + host for descriptive CoAP URLs (coap(s)://THINGSBOARD_HOST or coap(s)://coap.thingsboard.cloud)
* {CA_CERT} — CA root certificate filename (ca-root.pem or tb-cloud-root-ca.pem)
*/
import { Code } from '@astrojs/starlight/components';
import { getHostConfig } from '~/data/hosts';
Expand Down Expand Up @@ -40,6 +41,7 @@ const replacements: Record<string, string> = hosts.isSelfHosted
'{HTTP_URL_PREFIX}': 'http(s)://THINGSBOARD_HOST',
'{COAP_HOST_LABEL}': 'THINGSBOARD_HOST',
'{COAP_URL_PREFIX}': 'coap(s)://THINGSBOARD_HOST',
'{CA_CERT}': 'ca-root.pem',
}
: {
'{MQTT_HOST}': hosts.mqttHostName,
Expand All @@ -52,6 +54,7 @@ const replacements: Record<string, string> = hosts.isSelfHosted
'{HTTP_URL_PREFIX}': 'https://' + hosts.hostName,
'{COAP_HOST_LABEL}': hosts.coapHostName,
'{COAP_URL_PREFIX}': 'coap(s)://' + hosts.coapHostName,
'{CA_CERT}': 'tb-cloud-root-ca.pem',
};

let resolved = code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,29 @@ CoAP supports two credential types. Configure them per device under **Manage cre

### Access Token

Include the device access token as a path segment in the URL. Copy it from **Entities → Devices → [device] → Copy Access Token**.
Include the device access token as a path segment in the URL. Copy it from **Entities → Devices → [device] → Copy Access Token**, and replace `$ACCESS_TOKEN` in the commands below with it.

**Plain CoAP (port 5683):**

<HostCode product={props.product} lang="bash" code={`coap-client -v 6 -m POST -t "application/json" -e '{"temperature":25}' "coap://{COAP_HOST}:5683/api/v1/$ACCESS_TOKEN/telemetry"`} />

**CoAP over DTLS — One-way TLS (port 5684):**

The client verifies the server certificate using a CA root certificate. Download `ca-root.pem` from the **Entities** → **Devices** → **[device]** → **Check connectivity** → **CoAP** .
The client verifies the server certificate using a CA root certificate.

<HostCode product={props.product} lang="bash" code={`coap-client-openssl -v 6 -m POST -R ca-root.pem -t "application/json" -e '{"temperature":25}' "coaps://{COAP_HOST}/api/v1/$ACCESS_TOKEN/telemetry"`} />
<ShowFor product={props.product} show={[Products.CE, Products.PE]}>

Download `ca-root.pem` from the **Entities** → **Devices** → **[device]** → **Check connectivity** → **CoAP** .

</ShowFor>

<ShowFor product={props.product} show={[Products.PAAS, Products.PAAS_EU]}>

Download `tb-cloud-root-ca.pem` from the **Entities** → **Devices** → **[device]** → **Check connectivity** → **CoAP** .

</ShowFor>

<HostCode product={props.product} lang="bash" code={`coap-client-openssl -v 6 -m POST -R {CA_CERT} -t "application/json" -e '{"temperature":25}' "coaps://{COAP_HOST}/api/v1/$ACCESS_TOKEN/telemetry"`} />

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,29 @@ Choose the credential type that fits your device's security requirements. Config

The simplest credential type. The token acts as the MQTT username; no password is required.

Replace `$ACCESS_TOKEN` in the commands below with your device's actual access token.

**Plain MQTT (port 1883):**

<HostCode product={props.product} lang="bash" code={`mosquitto_pub -d -q 1 -h "{MQTT_HOST}" -p 1883 -t "v2/t" -u "$ACCESS_TOKEN" -m '{"temperature": 25}'`} />

**MQTT over TLS (port 8883) — one-way SSL:**

The client verifies the server's identity using a CA root certificate. Download `ca-root.pem` from the **Check connectivity** dialog on the device page.
The client verifies the server's identity using a CA root certificate.

<ShowFor product={props.product} show={[Products.CE, Products.PE]}>

Download `ca-root.pem` from the **Check connectivity** dialog on the device page.

</ShowFor>

<ShowFor product={props.product} show={[Products.PAAS, Products.PAAS_EU]}>

Download `tb-cloud-root-ca.pem` from the **Check connectivity** dialog on the device page.

</ShowFor>

<HostCode product={props.product} lang="bash" code={`mosquitto_pub -d -q 1 --cafile ca-root.pem -h "{MQTT_HOST}" -p 8883 -t "v2/t" -u "$ACCESS_TOKEN" -m '{"temperature": 25}'`} />
<HostCode product={props.product} lang="bash" code={`mosquitto_pub -d -q 1 --cafile {CA_CERT} -h "{MQTT_HOST}" -p 8883 -t "v2/t" -u "$ACCESS_TOKEN" -m '{"temperature": 25}'`} />

---

Expand All @@ -67,7 +81,7 @@ Replaces the access token with a custom `clientId`, `username`, and `password`.

**MQTT over TLS (port 8883) — one-way SSL:**

<HostCode product={props.product} lang="bash" code={`mosquitto_pub -d -q 1 --cafile ca-root.pem -h "{MQTT_HOST}" -p 8883 -t "v2/t" -i "$CLIENT_ID" -u "$USERNAME" -P "$PASSWORD" -m '{"temperature": 25}'`} />
<HostCode product={props.product} lang="bash" code={`mosquitto_pub -d -q 1 --cafile {CA_CERT} -h "{MQTT_HOST}" -p 8883 -t "v2/t" -i "$CLIENT_ID" -u "$USERNAME" -P "$PASSWORD" -m '{"temperature": 25}'`} />

---

Expand All @@ -90,7 +104,7 @@ Each device has its own certificate registered directly on the device record.
```
2. Register the certificate in ThingsBoard: **Entities → Devices → \[device\] → Manage credentials → X.509 Certificate**, paste `cert.pem`, save.
3. Connect using the certificate and key:
<HostCode product={props.product} lang="bash" code={`mosquitto_pub --cafile ca-root.pem -d -q 1 -h "{MQTT_HOST}" -p 8883 -t "v2/t" --key key.pem --cert cert.pem -m '{"temperature": 25}'`} />
<HostCode product={props.product} lang="bash" code={`mosquitto_pub --cafile {CA_CERT} -d -q 1 -h "{MQTT_HOST}" -p 8883 -t "v2/t" --key key.pem --cert cert.pem -m '{"temperature": 25}'`} />
</Steps>

#### Certificate Chain (Recommended for fleets)
Expand All @@ -117,7 +131,7 @@ Register one intermediate CA certificate in the device profile instead of one ce
```
2. Register the intermediate certificate in ThingsBoard: **Profiles → Device profiles → \[profile\] → Device Provisioning → X.509 Certificate Chain**. Paste `intermediateCert.pem`, configure the CN regex for device name extraction, and optionally enable auto-provisioning.
3. Connect using the chain and device key:
<HostCode product={props.product} lang="bash" code={`mosquitto_pub --cafile ca-root.pem -d -q 1 -h "{MQTT_HOST}" -p 8883 -t "v2/t" --key deviceKey.pem --cert chain.pem -m '{"temperature": 25}'`} />
<HostCode product={props.product} lang="bash" code={`mosquitto_pub --cafile {CA_CERT} -d -q 1 -h "{MQTT_HOST}" -p 8883 -t "v2/t" --key deviceKey.pem --cert chain.pem -m '{"temperature": 25}'`} />
</Steps>

<Aside type="tip">
Expand Down