Post your best Lua script examples here

User avatar
By f4n
#11519
jankop wrote:I don't know if the measured values are correct, but the sensor is read well.
You only have incorrectly set the type of sensor in the test program.
Code: Select allchecksum    103
humidity - timing of bits      0 1 1 1 1 1 5 1 5 1 5 1 1 5 5 1 = 0000 0010  1010 0110  = 678
temperat - timing of bits      1 1 1 1 1 1 1 5 5 2 5 5 5 5 5 1 = 0000 0001  1011 1110  = 446
checksum - timing of bits      1 5 5 1 1 5 5 10 = 0110 0111  = 103
2,6484375*256=678  678/10=67,8%
1,7421875*256=446  446/10=44,6 C


thank you for your reply and the hint with the device type.
however the values seems to be wrong. i sit here in my living room with ~19°C. i have a standalone sensor which measured 18,8°C and 42% humidity.

i changed the sensor type in the woats.lua and the new result is as follows (i recognized a lot of checksum/checksumTest mismatches and had to try a couple of times before i got this result, even with or without the pull up, similar results with a different dht22)
Code: Select allchecksum    37
checksumTest    37
humidity - timing of bits      0 1 1 1 1 5 1 2 5 1 1 1 1 5 1 2
temperat - timing of bits      1 1 1 1 1 1 1 5 5 2 1 5 5 5 1 1
checksum - timing of bits      1 1 5 1 1 5 1 10
Humidity:    115.6%
Temperature: 41.2 deg C
User avatar
By GerryKeely
#11929 Hi Titanium

Change your print statements to
Code: Select allprint("Temperature = "..t/10)
  print("Humidity = "..h/10)


and is if that works.
The latest version of nodemcu uses floating point maths ,when routines for dht22 were developed there was only integer maths available
Gerry