Post your best Lua script examples here

User avatar
By bircoe
#10198 I get strange values out of my DHT22, see below:

Code: Select allTemperature: 47.4.0000000000002 deg C
Temperature: 117.32.3.2000000000004 deg F
Temperature: 117.32 deg F
Humidity: 117.8.0000000000007%


It's certainly not 47.4 degrees in my house, closer to half that...

I've used your library untouched from here: https://github.com/javieryanez/nodemcu- ... ster/dht22

Any ideas? The only thing I can come up with is my DHT22 is old and may be faulty, I've got another on the way. But the values do change when I breath on it so not sure what's going on here.
User avatar
By Toshi Bass
#11035 I am also having big difficulty with this new code (the older code has been working without issue for months with NodeMCU 0.9.2) however I tried with 0.9.5 20150213 and using dht22.lua I get out of memory and with dht22_min.lua it crashes with
?U)??????1?D)??D??? so which firmware version is this code supposed to work with ?
User avatar
By Pigs Fly
#11037 0.9.4 was the latest I've used - not too broken, no need to fix. This isn't an answer to your question, but keep in mind that the code just barely worked in the first place. Lua was so slow that my loop for receiving the DHT output (in the original working code earlier in the thread) had to be pared down to the bare essentials just to distinguish a binary one from a zero. Further, the bit timing was highly dependent upon the speed of Lua's execution.

It would not surprise me if newer Lua firmware was either faster or slower. If a newer version is slower, this code won't work at all. If it's faster, the threshold test for determining the bit length can be adjusted to account for the faster loop execution.

As to crashes, bad math, and other issues, that may be related to the new floating point capabilities which I haven't explored but is discussed throughout the forums.

The DHT code really would be best built into the firmware, but that's not something I can pursue right now.

I'm actually finding enough in the way of limitations with the ESP that I've switched to using one of those $2 mini-arduinos for reading sensors and controlling stuff, leaving the ESP only for network communication. It's just not worth the brain damage trying to make Lua push these limits, and I get lots more in terms of inputs and GPIO, and established, working libraries.

Good luck.