Skip to content

Instantly share code, notes, and snippets.

@fasmide
Created Mar 24, 2016
Embed
What would you like to do?
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