Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By lizby
#58386 I'm using a DHT11 to get temperature readings, and want to use the temp_dec value to prevent dithering in my reporting (e.g., for changes between 20C and 21C when the actual temperature change is very small). I thought I could use temp_dec to make sure that the change was significant, but using recent cloud-built firmware (nodemcu-dev-15-modules-2016-11-15-02-51-25-integer.bin), temp_dec always has a value of 0. This is with a Wemos D1 module.

Am I doing something wrong? Would I be better off using float?

Code: Select allpin = 5
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
    ))
--    print("temp, last: "..temp.." ".._G.last_temp)
    if _G.last_temp == nil or temp ~= _G.last_temp then
      _G.last_temp = temp
      _G.temperature = temp
      _G.humidity = humi
      _G.message = _G.ModID.." ".._G.temperature.." ".._G.humidity.." 0 "
      dofile("sntptime.lua") -- was httpgettime.lua
    end

    -- 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 timed out." )
end