GET TOPIC Functional Keyword
| Feature | Since Version | Notes |
|---|---|---|
GET TOPIC |
>v1.4.6 | Retrieves data from a topic |
1. Overview
- Description:
Instructs the broker to retrieve the current value stored (either internally via
KEEP TOPICor the last retained message published viaPUBLISH TOPIC) for a specified MQTT topic.
2. Signature
- Syntax:
3. Parameters
"<topicPath>": The topic path (string) from which to retrieve the value. Can include wildcards (+,#) in some contexts, though typically used with specific paths.
4. Return Value
- Description:
Returns the value stored at the specified topic path. If the topic does not exist or has no stored value, it returns
EMPTY.
5. Usage Examples
Basic Example
Retrieve a configuration setting and use it in a publish command.
DEFINE ACTION ApplyThreshold
ON TOPIC "sensors/temperature" DO
SET "threshold" = GET TOPIC "config/temp_threshold"
IF PAYLOAD > {threshold} THEN
PUBLISH TOPIC "alerts/temp" WITH "Temperature exceeded threshold!"
Intermediate Example
Check if a device is enabled before processing its data.
DEFINE ACTION ProcessIfEnabled
ON TOPIC "device/A/data" DO
// Assumes "config/device/A/enabled" stores "true" or "false"
IF GET TOPIC "config/device/A/enabled" == "true" THEN
PUBLISH TOPIC "processed/device/A" WITH (PAYLOAD * 0.5)
Advanced Example (Counter)
Increment a counter stored internally.
DEFINE ACTION IncrementCounter
ON TOPIC "events/trigger" DO
SET "currentCount" WITH GET TOPIC "internal/counter"
IF {currentCount} == EMPTY THEN
SET "newCount" WITH 1
ELSE
SET "newCount" WITH {currentCount} + 1
KEEP TOPIC "internal/counter" WITH {newCount} // Store updated count
PUBLISH TOPIC "public/counter" WITH {newCount} // Optionally publish it
6. Notes & Additional Information
GET TOPICis fundamental for accessing stored state or configuration within LOT.- Always consider checking the return value against
EMPTYif there's a possibility the topic might not have a value yet.