Go Down

Topic: LowPower.sleep(120000) does not work (Read 4354 times) previous topic - next topic

AdeleK-Gregory

Jun 14, 2017, 10:08 am Last Edit: Jun 14, 2017, 10:14 am by AdeleK-Gregory
Hello,

"LowPower.sleep(120000)" doesn't work.

Thanks for your help...


Code: [Select]
/*
  SigFox Event Trigger tutorial

  This sketch demonstrates the usage of a MKRFox1200
  to build a battery-powered alarm sensor with email notifications

  A couple of sensors (normally open) should we wired between pins 1 and 2 and GND.

  This example code is in the public domain.
*/

#include <SigFox.h>
#include <ArduinoLowPower.h>

// Set debug to false to enable continuous mode
// and disable serial prints
int debug = true;

volatile int alarm_source = 0;

void setup() {

  if (debug == true) {

    // We are using Serial1 instead than Serial because we are going in standby
    // and the USB port could get confused during wakeup. To read the debug prints,
    // connect pins 13-14 (TX-RX) to a 3.3V USB-to-serial converter

    Serial1.begin(115200);
    while (!Serial1) {}
  }

  if (!SigFox.begin()) {
    //something is really wrong, try rebooting
    reboot();
  }

  //Send module to standby until we need to send a message
  SigFox.end();

  if (debug == true) {
    // Enable debug prints and LED indication if we are testing
    SigFox.debug();
  }

  // attach pin 0 and 1 to a switch and enable the interrupt on voltage falling event
  pinMode(0, INPUT_PULLUP);
  LowPower.attachInterruptWakeup(0, alarmEvent1, FALLING);

  pinMode(1, INPUT_PULLUP);
  LowPower.attachInterruptWakeup(1, alarmEvent2, FALLING);
}

void loop()
{
  // Sleep until an event is recognized
  LowPower.sleep(120000);
  Serial1.println("BEGIN");

  // if we get here it means that an event was received

  SigFox.begin();

  if (debug == true) {
    Serial1.println("Alarm event on sensor " + String(alarm_source));
  }
  delay(100);

  // 3 bytes (ALM) + 8 bytes (ID as String) + 1 byte (source) < 12 bytes
  String to_be_sent = "ALM" + SigFox.ID() +  String(alarm_source);

  SigFox.beginPacket();
  SigFox.print(to_be_sent);
  int ret = SigFox.endPacket();

  // shut down module, back to standby
  SigFox.end();

  if (debug == true) {
    if (ret > 0) {
      Serial1.println("No transmission");
    } else {
      Serial1.println("Transmission ok");
    }

    Serial1.println(SigFox.status(SIGFOX));
    Serial1.println(SigFox.status(ATMEL));

    // Loop forever if we are testing for a single event
    //while (1) {};
   
  }
}

void alarmEvent1() {
  alarm_source = 1;
}

void alarmEvent2() {
  alarm_source = 2;
}

void reboot() {
  NVIC_SystemReset();
  while (1);
}




pert

Please explain exactly what you mean by "doesn't work".

When your code requires a library that's not included with the Arduino IDE please always post a link (using the chain link icon on the toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger(Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

ArduinoLowPower repository:
https://github.com/arduino-libraries/ArduinoLowPower

AdeleK-Gregory

It means : The MKRFOX never goes out of sleep mode. Normally, it should go out of sleep mode after 120000 ms (2 mins).

astroman35

Try to add this line in your setup() function :
Code: [Select]
LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, alarmEvent0, CHANGE);

And create a dummy function :
Code: [Select]
void alarmEvent0() {
  alarm_source = 0;
}

AdeleK-Gregory


ghurbain

With this interrupt, When the arduino will wake up, it'll start all the sketch from beginning ? or just the loop ?

nimasa

Try to add this line in your setup() function :
Code: [Select]
LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, alarmEvent0, CHANGE);

And create a dummy function :
Code: [Select]
void alarmEvent0() {
  alarm_source = 0;
}

Thanks astroman35,
I was looking a lot for a solution to this problem and you saved me finally.

Pedotech

Astroman, you saved my day!
I donĀ“t really understand your solution, but it worked
Thanks a lot.

Go Up