Skip to content

Instantly share code, notes, and snippets.

@thinkl33t
Created April 15, 2015 23:16
Show Gist options
  • Save thinkl33t/2557f6f77f3a56566b06 to your computer and use it in GitHub Desktop.
Save thinkl33t/2557f6f77f3a56566b06 to your computer and use it in GitHub Desktop.
esp8266 MQTT button
wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","PASSWORD")
wifi.sta.connect()
tmr.alarm(1, 100, 1, function()
if wifi.sta.getip() ~= nil then
tmr.stop(1)
m = mqtt.Client( "ESP8266-" .. node.chipid(), 120)
m:connect( "192.168.1.13" , 1883, 0, function(conn)
m:publish("button/1/pressed", "", 0, 0, function(conn)
node.dsleep(0)
end)
end)
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment