-->
Page 1 of 1

"require" not working?

PostPosted: Fri Feb 13, 2015 2:17 pm
by quantalume
I'm new to Lua, but my understanding is that require() returns an object table. After flashing the latest pre-build (nodemcu_latest.bin), I get the following behaviour:

Code: Select all>PIN = 5 --  data pin, GPIO14
> dht22 = require("dht22")
> dht22.read(PIN)
stdin:1: attempt to index global 'dht22' (a boolean value)
> print(dht22)
true
>


I'm using Javier Yanez' DHT22, but this seems to be true with other Lua modules I've tried. This all worked fine with the 2015-01-27 build. Does this have something to do with node.compile()? I have not compiled any of the modules.

EDIT: I just tried downgrading to nodemcu_20150212.bin, and everything is working as expected again:

Code: Select all> dht22 = require("dht22")
> dht22.read(PIN)
> print(dht22)
table:
>

Re: "require" not working?

PostPosted: Fri Feb 13, 2015 6:24 pm
by MK1888
Does it matter that you're not setting the pin mode?

Re: "require" not working?

PostPosted: Sat Feb 14, 2015 3:22 pm
by quantalume
I think the problem was related to the flash filesystem. When I first upgraded to the 20150213 build, all of the files were still showing up (init.lua and dht22.lua). After upgrading to 20150214, the filesystem appeared to be purged, so I re-uploaded dht22.lua using ESPlorer. It now seems to work fine, even when reverting to 20150213.