diff options
Diffstat (limited to 'application.lua')
-rw-r--r-- | application.lua | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/application.lua b/application.lua new file mode 100644 index 0000000..63f477e --- /dev/null +++ b/application.lua @@ -0,0 +1,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) |