Skip to content
Matthias Görges edited this page Mar 16, 2015 · 1 revision

mqtt-connected? checks if a MQTT instance is connected to a data broker.

Parameter Description
t MQTT instance

Example

Example 1: Check if a MQTT broker connection exists before publishing a topic. Example is extracted from modules/mqtt/mqtt.scm

(define (mqtt-publish t topic msg qos retain)
  (mqtt:log 2 "mqtt-publish " t " " topic " " msg " " qos " " retain)
  (let ((connected (mqtt-connected? t)))
    (if connected 
      (begin 
        (mqtt:publish (table-ref t 'handle #f) topic qos retain (mqtt:encode msg)) 
        #t
      ) 
      #f
    )
  ))
Clone this wiki locally