Last active
August 29, 2015 14:22
-
-
Save bitdivision/c91f95bc8c365a7a9f92 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
wifi.setmode(wifi.STATION) | |
wifi.sta.config("YOUR SSID", "PASSWORD") | |
gpio.mode(4, gpio.OUTPUT) | |
tmr.alarm(0, 5000, 0, function() | |
m = mqtt.Client("ESP8266"..node.chipid() , 120) | |
m:connect("YOUR IP ADDRESS", 1883, 0, function(conn) | |
print("Connected to MQTT broker") | |
m:subscribe("esp_led", 0) | |
end) | |
m:on("message", function(conn, topic, data) | |
if data ~= nil then | |
print("Received message on topic: " .. topic .. " with message: " .. data) | |
if data == "1" then | |
gpio.write(4, gpio.HIGH) | |
elseif data == "0" then | |
gpio.write(4, gpio.LOW) | |
else | |
print("The message must be 1 or 0") | |
end | |
end | |
end) | |
end) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment