Post your best Lua script examples here

User avatar
By iHaveESP
#9009 The alternative DHT module is leaner on heap ( ~700b). See https://github.com/nodemcu/nodemcu-firmware/tree/master/lua_examples

I have DHT11:

I made the following change to the module for DHT11 ( I don't have DHT22):

--h = 10 * b[1]
--t = 10 * b[3]
h = b[1]
t = b[3]

..it will return integer values for t and h.

This should be included in the usage example:

t, h = require("yet-another-dht22").read(4)
-- unload module
yet-another-dht22 = nil
package.loaded["yet-another-dht22"] = nil

-- t and h remain available to your program, call above to update variables and release
print(t)
print(h)

-Cheers!
User avatar
By iHaveESP
#9149 I should have been clearer, it's savings is the difference between the two:

" yet-another-dht22" not setting to "true", I have DHT11:
24056
> dht11 = require("dht11_dvv")
> =node.heap()
19848
>

"nodeMCU adopted module":
> =node.heap()
24056
> dht22 = require("dht22")
> =node.heap()
19104

...can mean the difference in stability vs reboots.
User avatar
By Fr4gg0r
#9196 If you implement it in C, it should only consume a few bytes (~ some function pointers and the name of the lua method) statically. ;)

Also you won't have any troubles with floats in C etc.