Subscribe with a multi-level wildcard

Use MQTT's multi-level wildcard to subscribe to multiple topics

MQTT's multi-level wildcards allow you to subscribe to multiple topics simultaneously while using a specific topic structure. They follow the same topic structure up to the wildcard level.

Multi-level wildcards are represented with a hash symbol (#). Multi-level wildcards must always be placed as the last level of the topic. For example, use the following subscription topic with a multi-level wildcard:

Topic

/v1.6/devices/<device_label>/#

Then the response is updated with the last dot of any variable that receives a value within the specified device.

FieldValueRequired
Hostindustrial.api.ubidots.comYes
Port1883/8883 (Non-TLS/TLS)Yes
UsernameYour Ubidots TokenYes
PasswordAny character or leave blankNo
Quality of Service0 or 1No
🚧

Non-specific results

Results for subscriptions that use wildcards do not identify which variable received the resulting value/dot. They only return the value/dot itself.

Examples

📘

Note

The bash examples in this section use the Eclipse Mosquitto library. To test them, install it using the official instructions.

If there are three devices that contain the following variables:

DeviceVariables
device-atemperature, pressure, humidity
device-btemperature
device-cpressure, humidity

Using a multi-level wildcard subscription to obtain a dot sent to any variable within a specific device
Use the following multi-level wildcard subscription topic:

/v1.6/devices/device-a/#

Then the results would be the same as if you made multiple subscriptions, as follows:

/v1.6/devices/device-a/temperature
/v1.6/devices/device-a/pressure
/v1.6/devices/device-a/humidity

Therefore, the response would be updated if device-a receives a new value for its temperature, pressure, or humidity variable.

$ mosquitto_sub \
-h "industrial.api.ubidots.com" \
-t "/v1.6/devices/device-a/#" \
-u "BBFF-Rfcgaxns6HlVb155WA0RhSY85xNDmB" \
-p 1883 \
-q 1
-v

Using a multi-level wildcard to obtain the dot of any variable from any device when it is updated
Use the following subscription topic:

/v1.6/devices/#

Then the results would be the same as if you made multiple subscriptions, as follows:

/v1.6/devices/device-a/temperature
/v1.6/devices/device-a/pressure
/v1.6/devices/device-a/humidity
/v1.6/devices/device-b/temperature
/v1.6/devices/device-c/pressure
/v1.6/devices/device-c/humidity

Therefore, the response would be updated if any variable from any device is updated.

$ mosquitto_sub \
-h "industrial.api.ubidots.com" \
-t "/v1.6/devices/#" \
-u "BBFF-Rfcgaxns6HlVb155WA0RhSY85xNDmB" \
-p 1883 \
-q 1
-v