-->
Page 1 of 1

wifi.sleeptype and power consumption

PostPosted: Thu Mar 19, 2015 11:15 am
by Andeersg
Hi,

I have set up my ESP to do the following:
1. read temperature from ds18b20
2. if the temperature is different from last reading connect to wifi and transmit temperature to server
3. disconnect from wifi and wait 30 min.

All of this is working, but i noticed that it uses 69-70mA all the time. Today i tried to add:
Code: Select allwifi.sleeptype(wifi.MODEM_SLEEP)


Complete init.lua:
Code: Select all--init.lua

require('ds18b20')
port = 80
gpio0 = 3

key = 'livingroom'
temp = 0
ds18b20.setup(gpio0)

wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","PASSWORD")
realtype = wifi.sleeptype(wifi.MODEM_SLEEP)

print("Sleepmode "..realtype)

function readTemp()
  local current_temp = ds18b20.read()
  current_temp = ds18b20.read()
  current_temp = string.format("%8.1f", current_temp)
  print("Read temp " ..current_temp)
  if current_temp ~= temp then
    sendData(current_temp)
    temp = current_temp
  end
end

function sendData(up_temp)
  wifi.sta.connect()
  tmr.alarm(1, 1000, 1, function()
    if wifi.sta.getip()== nil then
      --print("IP unavaiable, Waiting...")
    else
      tmr.stop(1)
      -- Send value to server.
      conn=net.createConnection(net.TCP, 0)
      conn:on("receive", function(conn, payload) print(payload) end)
      conn:connect(80,'00.00.00.00')
      conn:send("GET /temptest.php?key="..key.."&field1="..up_temp.." HTTP/1.1\r\n")
      conn:send("Host: example.com\r\n")
      conn:send("Accept: */*\r\n")
      conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n")
      conn:send("\r\n")
      conn:on("sent",function(conn)
        conn:close()
      end)
      conn:on("disconnection", function(conn)
        -- Disconnect from network and save energy.
        wifi.sta.disconnect()
      end)
    end
  end)
end

-- run at startup.
readTemp()
-- send data every X ms, 1800000 == 30 minutes
tmr.alarm(0, 1800000, 1, function() readTemp() end )


But i don't see any change in power consumption. My code is also here: https://github.com/andeersg/wifi-temperature-logger

Am i doing something wrong? Or are there some other tricks i can use to reduce idle power consumption?

Re: wifi.sleeptype and power consumption

PostPosted: Fri Mar 20, 2015 1:42 am
by laurynas
deepsleep.
you need to connect a couple of pins for that, but it will then use 1000000x less energy :)

my dht22 sensor works on battery. it takes <2s to measure, connect and post to thingspeak. after that it goes to sleep for 10 minutes and resets after it.

Re: wifi.sleeptype and power consumption

PostPosted: Fri Mar 20, 2015 2:21 am
by Andeersg
Ok, was afraid of that :P

I'm not good at soldering that small, but i guess i just need to try.

Re: wifi.sleeptype and power consumption

PostPosted: Mon Mar 23, 2015 5:13 am
by aldepas
Hello, I saw that in your code using the wifi.MODEM_SLEEP mode, which is already used by default. It appears that the best mode wifi.LIGHT_SLEEP results.

http://bbs.espressif.com/viewtopic.php?f=6&t=133&p=485&hilit=sleep+modem#p485

http://bbs.espressif.com/viewtopic.php?f=7&t=171&p=617

http://www.esp8266.com/viewtopic.php?f=9&t=1719