-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathwifi_sensor.lua
More file actions
54 lines (46 loc) · 1.37 KB
/
wifi_sensor.lua
File metadata and controls
54 lines (46 loc) · 1.37 KB
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
SensorPin1 = 5
status1 = "LOW"
oldstatus1 = "LOW"
gpio.mode(SensorPin1,gpio.INPUT,gpio.FLOAT)
SensorPin2 = 6
status2 = "LOW"
oldstatus2 = "LOW"
gpio.mode(SensorPin2,gpio.INPUT,gpio.FLOAT)
SensorPin3 = 4
function ReadDHT11()
dht11 = require("dht11")
dht11.init(SensorPin3)
t = dht11.getTemp()
h = dht11.getHumidity()
humi=(h)
temp=(t)
fare=((t*9/5)+32)
print("Humidity: "..humi.."%")
print("Temperature: "..temp.." deg C")
print("Temperature: "..fare.." deg F")
print("==================================")
dht11 = nil
package.loaded["dht11"]=nil
end
function run()
tmr.alarm(0, 500, 1, function() -- Set alarm to one second
if gpio.read(SensorPin1)==1 then status1="LOW" else status1="HIGH" end
if status1 ~= oldstatus1 then
print("Soil 1: "..status1)
print("==================================")
end
oldstatus1 = status1
end)
tmr.alarm(1, 500, 1, function() -- Set alarm to one second
if gpio.read(SensorPin2)==1 then status2="LOW" else status2="HIGH" end
if status2 ~= oldstatus2 then
print("Soil 2: "..status2)
print("==================================")
end
oldstatus2 = status2
end)
tmr.alarm(2, 5000, 1, function() -- Set alarm to one second
ReadDHT11()
end)
end
run()