Created
February 24, 2017 01:23
-
-
Save Annath/0098672d0da66b210feea6acd80bf0a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- initiate the mqtt client and set keepalive timer to 120sec | |
mqtt2 = mqtt.Client("huzzah", 120, "user", "pass") | |
mqtt2:on("connect", function(con) print ("connected") end) | |
mqtt2:on("offline", function(con) print ("offline") end) | |
-- on receive message | |
mqtt2:on("message", function(conn, topic, data) | |
print(topic .. ":" ) | |
if data ~= nil then | |
print(data) | |
end | |
end) | |
mqtt2:connect("m13.cloudmqtt.com", 12759, 0, function(conn) | |
print("connected") | |
-- subscribe topic with qos = 0 | |
mqtt2:subscribe("my_topic",0, function(conn) | |
-- publish a message with data = my_message, QoS = 0, retain = 0 | |
mqtt2:publish("my_topic","my_message",0,0, function(conn) | |
print("sent") | |
end) | |
end) | |
end, | |
function(conn, reason) | |
print("failed: ", reason) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment