diff options
author | Clemens Fries <git-iot@xenoworld.de> | 2017-07-21 19:03:52 +0200 |
---|---|---|
committer | Clemens Fries <git-iot@xenoworld.de> | 2017-07-21 19:03:52 +0200 |
commit | d2c85c44d19c2c99c1f8ce212015c1964a795205 (patch) | |
tree | 0d657359607e7116cf37a8ccc1b75d3a526c78c4 | |
parent | f1cb06d71eca5b5d374eca0485efef0ee8de3b9e (diff) |
add yolo http responder for BME280 data
-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) |