DeFluder
New member
Друзья, что я делаю не так, почему не хочет работать пример из NodeMCU documentation, пока не закоментирую строчку
"m:lwt("/lwt", "offline", 0, 0)" ?
"m:lwt("/lwt", "offline", 0, 0)" ?
JavaScript:
m = mqtt.Client("clientid", 120)
m = mqtt.Client("clientid", 120, "user", "password")
m:lwt("/lwt", "offline", 0, 0)
m:on("connect", function(client) print ("connected") end)
m:on("offline", function(client) print ("offline") end)
m:on("message", function(client, topic, data)
print(topic .. ":" )
if data ~= nil then
print(data)
end
end)
m:on("overflow", function(client, topic, data)
print(topic .. " partial overflowed message: " .. data )
end)
m:connect("192.168.11.118", 1883, 0, function(client)
print("connected")
client:subscribe("/topic", 0, function(client) print("subscribe success") end)
client:publish("/topic", "hello", 0, 0, function(client) print("sent") end)
end,
function(client, reason)
print("failed reason: " .. reason)
end)
m:close();