aboutsummaryrefslogtreecommitdiffstats
path: root/application.lua
blob: 24748227729251e99428b2d185cab5dc9aac38d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
bme280.init(3, 4, nil, nil, nil, 0) -- initialize to sleep mode

status = tsl2561.init(3, 4, tsl2561.ADDRESS_FLOAT, tsl2561.PACKAGE_T_FN_CL)
if status == tsl2561.TSL2561_OK then
    status = tsl2561.settiming(tsl2561.INTEGRATIONTIME_101MS, tsl2561.GAIN_1X)
end

srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
	conn:on("receive",function(conn)
		bme280.startreadout(0, function ()
			T, P, H = bme280.read()
			lux = tsl2561.getlux()
			lux_bs, lux_ir, lux_st = tsl2561.getrawchannels()
			-- local Tsgn = (T < 0 and -1 or 1); T = Tsgn*T
			conn:send(string.format([[HTTP/1.1 200 OK
Content-Type: application/json
Access-Control-Allow-Origin: *
Connection: close

{"temperature": %s, "pressure": %s, "humidity": %s,
"lux": %s, "lux_ir": %s, "lux_bs": %s}]], T, P, H, lux, lux_ir, lux_bs))
		end)
	end)
	conn:on("sent", function(conn)
		conn:close()
	end)
end)