aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClemens Fries <git-iot@xenoworld.de>2017-07-21 19:03:52 +0200
committerClemens Fries <git-iot@xenoworld.de>2017-07-21 19:03:52 +0200
commitd2c85c44d19c2c99c1f8ce212015c1964a795205 (patch)
tree0d657359607e7116cf37a8ccc1b75d3a526c78c4
parentf1cb06d71eca5b5d374eca0485efef0ee8de3b9e (diff)
add yolo http responder for BME280 data
-rw-r--r--application.lua19
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)