Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- STATUS_OK = 1
- STATUS_ERROR_CHECKSUM = 2
- STATUS_ERROR_TIMEOUT = 3
- time_between_sensor_readings = 60000
- function getSensorData()
- dht = require("dht")
- status,temp,humi,temp_decimal,humi_decimal = dht.read(dhtPin)
- if (status == dht.OK) then
- temperature = temp.."."..(math.abs(temp_decimal)/100)
- humidity = humi.."."..(math.abs(humi_decimal)/100)
- if (temp == 0 and temp_decimal < 0) then
- temperature = "-"..temperature
- end
- return STATUS_OK,temperature,humidity
- elseif (status == dht.ERROR_CHECKSUM) then
- print("DHT CHecksum error")
- return STATUS_ERROR_CHECKSUM,0,0
- elseif(status == dht.ERROR_TIMEOUT) then
- return STATUS_ERROR_TIMEOUT,0,0
- end
- dht = nil
- package.loaded["dht"] = nil
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement