Espruino-wifi not deepSleeping

Posted on
  • Hi friends.
    I'm trying to get confidence with Espruino-wifi.

    Here is a very simple program that just HPPT.get to a we server, on every 20 secs.
    I've measured the current adsorbed and it is never below 20mA.
    Of course it peaks to about 90mA when transmitting, but this is not the problem.

    When measuring the board is not connected to USB.
    Power (5V) is supplied on pins GND and VBA.

    I was expecting less that 1 mA when deepSleeping, but, as far as I understand, I'm not able to convince the board to sleep deep enought :-).

    So thanks for your help.
    Marco

    Here is my code.

    function manage() {
      
      //USB.setConsole();
      
      var WIFI_NAME = "tzaziki";
      var WIFI_OPTIONS = {
        password: ""
      };
    
      var wifi = require("EspruinoWiFi");
      var HTTP = require ("http");
     
      setDeepSleep(1);
      wifiConnected = false;
    
      // Need to connect before setIntervan (..) because it will produce a timeout
      wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {
          if (err) {
            console.log("Connection error: " + err);
          } else {
            console.log("Connected!");
            wifiConnected = true;
          }
        });
      
      
      setInterval(function() {
        console.log ("new cycle ...");
        if (wifiConnected === false)
          {
            console.log ("reconecting to wifi...");
            wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {
            if (err) {
              console.log("Connection error: " + err);
            } else {
              console.log("Connected!");
              wifiConnected = true;
            } 
          });
        }
    
        HTTP.get("http://192.168.1.121:1880/espr­uino?Temp=24", function(res) {
          res.on('data', function(data) {
            console.log(data);
          });
          res.on('close', function(data) {
            console.log("HTTP got close.");
          });
          res.on('error', function(data) {  // timeout not trapped 
            console.log("HTTP error.");
            wifiConnected = false;
          });
        });
     
        }, 20000);
      
      console.log("deepSleep enabled.");
      setDeepSleep(1);
    }
    
    function onInit() {
      manage();
    }
    save();
    
  • I think your problem is that you are still connected to WiFi - while the microcontroller itself can draw very little power, WiFi still takes a lot.

    Also, setDeepSleep(1); can't be used when there's a WiFi connection as it stops the UART from working correctly.

    How about:

    function finished() {
      wifi.disconnect();
      setDeepSleep(1);
    }
    function newCycle() {
      setDeepSleep(0);
      wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {
        if (err) { 
          finished();
          return;
        }
        HTTP.get("http://192.168.1.121:1880/espr­uino?Temp=24", function(res) {
          res.on('data', function(data) {
            console.log(data);
          });
          res.on('close', function(data) {
            console.log("HTTP got close.");
            finished();
          });
          res.on('error', function(data) {  // timeout not trapped 
            console.log("HTTP error.");
            finished();
          });
        });
      });
    }
    setInterval(newCycle, 20000);
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Espruino-wifi not deepSleeping

Posted by Avatar for marcotglb @marcotglb

Actions