无法将客户端连接到 Broker

时间:2021-02-01 14:52:04

标签: lua mqtt

我是第一次在 lua 上编码,并为 IO 链路传感器创建了一个 mqtt 客户端实例,以发布有关 MQTT 主题的数据。但是,我不知道如何连接到我当地的 mosquitto 代理,因为“连接被拒绝”但代理在线并且正在工作。 我的 mqtt 客户端的设置如下所示:

local client = MQTTClient.create()
local BROKER_IP = '127.0.0.1'

local USE_TLS = false

client:setIPAddress(BROKER_IP)
if (USE_TLS) then
  client:setPort(1883)
  client:setTLSEnabled(true)
  client:setTLSVersion('TLS_V12')
  client:setCABundle('resources/mosquitto/mybroker-cert.pem')
  client:setClientCertificate(
    'resources/mosquitto/mqtt-client-cert-2.pem',
    'resources/mosquitto/mqtt-client-key-2.pem',
    'changemeclient'
  )
end

现在错误标记在以下 client:publish 行。

备注:这里发布的数据是一个距离,因此转换为字符串。

if dataValid == 'PI_STATUS_VALID' then
    local sDistance = string.format('%d', distance)
    client:publish('/topic/test', sDistance, "QOS0", "NO_RETAIN")
  end

有人看到问题可能出在哪里吗?

0 个答案:

没有答案
相关问题