Created
December 12, 2019 21:08
-
-
Save bakroistvan/b06a5a456ba7d93887e6857d26c30740 to your computer and use it in GitHub Desktop.
nodemcu-mqtt
This file contains 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 | |
mqtt = mqtt.Client("client_id", 120, "<<user>>", "<<pass>>") | |
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("farmer.cloudmqtt.com", 11253, 0, function(conn) | |
print("connected") | |
-- subscribe topic with qos = 0 | |
mqtt:subscribe("my_topic",0, function(conn) | |
-- publish a message with data = my_message, QoS = 0, retain = 0 | |
mqtt:publish("my_topic","my_message",0,0, function(conn) | |
print("my_message sent") | |
end) | |
end) | |
end) |
This file contains 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
station_cfg={} | |
station_cfg.ssid="bagameri" | |
station_cfg.pwd="jelszavacskam" | |
station_cfg.save=true | |
wifi.sta.config(station_cfg) | |
function connected_cb(SSID, BSSID, ch) | |
print(SSID) | |
print(BSSID) | |
print(ch) | |
end | |
wifi.sta.connect(connected_cb) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment