Last active
March 17, 2016 19:09
-
-
Save perusio/345cc092d401daefb1dd to your computer and use it in GitHub Desktop.
DHT Lua ESP8266
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function print_dht_data(pin) | |
local status, temp, humi, temp_dec, humi_dec = dht.read(pin) | |
if status == dht.OK then | |
-- Integer firmware using this example. | |
print( | |
string.format( | |
'DHT Temperature:%d.%03d - Humidity:%d.%03d\r\n', | |
math.floor(temp), | |
temp_dec, | |
math.floor(humi), | |
humi_dec | |
) | |
) | |
-- Float firmware using this example. | |
print('DHT Temperature: '.. temp .. '-' .. 'Humidity:' .. humi) | |
elseif status == dht.ERROR_CHECKSUM then | |
print('DHT Checksum error.') | |
elseif status == dht.ERROR_TIMEOUT then | |
print('DHT Time out.') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment