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.
| 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 |
Non-specific resultsResults for subscriptions that use wildcards do not identify which variable received the resulting value/dot. They only return the value/dot itself.
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 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/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/#" \
-u "BBFF-Rfcgaxns6HlVb155WA0RhSY85xNDmB" \
-p 1883 \
-q 1
-vUsing 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/humidityTherefore, 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
