Lua mqtt客户端,(零值)错误

时间:2017-04-14 11:50:59

标签: lua mqtt esplorer

我试图用物联网概念来测试程序。我有这个简单的mqtt lua的客户端。它在刷新我的devkit nodemcu v2后工作正常,但是当我重新启动它或者我再次保存它时,ESPlorer说:

test.lua:2: attempt to call field 'Client' (a nil value) 

代码: 资料来源:https://www.cloudmqtt.com/docs-nodemcu.html

-- initiate the mqtt client and set keepalive timer to 120sec
mqtt = mqtt.Client("client_id", 120) -- "username", "password")

mqtt:on("connect", function(con) print ("connected") end)
mqtt:on("offline", function(con) print ("offline") end)

-- on receive message
mqtt:on("message", function(conn, topic, data)
print(topic .. ":" )
if data ~= nil then
print(data)
end
end)

mqtt:connect("IP", 1883, 0, function(conn) 
print("connected")
-- subscribe topic with qos = 0
mqtt:subscribe("/topic",0, function(conn) 
-- publish a message with data = my_message, QoS = 0, retain = 0
 mqtt:publish("/topic","hello",0,0, function(conn) 
  print("sent") 
end)
end)
end)

这个客户可以随时工作吗?我错过了什么?现在我只能在闪存设备上保存脚本后与代理进行通信。

0 个答案:

没有答案