Skip to content

ivan4th/cl-mqtt

Repository files navigation

MQTT driver for cl-async.

MQTT is a lightweight pubsub messaging protocol. It's much simpler than complex messaging protocols like AMQP but nevertheless may be quite handy for Internet of Things and many other tasks. Among other things, it supports nice WebSocket encapsulation which may be later added to this driver, too.

Example code:

(defun test-it (host port)
  (bb:alet ((conn (mqtt:connect
                   host
                   :port port
                   :on-message #'(lambda (message)
                                   (format t "~%RECEIVED: ~s~%"
                                           (babel:octets-to-string
                                            (mqtt:mqtt-message-payload message)
                                            :encoding :utf-8))))))
    (bb:walk
      (mqtt:subscribe conn "/a/#")
      (mqtt:subscribe conn "/b/#")
      (mqtt:publish conn "/a/b" "whatever1")
      (mqtt:unsubscribe conn "/a/#")
      (mqtt:publish conn "/a/b" "whatever2")
      (mqtt:publish conn "/b/c" "foobar")
      (as:with-delay (1)
        (mqtt:disconnect conn))))
  (values))

REPL interaction:

CL-USER> (ql:quickload 'cl-async-repl)
...
CL-USER> (as-repl:start-async-repl)
;; event thread started.
; No value
CL-USER> (test-it "localhost" 1883)

; No value
RECEIVED: "whatever1"

RECEIVED: "foobar"

About

MQTT driver for cl-async

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published