ESP8266: testing deep sleep & interrupts !?


This weekend I’ve been testing one of my ESP-12 module for more than just a few minutes; more like a few hours. Just to see how ‘robust’ the ESP8266 actually is. The story about ‘zombie mode‘, where the module didn’t restart after the deep sleep period had ended, made me curious whether the ESP8266 was stable enough (to use at all).

So I created these 2 scripts to make it do something useful for a change:

init.lua:

FileToExecute="gettemp.lua"
l = file.list();
for k,v in pairs(l) do
  if k == FileToExecute then
    print("*** You've got 5 sec to stop timer 0 ***")
    tmr.alarm(0, 5000, 0, function()
      print("Executing ".. FileToExecute)
      dofile(FileToExecute)
    end)
  end
end

gettemp.lua:

require('ds18b20')

serv_ip = '192.168.10.168'
serv_port = 8001
gpio4 = 2
interval = 20000000
ds18b20.setup(gpio4)

function getTemp()
  temp = ds18b20.read()
  conn = net.createConnection(net.TCP, 0)
  conn:on("connection", function(socket)
    socket:send(""..node.chipid().." "..tries.." "..temp.."\r")
  end)
  conn:on("sent",function(conn)
    conn:close()
  end)
  conn:on("disconnection", function(conn)
    node.dsleep(interval-tmr.now(), 0)
  end)

  conn:connect(serv_port, serv_ip)

end                   

function connect()
  tries = tries + 1
  wifi_ip = wifi.sta.getip()
  if wifi_ip == nil then
    if tries < 5 then
      tmr.alarm(0, 1000, 0, connect)
    else
      node.dsleep(interval-tmr.now())
    end
  else
    getTemp()
  end
end

tries = 0
connect()

Nothing spectacular – it reads a DS18B20 sensor, sends the temperature and some other data to a NodeJS TCP server, goes to deep sleep and wakes up 20 seconds after the previous wake-up, so that the module does this 180 times per hour. It has been running since Friday night.

ESP8266 measuring DS18B20 and going to deep sleep

But then I found another interesting post about deep sleep and interrupts. And if my interpretation is right, this could be what I’ve been looking for – I just had to try it out:

You can easily esp8266 wake from a deep sleep. Just bring on to the RST short negative pulse. I use it.

 

Well…it works! (on a ESP-12 that is, haven’t tested any other model).

ESP8266 wake-up wire

 

Whenever the black wire at the bottom of picture makes contact with the RST pin and effectively pulling it to GND, the ESP8266 wakes up – this needs further research! 🙂

For now, I resumed the reliability test for another night.

Tagged , , . Bookmark the permalink.

9 Responses to ESP8266: testing deep sleep & interrupts !?

  1. Richard says:

    I’m missing the wifi.sta.config en wifi.sta.connect?? Where did you put these options in gettemp.lua before function connect()?

  2. Pingback: ESP8266 current / power usage charts - Digits Domotica Blog

  3. Somewhere i’ve read that SSID and Password are stored in Flash, so that you have to set it only once.

    Did you figure out if connecting RST to GND does a “real wake up” (so that stored values are preserved) or just a simple “reset” with running the normal (re-)boot sequence?
    Martin

  4. Samyr Almeida says:

    Could you send me your NodeJS TCP server code?

    • Robert Hekkers says:

      var net = require('net');
      var tools = require("./tools");

      tools.initProcess('tcpserver');

      (function connect() {
      tools.mqttClient.connect({clientId: 'drv_'+tools.systemId});
      })();

      tools.mqttClient.on('connect', function(packet) {
      setupDriver();
      });

      function setupDriver(){
      tools.clog("Setting up driver");
      net.createServer(function (socket) {
      socket.name = socket.remoteAddress + ":" + socket.remotePort

      socket.on('data', function (data) {
      tools.log(new Date().toLocaleTimeString() + " < " + data); }); socket.on('error', function (error) { tools.log(new Date().toLocaleTimeString() + " SOCKET ERROR"); }); socket.on('close', function() { //tools.log(new Date().toLocaleTimeString() + " Closed"); }) socket.on('end', function() { //tools.log(new Date().toLocaleTimeString() + " End"); }) }).listen(8001); }

      All you need to do is drop the tools module, add the mqtt module and add some code to create the mqtt client yourself.

  5. Tarun says:

    How can i dot he same thing with arduino ??
    Can esp8266 wakes up when is receives any data serially?

Leave a Reply

Your email address will not be published. Required fields are marked *