Skip to content

Instantly share code, notes, and snippets.

@perusio
Last active March 17, 2016 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perusio/345cc092d401daefb1dd to your computer and use it in GitHub Desktop.
Save perusio/345cc092d401daefb1dd to your computer and use it in GitHub Desktop.
DHT Lua ESP8266
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