Chat freely about anything...

User avatar
By Ghil
#35712 I try to send data (temperature) continuously to android ... With my code (below) I get the data and can display but only when ESP8266 itself receives data. I would send them continuously .... how to do it or where can I find a tutorial for it? Thank you very much for helping me

Code: Select allsv=net.createServer(net.TCP)
    sv:listen(1000,function(c)
      c:on("receive", function(c, pl)
            print(pl)
            c:send(readDHT())
       end)
     end)
     

PIN = 4 --  data pin, GPIO2

function readDHT()
   
  while h == nil do 
      dht22 = require("dht22")
      dht22.read(PIN)
   
      t = dht22.getTemperature()
   
      h = dht22.getHumidity()

   end
   h = nil
   dht22 = nil
 
   package.loaded["dht22"]=nil
   return "T"..((t-(t % 10)) / 10).."."..(t % 10)
 end 
      --print("H"..((h - (h % 10)) / 10).."."..(h % 10))
     
   

  tmr.alarm(0, 10000, 1, function() readDHT() end)