CoAP

UbiFunctions can be invoked using the Constrained Application Protocol (CoAP), a lightweight request/response protocol designed for constrained devices and low-power networks. CoAP follows a REST-like interaction model similar to HTTP, but runs over UDP and minimizes message overhead, making it well suited for embedded systems and sensor networks.

Ubidots supports CoAP for sending data to devices, variables, and user-defined functions. When invoking an UbiFunction through CoAP, devices can trigger custom server-side logic such as data processing, validation, or integrations with external services, using a minimal and efficient communication mechanism.

Currently, Ubidots supports only the POST method over CoAP.


CoAP Settings

Setting
Value

Protocol

CoAP

Host

coap.ubidots.com

Port

5684

Supported methods

POST

Notes

  • CoAP runs over UDP.

  • TLS is not supported for CoAP.

  • Only the POST method is currently available.


Invoking an UbiFunction via CoAP

Each UbiFunction has a dedicated CoAP endpoint that allows it to be triggered directly.

Endpoint

Where:

  • <username> is your Ubidots account username.

  • <function_label> is the label of the Function you want to invoke.

All requests must be sent using the POST method.


Authentication

Unlike sending data to devices or variables over CoAP, invoking an UbiFunction does not require an authentication token in the request.

No query parameters or headers are needed for authentication when calling a Function endpoint. Access is handled internally by Ubidots based on the function and account context.


Payload Format

The payload sent to an UbiFunction over CoAP is fully defined by your Function code.

UbiFunctions receive the request body exactly as it is sent. There is no fixed schema or enforced structure, allowing you to use:

  • JSON objects

  • Key-value pairs

  • Arrays

  • Plain text

Your Function script is responsible for parsing and interpreting the payload according to your logic.

Example payload (JSON)


Example: Triggering a Function Using coap-client

You can use the coap-client utility from the libcoap package to test or invoke an UbiFunction from the command line.

This request sends the payload directly to the Function and triggers its execution.


Function Response

The response returned by a Function (if any) depends entirely on how the Function is implemented. If your script generates a response, it will be returned to the CoAP client. Otherwise, no response content is expected.


Limitations and Considerations

  • Only the POST method is supported for CoAP requests.

  • TLS is not supported for CoAP.

  • Keep payloads compact to avoid fragmentation at the UDP/CoAP layer.

  • The Function CoAP endpoint does not create devices or variables. It only triggers Function execution.

  • Response behavior depends on the Function implementation and should not be relied upon for guaranteed delivery.

Last updated

Was this helpful?