aboutsummaryrefslogtreecommitdiffstats
path: root/application.lua
blob: 63f477ecb5a0527428d3cf20c9d798282cf4e555 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
bme280.init(3, 4, nil, nil, nil, 0) -- initialize to sleep mode

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

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