Lua mqtt client, (a nil value) error -


i'm trying test programs concept of internet of things. got simple mqtt lua's client. works fine after flashing devkit nodemcu v2, when restart or save again esplorer says:

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

code: source: https://www.cloudmqtt.com/docs-nodemcu.html

-- initiate mqtt client , set keepalive timer 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 print(data) end end)  mqtt:connect("ip", 1883, 0, function(conn)  print("connected") -- subscribe topic qos = 0 mqtt:subscribe("/topic",0, function(conn)  -- publish message data = my_message, qos = 0, retain = 0  mqtt:publish("/topic","hello",0,0, function(conn)    print("sent")  end) end) end) 

is possible client can work anytime? missing? right can communicate broker after saving script on flashed device.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -