Use MQTT's single-level wildcard to Subscribe to multiple Topics
MQTT's single-level wildcards allow you to subscribe to multiple topics simultaneously while using a specific topic structure. They match any subscription that follows the same topic structure.
Single-level wildcards are represented with a plus sign (+). For example, use the following subscription topic with a single-level wildcard:
Topic
/v1.6/devices/+/<variable_label>Then the response will be updated with the last dot of a device that contains a variable with the same {VARIABLE_LABEL} specified in the topic and has received a value.
| Field | Value | Required |
|---|---|---|
| Host | industrial.api.ubidots.com | Yes |
| Port | 1883/8883 (Non-TLS/TLS) | Yes |
| Username | Your Ubidots Token | Yes |
| Password | Any character or leave blank | No |
| Quality of Service | 0 or 1 | No |
Examples
NoteThe 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:
| Device | Variables |
|---|---|
| device-a | temperature, pressure, humidity |
| device-b | temperature |
| device-c | pressure, humidity |
Using a single-level wildcard subscription to obtain a value/dot sent to a specified variable for any device
Use the following single-level wildcard subscription topic:
/v1.6/devices/+/pressure/lv/v1.6/devices/+/pressureThen the results would be as if multiple subscriptions were made as follows:
/v1.6/devices/device-a/pressure/lv
/v1.6/devices/device-c/pressure/lv/v1.6/devices/device-a/pressure
/v1.6/devices/device-c/pressureTherefore, the response would be updated if either device-a or device-c receives a new value/dot for its pressure variable.
$ mosquitto_sub \
-h "industrial.api.ubidots.com" \
-t "/v1.6/devices/+/pressure/lv" \
-u "BBFF-Rfcgaxns6HlVb155WA0RhSY85xNDmB" \
-p 1883 \
-q 1
-v$ mosquitto_sub \
-h "industrial.api.ubidots.com" \
-t "/v1.6/devices/+/pressure" \
-u "BBFF-Rfcgaxns6HlVb155WA0RhSY85xNDmB" \
-p 1883 \
-q 1
-vUsing a single-level wildcard to obtain the last value/dot of any variable from a device when it is updated
Use the following subscription topic:
/v1.6/devices/device-a/+/lv/v1.6/devices/device-a/+Then the results would be as if multiple subscriptions were made as follows:
/v1.6/devices/device-a/temperature/lv
/v1.6/devices/device-a/pressure/lv
/v1.6/devices/device-a/humidity/lv/v1.6/devices/device-a/temperature
/v1.6/devices/device-a/pressure
/v1.6/devices/device-a/humidityTherefore, 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/+/lv" \
-u "BBFF-Rfcgaxns6HlVb155WA0RhSY85xNDmB" \
-p 1883 \
-q 1
-v$ mosquitto_sub \
-h "industrial.api.ubidots.com" \
-t "/v1.6/devices/device-a/+" \
-u "BBFF-Rfcgaxns6HlVb155WA0RhSY85xNDmB" \
-p 1883 \
-q 1
-v
