Advertisement
Guest User

Untitled

a guest
Aug 14th, 2017
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.74 KB | None | 0 0
  1. STATUS_OK = 1
  2. STATUS_ERROR_CHECKSUM = 2
  3. STATUS_ERROR_TIMEOUT = 3
  4. time_between_sensor_readings = 60000
  5.  
  6. function getSensorData()
  7.   dht = require("dht")
  8.   status,temp,humi,temp_decimal,humi_decimal = dht.read(dhtPin)
  9.   if (status == dht.OK) then
  10.     temperature = temp.."."..(math.abs(temp_decimal)/100)
  11.     humidity = humi.."."..(math.abs(humi_decimal)/100)
  12.     if (temp == 0 and temp_decimal < 0) then
  13.       temperature = "-"..temperature
  14.     end
  15.     return STATUS_OK,temperature,humidity
  16.   elseif (status == dht.ERROR_CHECKSUM) then
  17.     print("DHT CHecksum error")
  18.     return STATUS_ERROR_CHECKSUM,0,0
  19.   elseif(status == dht.ERROR_TIMEOUT) then
  20.     return STATUS_ERROR_TIMEOUT,0,0
  21.   end
  22.   dht = nil
  23.   package.loaded["dht"] = nil
  24. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement