Skip to content

Instantly share code, notes, and snippets.

@joelbyler
Created July 30, 2015 21:04
Show Gist options
  • Save joelbyler/8625d0adddf41c7a8ad4 to your computer and use it in GitHub Desktop.
Save joelbyler/8625d0adddf41c7a8ad4 to your computer and use it in GitHub Desktop.
wifi.setmode(wifi.STATION)
wifi.sta.config('YOUR_SSID','YOUR_SSID_PWD')
wifi.sta.connect()
tmr.alarm(1, 5000, 1, function()
if wifi.sta.getip()== nil then
print('IP unavaiable, waiting...')
else
tmr.stop(1)
print('IP is '..wifi.sta.getip())
conn=net.createConnection(net.TCP, false)
conn:on("receive", function(conn, pl) print(pl) end)
conn:connect(80,"121.41.33.127")
conn:send("GET / HTTP/1.1\r\nHost: www.nodemcu.com\r\n" .."Connection: keep-alive\r\nAccept: */*\r\n\r\n")
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive",function(conn,payload)
print(payload)
conn:send("<h1>Hello, this is a simple http response from a NodeMCU module .</h1>")
end)
end)
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment