I’m Building a geocache gadget cache and I’m trying to use the imp.deepsleepfor command. My program seems to be working fine except the imp.wakeup resolution for my lock (on line 5) is controlled by the imp.sleep (on line 54). I’m sure i made a noob mistake can someone help me?
`
//---------------Lock Function----------------------------
function powerHandler(state) {
server.log(“Cache Opened”);
hardware.pin5.write(state);
imp.wakeup(0.1, function(){ //keeps lock from burning up
hardware.pin5.write(0)
})}
//---------------Battery Sleep Wakeup Code----------------
// Description: Debounced button press with callbacks
class Button{
static NORMALLY_HIGH = 1;
static NORMALLY_LOW = 0;
_pin = null;
_pull = null;
_polarity = null;
_pressCallback = null;
_releaseCallback = null;
constructor(pin, pull, polarity, pressCallback, releaseCallback){
_pin = pin; //Unconfigured IO pin, eg hardware.pin2
_pull = pull; //DIGITAL_IN_PULLDOWN, DIGITAL_IN or DIGITAL_IN_PULLUP
_polarity = polarity; //Normal button state, ie 1 if button is pulled up and the button shorts to GND
_pressCallback = pressCallback; //Function to call on a button press (may be null)
_releaseCallback = releaseCallback; //Function to call on a button release (may be null)
_pin.configure(_pull, debounce.bindenv(this));
}
function debounce(){
_pin.configure(_pull);
imp.wakeup(0.050, getState.bindenv(this)); //Based on googling, bounce times are usually limited to 10ms
}
function getState(){
if( _polarity == _pin.read() ){
if(_releaseCallback != null){
_releaseCallback();
}
}else{
if(_pressCallback != null){
_pressCallback();
}}
_pin.configure(_pull, debounce.bindenv(this));
}}
// we can only go to deepsleep if hardware.pin1 is low
function TrySleep() {
if (hardware.pin1.read() == 0) {
// if pin1 is low, we can sleep
server.log(“Going to sleep”);
imp.onidle(function() { imp.deepsleepfor(3600.0); });
} else {
hardware.pin8.write(1); //Turns on RGB LED’s
// server.log(“Can’t sleep, 9 volt battery inserted, RGB LED’s active”)
// if we can’t go to sleep yet, wait a while, then try again
imp.sleep(0.5);
imp.onidle(TrySleep);
}}
//---------------Diagnostics------------------------------
//coming soon
//---------------Configuration----------------------------
agent.on(“power”, powerHandler);
hardware.pin1.configure(DIGITAL_IN_WAKEUP);
hardware.pin5.configure(DIGITAL_OUT);
hardware.pin8.configure(DIGITAL_OUT);
hardware.pin9.configure(DIGITAL_IN_PULLUP);
// go to sleep loop
TrySleep();
//powerHandler();
`