Post your best Lua script examples here

User avatar
By jsgalway8266
#25082 Working to set up a suite of home sensors and am starting with this temp/humidity for practice working with the NODEMCU.

My setup includes ESP8266 Node MCU and DHT11. Latest firmware March 2015. DHT11 has 10k pullup resistor.
Files loaded, ran and provided following results:
--------------------------------------------------------
NodeMCU 0.9.5 build 20150318 powered by Lua 5.1.4

Hard Restart Wednesday, August 05, 2015 09:33:31

Humidity: -1%
Temperature: 0 deg C
Temperature: 32 deg F

Changed DHT11 module, got same results.
DHT11 module is plugged into 3.3v, GND and D4 pins on NODEMCU board.

-----------------------------------------------
Uploaded the WOTS.LUA and TESTDHT.lua files and got the following results for the sensors:

dofile(wots.lua) Wednesday, August 05, 2015 09:09:32

dofile("wots.lua")
checksum 119
checksumTest 118
humidity - timing of bits 0 6 1 2 2 6 1 1 1 1 2 2 1 1 1 1
temperat - timing of bits 2 2 6 6 2 1 6 2 1 2 2 1 1 2 2 1
checksum - timing of bits 1 6 6 6 2 6 6 10
Humidity: 0%
Temperature: 50 deg C

What did I miss or not configure properly?
User avatar
By jankop
#25098
Code: Select allchecksum - timing of bits 1 6 6 6 2 6 6 10


Checksum is bad and humidity is set to nil. Timing of the last bit is too long.
Has your ESP8266 sufficiently strong powersource? Is sensor connection really correct? Has resistor value really 10k ohms?
User avatar
By jsgalway8266
#25120 Has your ESP8266 sufficiently strong powersource? Power supply is 5.1vdc at 2.1A.
Is sensor connection really correct? I believe so.
Has resistor value really 10k ohms? SMD component is labeled 103 which I assume is 10 K ohms.
The DHT11 was acquired from SEEED studio and is an AOSONG sensor on circuit board with Pin 1 labeled GND and connected to GND on Node MCU. Pin 2 is Vcc and connected to 3.3vdc on Node MCU. Pin 4 is labeled sig and connected to D4 on NodeMCU.

Is there another suggested way to connect the DHT11?
Thanks.
User avatar
By jsgalway8266
#25132 So, since my checksum doesn't match, could the following code from DHT11.lua be the problem?

--DHT data acquired, process.
for i = 1, 8, 1 do
if(bitStream[i+0]>2)then
humidity=humidity+2^(8-i)
end
if(bitStream[i+8]>2)then
checko1=checko1+2^(8-i)
end
if(bitStream[i+16]>2)then
temperature=temperature+2^(8-i)
end
if(bitStream[i+24]>2)then
checko2=checko2+2^(8-i)
end
if (bitStream[i+32]>2)then
checksum=checksum+2^(8-i)
end
end

checksumTest=(humidity+checko1+temperature+checko2)%256

If so, what should it be?

Thanks