Skip to content
Try for free

ThingsBoard Cloud

Choose your data region

Your data stays in the region you choose, for residency and compliance. No credit card required.

Rather run it yourself? Install on your own servers

Getting Connected

CoAP is a lightweight, UDP-based protocol designed for constrained IoT devices. ThingsBoard acts as a CoAP server supporting both regular request-response and the CoAP Observe option for push-style subscriptions.

Parameter Value
Host Your ThingsBoard hostname or IP
Port 5683 (plain CoAP) · 5684 (CoAP over DTLS)
Protocol CoAP / CoAP over DTLS
URL scheme coap:// · coaps://

Examples in this section use coap-client (from the libcoap package), which supports query parameters and DTLS. Install it on Ubuntu:

Terminal window
sudo apt install libcoap3-bin

On older Ubuntu releases where libcoap3-bin isn’t available, install libcoap2-bin instead:

Terminal window
sudo apt install libcoap2-bin

For DTLS examples, coap-client-openssl is required — a build of coap-client with OpenSSL support. See the Californium cf-client or build from source.

CoAP supports two credential types. Configure them per device under Manage credentials — see Devices.

Type URL Authentication
Access Token coap(s)://HOST/api/v1/$ACCESS_TOKEN/{resource} Token in the URL path
X.509 Certificate coaps://HOST/api/v1/{resource} Mutual DTLS — no token in URL

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):

Terminal window
coap-client -v 6 -m POST -t "application/json" -e '{"temperature":25}' "coap://coap.thingsboard.cloud: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 tb-cloud-root-ca.pem from the Entities ⇾ Devices ⇾ [device] ⇾ Check connectivity ⇾ CoAP.

Terminal window
coap-client-openssl -v 6 -m POST -R tb-cloud-root-ca.pem -t "application/json" -e '{"temperature":25}' "coaps://coap.thingsboard.cloud/api/v1/$ACCESS_TOKEN/telemetry"

Mutual DTLS authentication — both client and server verify each other’s certificates. No token is included in the URL.

  1. Generate a self-signed EC private key and certificate:

    Terminal window
    openssl ecparam -out key.pem -name secp256r1 -genkey
    openssl req -new -key key.pem -x509 -nodes -days 365 -out cert.pem
  2. Go to Entities ⇾ Devices ⇾ [device] ⇾ Manage credentials, select X.509 Certificate, and paste the contents of cert.pem.

  3. Connect using the certificate and key:

    Terminal window
    coap-client-openssl -v 6 -c cert.pem -j key.pem -m POST -t "application/json" -e '{"temperature":25}' "coaps://coap.thingsboard.cloud/api/v1/telemetry"

ThingsBoard Cloud already has DTLS configured. Connect on port 5684 using coaps:// — no additional server-side setup is needed.

A connecting CoAPS client must support:

  • DTLS 1.2 (DTLS 1.3 is not supported)
  • An ECDHE key exchange with certificate-based authentication — PSK and Raw Public Key are not supported by the CoAP transport
  • One of the AEAD cipher suites below, matching the server certificate key type
  • A supported curve and a SHA-256 signature algorithm

Server certificate with an EC key:

  • TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
  • TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
  • TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8
  • TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8
  • TLS_ECDHE_ECDSA_WITH_AES_128_CCM
  • TLS_ECDHE_ECDSA_WITH_AES_256_CCM

Server certificate with an RSA key:

  • TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  • TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384

Supported curves: secp256r1, secp384r1, X25519, X448

Signature algorithms: SHA256withECDSA, SHA256withRSA

When you set the transport type to CoAP in a device profile, additional settings become available under Transport configuration. These settings apply to all devices using the profile.

Type Description
Default Standard CoAP device. Supports JSON and Protobuf payloads.
Efento NB-IoT Built-in support for Efento NB-IoT sensors. ThingsBoard automatically parses Efento’s proprietary Protobuf format for measurements, device info, and configuration. See Efento NB-IoT sensors and ThingsBoard for setup details.

When using the Default device type, choose the serialization format for CoAP messages:

Format Description
JSON Default. Devices send plain JSON payloads as shown in the telemetry, attributes, and RPC examples.
Protobuf Devices send binary Protocol Buffers messages. You define .proto schemas per profile for telemetry, attributes, RPC request, and RPC response — identical to the MQTT transport Protobuf configuration.

NB-IoT devices typically operate in low-power modes where they are not always reachable. The power saving mode setting tells ThingsBoard how long the device is available after it wakes up, so the platform can queue and deliver commands (RPC, shared attribute updates) within the reachability window.

Mode Parameters Description
PSM (Power Saving Mode) PSM Activity Timer, Time unit The device wakes up periodically to send data, then enters deep sleep. ThingsBoard delivers queued commands during the activity window defined by the PSM Activity Timer.
DRX (Discontinuous Reception) (none) The device uses standard sleep cycles and is reachable frequently. No additional configuration needed.
eDRX (Extended Discontinuous Reception) eDRX cycle, Time unit, Paging Transmission Window, Time unit The device has longer sleep cycles than DRX. ThingsBoard uses the eDRX cycle and Paging Transmission Window to determine when the device is reachable.

PSM parameters:

Parameter Description
PSM Activity Timer Duration the device stays awake after sending data. ThingsBoard must deliver commands within this window.
Time unit Seconds, Minutes, or Hours

eDRX parameters:

Parameter Description
eDRX cycle Total duration of one eDRX cycle (sleep + wake).
Paging Transmission Window Duration within each eDRX cycle when the device listens for downlink messages.
Time unit Seconds, Minutes, or Hours (configurable per parameter)
Code Meaning
2.01 OK Client’s request has been successfully processed
4.00 Bad Request Invalid URL, parameters, or payload
4.01 Unauthorized Invalid or missing access token
4.04 Not Found Requested resource does not exist
4.05 Method Not Allowed URL doesn’t support this request method