Skip to content
Chris Petersen edited this page Oct 16, 2014 · 1 revision

mqtt-store-setup sets up ln_store sharing using a MQTT broker.

Parameter Description
store Store name
args Optional: MQTT arguments

Note: All arguments natively supported by (make-mqtt . args) are also supported here. Only new arguments are listed below

Attribute Description
subscribe List of ("variable" "mqtt-topic" qos) lists, which are imported
publish List of ("variable" "mqtt-topic" qos retain) lists, which are exported

Example

Example 1: Make a connection to a mosquitto broker running on localhost:1883. Export the local variable "LocalTemp" as MQTT topic "inside/temperature, while importing the MQTT topics "inside/temperature" and "outside/temperature" as "InsideTemp" and "OutsideTemp" respectively.

> (define store (make-store "test"))
> (mqtt-store-setup store 'host "127.0.0.1" 'port 1883 
    'subscribe '(("InsideTemp" "inside/temperature" 2)
                 ("OutsideTemp" "outside/temperature" 0))
    'publish   '(("LocalTemp" "inside/temperature" 2 0))
  )
#t
> (store-ref store "InsideTemp")
#f
> (store-set! store "LocalTemp" 23.3)
#f
> (thread-sleep! 0.5)
> (store-ref store "LocalTemp")
23.3
> (store-ref store "InsideTemp")
23.3
Clone this wiki locally