Wifi Temperature and Humidity Logger.

LUA Code

pin = 3
Humidity = 0
HumidityDec=0
Temperature = 0
TemperatureDec=0
Checksum = 0
ChecksumTest=0

function get_()
Humidity = 0
HumidityDec=0
Temperature = 0
TemperatureDec=0
Checksum = 0
ChecksumTest=0

bitStream = {}
for j = 1, 40, 1 do
bitStream[j]=0
end
bitlength=0

gpio.mode(pin, gpio.OUTPUT)
gpio.write(pin, gpio.LOW)
tmr.delay(20000)
gpio_write=gpio.write

gpio.mode(pin, gpio.INPUT)

--bus will always let up eventually, don't bother with timeout

c=0
while (gpio_read(pin)==1 and c<100) do c=c+1 end

--bus will always let up eventually, don't bother with timeout

c=0
while (gpio_read(pin)==1 and c<100) do c=c+1 end

--acquisition loop
for j = 1, 40, 1 do
end
bitStream[j]=bitlength
bitlength=0
--bus will always let up eventually, don't bother with timeout
end

--DHT data acquired, processing it :-

for i = 1, 8, 1 do
if (bitStream[i+0] > 2) then
Humidity = Humidity+2^(8-i)
end
end
for i = 1, 8, 1 do
if (bitStream[i+8] > 2) then
HumidityDec = HumidityDec+2^(8-i)
end
end
for i = 1, 8, 1 do
if (bitStream[i+16] > 2) then
Temperature = Temperature+2^(8-i)
end
end
for i = 1, 8, 1 do
if (bitStream[i+24] > 2) then
TemperatureDec = TemperatureDec+2^(8-i)
end
end
for i = 1, 8, 1 do
if (bitStream[i+32] > 2) then
Checksum = Checksum+2^(8-i)
end
end
ChecksumTest=(Humidity+HumidityDec+Temperature+TemperatureDec) % 0xFF

print ("Temperature: "..Temperature.."."..TemperatureDec)
print ("Humidity: "..Humidity.."."..HumidityDec)