Log says "Device disconnected"

After the IMP ran nice for about 12 h it suddenly only has the red (orange?) LED active. And the Device Logs are saying

2014-12-15 08:31:48 UTC+1 [Status] Device disconnected

I tried to reset the Wifi and add it again, but no response. Also I disconnected it an reconnected it to the 9V power supply - no result.

I found the blinkup code reference: http://electricimp.com/docs/troubleshooting/blinkup/

What hardware configuration are you using – imp001 card with April development board or another? how are you powering it and to what pins?

Also, are you sure the 9v battery hasn’t run out? Try it on USB power (moving the jumper)

@ctmorrision: how do I check what kind of board/card I’m using?

I figured out the reason: the battery was empty. But it looks like my device source code is sucking too much energy. Another new 9V battery also lasted only about 12 hours. :frowning:

This is the device source code, why is it draining the battery?

`// Code from http://www.slickstreamer.info/2013/09/electric-imp-solar-powered-temperature.html
hardware.pin9.configure(ANALOG_IN);
const b_therm = 3988;
const t0_therm = 298.15;
const r_therm = 10000;

// Configure Pins
// pin 8 is driven high to turn off temp monitor (saves power) or low to read
therm_en_l <- hardware.pin8;
therm_en_l.configure(DIGITAL_OUT);
therm_en_l.write(1);
// pin 9 is the middle of the voltage divider formed by the NTC - read the analog voltage to determine temperature
temp_sns <- hardware.pin9;
// instantiate sensor classes

function getTemp() {
// instantiate our thermistor class
myThermistor <- thermistor(temp_sns, b_therm, t0_therm, r_therm, 10, false);
therm_en_l.write(0);
local temperature = format("%.1f",myThermistor.read_c());
server.log(temperature);
agent.send(“updateTemp”, temperature);

imp.wakeup(60, getTemp);

}

/*

  • Code from https://github.com/electricimp/reference/tree/master/hardware/thermistor/examples/tempbug-battery

  • simple NTC thermistor

  • Assumes thermistor is the high side of a resistive divider unless otherwise specified in constructor.

  • Low-side resistor is of the same nominal resistance as the thermistor
    */
    class thermistor {

     // thermistor constants are shown on your thermistor datasheet
    

    // beta value (for the temp range your device will operate in)
    b_therm = null;
    t0_therm = null;
    // nominal resistance of the thermistor at room temperature
    r0_therm = null;

    // analog input pin
    p_therm = null;
    points_per_read = null;

    high_side_therm = null;

    constructor(pin, b, t0, r, points = 10, _high_side_therm = true) {
    this.p_therm = pin;
    this.p_therm.configure(ANALOG_IN);

     // force all of these values to floats in case they come in as integers
     this.b_therm = b * 1.0;
     this.t0_therm = t0 * 1.0;
     this.r0_therm = r * 1.0;
     this.points_per_read = points * 1.0;
    
     this.high_side_therm = _high_side_therm;
    

    }

    // read thermistor in Kelvin
    function read() {
    local vdda_raw = 0;
    local vtherm_raw = 0;
    for (local i = 0; i < points_per_read; i++) {
    vdda_raw += hardware.voltage();
    vtherm_raw += p_therm.read();
    }
    local vdda = (vdda_raw / points_per_read);
    local v_therm = (vtherm_raw / points_per_read) * (vdda / 65535.0);

     local r_therm = 0;	
     if (high_side_therm) {
     	r_therm = (vdda - v_therm) * (r0_therm / v_therm);
     } else {
     	r_therm = r0_therm / ((vdda / v_therm) - 1);
     }
    
     local ln_therm = math.log(r0_therm / r_therm);
     local t_therm = (t0_therm * b_therm) / (b_therm - t0_therm * ln_therm);
     return t_therm;
    

    }

    // read thermistor in Celsius
    function read_c() {
    return this.read() - 273.15;
    }
    }

getTemp();`

This code is not designed to be kind to the battery, as it does not go into deep sleep between readings.

I have a thermometer in my garden shed which has been reporting the temperature and humidity every ten minutes for seven weeks, and is just nearing empty. This was running off an 850 mAh LiPo cell, and the key is to go into deep sleep after every reading, which reduces the current drain to about 6 microamps. I am using the reference code for a C3V0+ from MakeDeck, which includes monitoring the real battery voltage through a built-in resistive divider.

@DrJack, how do I activate “Deep Sleep”?

You’ll need to call server.sleepfor() when the imp goes idle (use imp.onidle(), as per the server.sleepfor() documentation).

Set it to sleep for 60s; the imp will wake, you can take a reading and send it to the agent (which will automatically bring up the WiFi, which goes off in deep sleep), and then your code can put the imp back into deep sleep again.

Bear in mind, waking from deep sleep is a warm reboot - your Squirrel code starts afresh with no variables preserved (that’s one way we get the power saving), so you’ll need to adapt your code accordingly, ie. configure the pin(s), take a reading, send the reading, go to deep sleep.

Take a look at this instructable. It’s a low power temperature logged, and goes through how deepsleep works.

@smittytone, @breardedinventor: thank you very much!