/chicken-mosquitto

Chicken Scheme bindings to the libmosquitto MQTT client library

Primary LanguageSchemeMIT LicenseMIT

chicken-mosquitto

Chicken Scheme Bindings to mosquitto MQTT client library

Requirements

Instalation

chicken-install mosquitto

Usage

Example client which sends message into topic2 each time it gets message from topic1:

(import (chicken blob)
	(chicken string)
	(mosquitto))

(define (message message)
  (display message)
  (newline)
  (flush-output))

(define client
  (make-mqtt-client #:on-connect (lambda (client err)
				   (when err
				     (abort err))
				   (message "Yay, we are connected!")
				   (mqtt-subscribe client "topic1"))))

(set-mqtt-client-disconnect-callback! client
				      (lambda (cl unexpected?)
					(when unexpected?
					  (message "Unexpected disconnect..."))))

(set-mqtt-client-message-callback! client
				   (lambda (cl msg)
				     (message (string-append
					       "Topic: " (mqtt-message-topic msg) " "
					       "Payload:" (blob->string (mqtt-message-payload msg))))
				     (mqtt-publish client "topic2" "message received, thanks!" )))

(mqtt-connect client "localhost"
	      #:username "mqtt-admin"
	      #:password "mypass")

(mqtt-loop-forever client)

Documentation

Full Documentation