cl-mqtt
cl-mqtt copied to clipboard
Cannot connect to mosquitto broker
Hello, this might be my basic misunderstanding, but I am unable to use this library to connect to mosquitto mqtt broker.
On the client side I get:
WARNING: MQTT error: connection timed out (waiting for :CONNACK)
On mosquitto side I get:
1573232854: New connection from 127.0.0.1 on port 1883.
1573232861: Socket error on client <unknown>, disconnecting.
So cl-mqtt is somehow reaching the broker, but the handshake is not completed.
Tested with cl-mqtt a7028bcb486959cf002df42eeb9d07518c90fd03 on 2 different machines:
- sbcl 1.5.8.debian, mosquitto 1.6.7-1, Linux 5.2.0-3 amd64
- sbcl 1.3.7.debian, mosquitto 1.4.10, Linux 4.19.66 armv6l
with only slightly modified example form README (I am not using swank, so no cl-async-repl):
(ql:quickload :cl-async)
(ql:quickload :cl-mqtt)
(defpackage :mqtt-player
(:use :cl :mqtt :bb))
(in-package :mqtt-player)
(defun test-it (host port)
(bb:alet ((conn (mqtt:connect
host
:port port
:client-id "mqtt-player"
: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))
(as:with-event-loop ()
(test-it "localhost" 1883))