Skip to content

Instantly share code, notes, and snippets.

@fasmide
Created March 24, 2016 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fasmide/51c2da7277c6c5359b24 to your computer and use it in GitHub Desktop.
Save fasmide/51c2da7277c6c5359b24 to your computer and use it in GitHub Desktop.
program = [[
wifi.sta.eventMonReg(wifi.STA_GOTIP, function()
pin = 5
status, temp, humi, temp_dec, humi_dec = dht.readxx(pin)
if status == dht.OK then
-- Integer firmware using this example
sendStr = string.format("DHT Temperature:%d.%03d;Humidity:%d.%03d\r\n",
math.floor(temp),
temp_dec,
math.floor(humi),
humi_dec
)
print(sendStr)
elseif status == dht.ERROR_CHECKSUM then
print( "DHT Checksum error." )
elseif status == dht.ERROR_TIMEOUT then
print( "DHT timed out." )
end
cu=net.createConnection(net.TCP)
cu:on("receive",function(cu,c) print(c) end)
cu:connect(1337, "10.42.2.170")
cu:on("connection", function(sck,c)
print("We have connection")
cu:send(sendStr, function() print("Sent") node.dsleep(1000*1000*10, 4) end)
end)
end)
wifi.sta.eventMonStart()
wifi.setmode(wifi.STATION)
wifi.setphymode(wifi.PHYMODE_N)
wifi.sta.config("hal9k","", 0)
wifi.sta.setip({ip = "10.42.2.171", netmask = "255.255.255.0", gateway = "10.42.2.1"})
wifi.sta.connect()
]]
file.open("init.lua", "w+")
file.write(program)
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment