javieryanez / nodemcu-modules

Modules for nodeMcu (LUA intepreter for ESP8266)
76 stars 47 forks source link

Wrong values or "attempt to perform arithmetic on global 'h' (a nil value)" #9

Open franzhartwig opened 6 years ago

franzhartwig commented 6 years ago

Hi,

I am using dht22_min.lua together with a small script for measuring temperature and humidity. My script is:

-- set up some DHT22 things from https://github.com/javieryanez/nodemcu-modules/tree/master/dht22
PIN = 4 --  data pin, GPIO2
dht22 = require("dht22_min")
chipserial = node.chipid()

-- run the server
dht22.read(PIN)
t = dht22.getTemperature()
h = dht22.getHumidity()

tdht22 = (t / 10).."."..(t % 10)
hdht22 = (h / 10).."."..(h % 10)
print("Temperature: "..tdht22.." C")
print("Humidity: "..hdht22.." %")

I am getting a nil value for humidity ( "attempt to perform arithmetic on global 'h' (a nil value)") some times, some times I get wrong values (about 11 deg and 25 % humidity, real temperature is about 24 deg actually). What should I change to get correct values and to get values every time the script runs?