mqtt unsubscribe - part-cw/lambdanative GitHub Wiki

(mqtt-unsubscribe t topic qos)

mqtt-unsubscribe un-subscribes from topic provided by the MQTT broker.

Parameter Description
t MQTT broker
topic Topic name string

Example

Example 1: Make a connection to a mosquitto broker running on localhost:1883, 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")))))
> (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