MQTT Publish
You can invoke an UbiFunction by publishing data through MQTT. This makes it possible to integrate devices and gateways that may have a non-editable JSON payload that is not compatible with our native MQTT broker or our HTTP Data Ingestion API.
Because our UbiFunctions MQTT Broker is shared across all functions, it is not possible to support subscribe requests and only the MQTT Publish method is accepted. Accordingly, all subscriptions requests will be rejected.
If you'd like to have a private MQTT Broker mapped to an UbiFunction, please reach out to our sales team. In this case, subscribe actions can be supported.
Here are the MQTT settings needed to invoke an UbiFunction over the MQTT protocol:
MQTT Settinigs
Value
URL
functions.ubidots.com
Port
1883 for plain MQTT. 8883 for MQTT over TLS.
Topic
/prv/<your-username>/<function-label>
Username
Your account username
Password
Valid Token from your Ubidots account.
ClientID
Any random string. Preferably longer than 15 characters

Topic structure

To trigger an UbiFunction through MQTT, the publication topic must follow the structure:
1
/prv/<username>/<function-label>
Copied!
Where:
  • <username> is your Ubidots account username.
  • <function-label> is the Name of the function but all lowercase and spaces replaced by dashes.
The base topic corresponds to the UbiFunction HTTPS Endpoint URL's path, as seen in the image below:

Advanced Topics

Additional topic levels are supported. To add more levels, simply add a forward slash ("/") after the base topic:
1
/prv/<username>/<function-label>/<level-1>/···/<level-N>
Copied!
Where:
  • <level-N> is any additional UTF-8 encoded string that you want to add to the topic
Topics have the below limitions:
Topic Limits
Limit
Length
1500 characters
Levels
10

UbiFunction args

When triggering an UbiFunction through the MQTT protocol, you'll receive a JSON object in the args variable of the main function. The JSON will have this structure:
1
{
2
"topic": "<topic>",
3
"payload": "<payload>",
4
"from_client_id": "<client_id>",
5
}
Copied!
Where:
Key
Type
Value description
topic
String
The multilevel publication topic
payload
String
The payload sent by the device in the publication message.
from_client_id
String
The client ID used in the MQTT connection.

Certificates

Ubidots supports SSL V1.1, TLS V1.2 and V1.3. You can download our root certificates in different formats:
  • PEM file: Certificate chain with two root certificates from our certificate authorities (CAs).
  • DER file: Same as the PEM file, with an alternative encoding.
  • CRT file: Same as the PEM file, with a different extension. Often referred to as .crt, .cert or .cer.

Examples

Port 1883
Port 8883
1
mosquitto_pub \
2
-p 1883 \
3
-h functions.ubidots.com \
4
-t "/prv/<username>/<function-name>" \
5
-m '{"token": "TOKEN", "device": "device-label", "variable-label": value}' \
6
-u "<username>" \
7
-P "TOKEN" \
8
-q 1 -d
Copied!
1
mosquitto_pub \
2
-p 8883 \
3
-h functions.ubidots.com \
4
-t "/prv/<username>/<function-name>" \
5
-m '{"token": "TOKEN", "device": "device-label", "variable-label": value}' \
6
-u "<username>" \
7
-P "TOKEN" \
8
-q 1 -d \
9
--cafile /Users/user/Documents/Ubidots/roots.pem
Copied!
Last modified 5mo ago