Dzwonek do drzwi hakerspejsu zrobiony z moduĊ‚u ESP8266 z odpalonym NodeMCU.

Kod


function wait_for_wifi_conn ( func )
   tmr.alarm (1, 200, 1, function ( )
      if wifi.sta.getip ( ) == nil then
         print (".")
      else
         tmr.stop (1)
         func()
      end
   end)
end

wifi.setmode(wifi.STATION)
wifi.sta.config("hackerspace.pl-guests","topkek")
wifi.sta.connect()
gpio.mode(3,gpio.OUTPUT)
gpio.write(3,gpio.HIGH)

wait_for_wifi_conn ( function() 
--while wifi.sta.status() ~= 5 do
--tmr.delay(1000000)
--print(wifi.sta.status())
--end
print(wifi.sta.getip())
sk=net.createConnection(net.TCP, 0)
sk:on("sent", function(conn) print("sent."); conn:close() end)
sk:on("connection", function(conn) print("papiez tanczy ,_,") end)
sk:on("disconnection", function(conn) print("disco."); node.dsleep(0,1) end)
sk:connect(4200,"10.8.1.15")
sk:send("SMOKE /weed HTTP/1.1\r\n\r\n")
end)