summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Dobrowolski <admin@tastycode.pl>2017-02-08 00:52:23 +0100
committerPiotr Dobrowolski <admin@tastycode.pl>2017-02-08 00:52:23 +0100
commit62b8e8cad06d6aad0d8e8fec0e57eacaec113fb8 (patch)
tree2a4a0a2f18646db589371b0c9daae3b996aed715
parent862d977fce801f191350bd2f57b54877cea1f69a (diff)
downloadlove2d-signage-62b8e8cad06d6aad0d8e8fec0e57eacaec113fb8.tar.gz
love2d-signage-62b8e8cad06d6aad0d8e8fec0e57eacaec113fb8.tar.bz2
love2d-signage-62b8e8cad06d6aad0d8e8fec0e57eacaec113fb8.zip
newdash: Add spejsiot integration
-rw-r--r--nodes/newdash.lua43
-rw-r--r--nodes/newdash_thread.lua13
2 files changed, 43 insertions, 13 deletions
diff --git a/nodes/newdash.lua b/nodes/newdash.lua
index e231342..851a8c5 100644
--- a/nodes/newdash.lua
+++ b/nodes/newdash.lua
@@ -22,6 +22,31 @@ local weatherGlyphs = {
drizzle = "",
}
+function node:spejsiotData(node_id, endpoint, parameter)
+ if self.state.spejsiot[node_id] and self.state.spejsiot[node_id]["$online"] and self.state.spejsiot[node_id][endpoint] and self.state.spejsiot[node_id][endpoint][parameter] ~= nil then
+ return self.state.spejsiot[node_id][endpoint][parameter]
+ else
+ return nil
+ end
+end
+
+function node:renderIOTState(node_id, endpoint, parameter, x, y)
+ local rawValue = self:spejsiotData(node_id, endpoint, parameter)
+ if rawValue == true then
+ love.graphics.setColor( 0, 255, 0 )
+ love.graphics.printf("ON", x, y, 400, 'left')
+ elseif rawValue == false then
+ love.graphics.setColor( 255, 0, 0 )
+ love.graphics.printf("OFF", x, y, 400, 'left')
+ elseif rawValue == nil then
+ love.graphics.setColor( 255, 0, 0 )
+ love.graphics.printf("OFFLINE", x, y, 400, 'left')
+ else
+ love.graphics.setColor( 255, 255, 255 )
+ love.graphics.printf(rawValue, x, y, 400, 'left')
+ end
+end
+
function node:render()
love.graphics.setColor( 0, 0, 0 )
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
@@ -43,16 +68,24 @@ function node:render()
love.graphics.setFont(headerFont)
love.graphics.printf("Ambient:", 720, 380, 160, 'right')
love.graphics.printf("Exhaust:", 720, 440, 160, 'right')
- love.graphics.printf("Lights:", 720, 500, 160, 'right')
+ love.graphics.printf("Pope:", 720, 500, 160, 'right')
love.graphics.setFont(valueFont)
- if self.state.insideTemperature then
- love.graphics.printf(string.format("%d° / %d%%RH", self.state.insideTemperature, self.state.insideHumidity), 900, 378, 400, 'left')
+
+ if self:spejsiotData("d106e1", "environment", "degree") then
+ love.graphics.printf(string.format(
+ "%d° / %d%%RH",
+ self:spejsiotData("d106e1", "environment", "degree"),
+ self:spejsiotData("d106e1", "environment", "humidity")
+ ), 900, 378, 400, 'left')
else
love.graphics.printf("?!", 900, 378, 400, 'left')
end
- love.graphics.printf("ON or OFF?", 900, 438, 400, 'left')
- love.graphics.printf("ON or OFF?", 900, 498, 400, 'left')
+
+ self:renderIOTState("c0dbe7", "relay", "on", 900, 438)
+ self:renderIOTState("0eac42", "spin and blink", "on", 900, 498)
+
+ love.graphics.setColor( 255, 255, 255 )
love.graphics.setFont(headerFont)
love.graphics.printf("at hackerspace:", 50, 593, 300, 'left')
love.graphics.setFont(atFont)
diff --git a/nodes/newdash_thread.lua b/nodes/newdash_thread.lua
index eafda8a..d5a1b55 100644
--- a/nodes/newdash_thread.lua
+++ b/nodes/newdash_thread.lua
@@ -3,20 +3,18 @@ local http = require("socket.http")
local json = require("vendor.json")
local weatherURL = 'https://openweathermap.org/data/2.5/weather?id=6695624&units=metric&appid=b1b15e88fa797225412429c1c50c122a1'
-local insideURL = 'http://dht01.waw.hackerspace.pl/'
+local spejsiotURL = 'http://spejsiot.waw.hackerspace.pl/api/1/devices'
local atURL = 'http://at.hackerspace.pl/api'
-local insideData = {}
+local spejsiotData = {}
local atData = nil
local r, c, h = http.request(weatherURL)
if c == 200 then
local data = json.decode(r)
- local r, c, h = http.request(insideURL)
+ local r, c, h = http.request(spejsiotURL)
if c == 200 then
- for n in string.gmatch(string.gsub(r, ",", "."), ":%s*(%S+)[*%%]") do
- insideData[#insideData+1] = n
- end
+ spejsiotData = json.decode(r)
end
local r, c, h = http.request(atURL)
@@ -29,8 +27,7 @@ if c == 200 then
weather = data.weather[1].main:lower(),
temperature = data.main.temp,
lastUpdate = data.dt,
- insideTemperature = insideData[1],
- insideHumidity = insideData[2],
+ spejsiot = spejsiotData,
at = atData,
})
print("Update finished")