-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.lua
87 lines (67 loc) · 1.75 KB
/
app.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
local data = {
inTemp = "",
outTemp = "",
inPress = "",
outCond = "",
inHum = "",
outHum = ""
}
local config = require('config')
local display = require("display")
local domoticz = require("domoticz")
local sensor = require("weather_sensor")
function getIn()
sensor.read(config.DHT_PIN, config.ALTITUDE, function(inTemp, inHum, inPress)
data.inTemp = inTemp
data.inHum = inHum
data.inPress = inPress
print(data.inTemp .. ", " .. data.inHum .. ", " .. data.inPress)
if (config.HAS_DISPLAY) then
display.render(data)
else
reportToDomoticz()
end
end)
end
function reportToDomoticz()
-- update sensor
domoticz.updateSensorTempHum(
config.DOMOTICZ_API_URL,
config.DOMOTICZ_USER,
config.DOMOTICZ_PASSWD,
config.DOMOTICZ_INDOOR_DEVICE_ID,
data
)
end
function getOut()
domoticz.getSensorTempHumBaro(
config.DOMOTICZ_API_URL,
config.DOMOTICZ_USER,
config.DOMOTICZ_PASSWD,
config.DOMOTICZ_OUTDOOR_DEVICE_ID,
function(outTemp, outHum, outCond)
data.outTemp = outTemp or "?"
data.outHum = outHum or "?"
data.outCond = outCond or "?"
display.render(data)
reportToDomoticz()
end)
end
print("setting up")
i2c.setup(0, config.SDA_PIN, config.SCL_PIN, i2c.SLOW)
if (config.HAS_DISPLAY) then
display.init(config.OLED_ADDR)
end
sensor.init()
-- delay 5 seconds to wait for sensor
tmr.alarm(0, 5*1000, tmr.ALARM_SINGLE, function()
getIn()
if (config.HAS_DISPLAY) then
getOut()
end
end)
tmr.alarm(1, 1*60*1000, tmr.ALARM_AUTO, getIn) -- 1*60*1000 = every 1 minutes
if (config.HAS_DISPLAY) then
tmr.alarm(2, 5*60*1000, tmr.ALARM_AUTO, getOut) -- 1*60*1000 = every 5 minutes
end
print("all set")