From d2c85c44d19c2c99c1f8ce212015c1964a795205 Mon Sep 17 00:00:00 2001 From: Clemens Fries Date: Fri, 21 Jul 2017 19:03:52 +0200 Subject: add yolo http responder for BME280 data --- application.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 application.lua 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) -- cgit