Skip to content

Latest commit

 

History

History
45 lines (40 loc) · 1.42 KB

README.md

File metadata and controls

45 lines (40 loc) · 1.42 KB

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"