newdash: Add spejsiot integration
parent
862d977fce
commit
62b8e8cad0
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue