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

mqtt-reset resets an existing MQTT instance.

Parameter Description
t MQTT instance
args Optional: Subscription arguments (below)
Attribute Description
clean-session Broker to clean all messages/subscriptions on disconnect (Default: 0)
host Hostname or IP (Default: "127.0.0.1")
port Port number (Default: 1883)
keepalive Interval of keepalive [sec] (Default: 10)
timeout Timeout [sec] (Default: 10)
max-packets (Default: 100)
handler Handler of type (lambda (topic val) ...) (Default: #f)
will Message to be send by broker if client disconnects '("topic" "msg" qos retain) (Default: #f)
username Username as string (Default: #f)
password Password as string (Default: #f)
tls-version TLS version (Default: "tlsv1.2")
tls-insecure Disable server certificate verification (Default: #f)
psk pre-shared-key in hex format (Default: #f)
psk_identity identity/username of this client (Default: #f)
id Id tag of host (Default: #f, which makes it LN/IP-pid)

Example

Example 1: Make a connection to a mosquitto broker running on localhost:1883, reset instance to connect to broker on 168.1.1.2:1882, subscribe to two topics, publish some data to them and wait for the results to show. Then unsubscribe from one topic and show that it's handler is no longer called. Finally close the connection properly.

> (define m (make-mqtt 'host "127.0.0.1" 'port 1883 
                       'handler (lambda (topic val) 
                          (for-each display (list topic ": " val "\n")))))
> (mqtt-reset m 'host "168.1.1.2" 'port 1882 'handler (lambda (topic val) 
                          (for-each display (list topic " = " val "\n")))))
> (thread-sleep! 0.5)
> (mqtt-subscribe m "Test1" 2)
#t
> (mqtt-subscribe m "Test2" 2)
#t
> (mqtt-publish m "Test1" 123 2 0)
#t
> (mqtt-publish m "Test2" 123456 2 0)
#t
> (thread-sleep! 1.)
Test1: 123
Test2: 123456
> (mqtt-unsubscribe m "Test1")
#t
> (mqtt-publish m "Test1" "blah" 2 0)
#t
> (mqtt-publish m "Test2" "LN1" 2 0)
#t
> (thread-sleep! 1.)
Test2: LN1
> (mqtt-destroy m)
#t
Clone this wiki locally