MKRFOX power saving issue

Hello,

I have an issue using the MKRFOX board with power saving feature.
I am using the latest libraries and boards.

Simple way to reproduce:
Take EventTrigger example sketch, and change this:

LowPower.sleep();

to this:

LowPower.sleep(60000);

Result: I get two frames at 60 seconds interval, but never the third, a reset is necessary, and same behaviour continues.

After further troubleshooting I have identified that following part of code never returns after sending the second frame (second frame which is actually received by the backend).

I have also noticed that I only encounter this with timed wakeups, not event wakeups.

I also added this to be sure, but that didn't help:
LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, alarmEvent0, CHANGE);

While troubelshooting, I added this in the setup:
SigFox.debug();

And this time I got consistent results.

I then read in documentation that Enabling the debugging all the power saving features are disabled.

That doesn't impact SAMD power saving features.

So the WeatherMonitor example sketch which comes with Sigfox library simply doesn't work.

Is anybody able to reproduce or tell what is going wrong?

Yanik

For anyone else looking at this, I think this is the EventTrigger example sketch kickouille mentioned:

I know there is a problem with sleep and Serial, but I don't think it affects Serial1. Did you add any use of Serial to the sketch?

Hi Pert,

Thank you for your answer.

Also as reference, this sketch provided by Sigfox library, using timed wakeups doesn't, I get the first frame, then the second frame after 15 minutes, and that stops here:

Reading again my first post, I realized I didn't mention where that stops in the code, this call never returns if any timed sleep has occured before:
int ret = SigFox.endPacket();

This call also uses timed wakeups for managing the timeout... So I'm wondering if that could not be the problem, calling a sleep elsewhere in the code (in another class for instace), while primary code just woke up. Not sure exactly why. And this call in the setup disables power saving features from Sigfox class, making it all working as expected:

SigFox.debug();

Concerning your remark about the Serial or Serial1, the code is not using it at all.

Hi everyone,
I have the exact same problem with you as a kickouille.
Did you manage to fix it?

thanks

Hi,

I've not been able to fix it.
However I did some troubleshooting, including doing a simple blink program using sleep instead of delay, and within this program make a call to a method of another class which also runs a low power sleep, and that doesn't seem to be a problem.

That definitely looks to be a combination of the two timed wakeups with Sigfox, not sure where exactly.

Now I have to debug Sigfox class and put some markers to exactly identify where it blocks.

Hello,

Ok I've found where that blocks.

In SigFox.cpp, function:
int SIGFOXClass::send(unsigned char mess[], int len, bool rx)

There is following block:

  if (!debugging) {
#ifdef SIGFOX_SPI
    LowPower.attachInterruptWakeup(interrupt_pin, NULL, FALLING);
	//LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, alarmEvent0, CHANGE);
    LowPower.sleep(timeout);
	digitalWrite(LED_BUILTIN, HIGH);
#endif
    if (digitalRead(interrupt_pin) == 0) {
	  status();
      ret = statusCode(SIGFOX);
    }
    goto exit;
  }

You can see a call to status() block:

void SIGFOXClass::status()
{
  digitalWrite(chip_select_pin, LOW);
  spi_port->beginTransaction(SPICONFIG);
  spi_port->transfer(0x0A);
  spi_port->transfer(0);
  ssm = spi_port->transfer(0);
  atm = spi_port->transfer(0);
  sig = spi_port->transfer(0);
  sig2 = spi_port->transfer(0);
  spi_port->endTransaction();
  digitalWrite(chip_select_pin, HIGH);
  delay(1);
}

It appears that program stops working right after:
spi_port->transfer(0x0A);

However I have noticed that the problem exists even if there is no LowPower feature used in the main program.

At this point, my feeling is that SPI is not recovering as it should after SAMD is woken up for the second time.

I confirm that if Sigfox library is being put in debug mode, power saving features are disabled (as shown in the code above), and all is working good in this case.

So I believe there is not problem with Sigfox library.

To be tested: check if the MKR is able to talk to an SPI device after the first sleep, and after the second sleep.

Hello,

I found a workaround, I still have to check if there is maybe a problem with the ArduinoLowPower library and another SPI device in a timed sleep.

I added SPI related lines in following portions of code in SigFox.cpp:

#ifdef SIGFOX_SPI
    spi_port->end();
    LowPower.attachInterruptWakeup(interrupt_pin, NULL, FALLING);
    LowPower.sleep(timeout);
    spi_port->begin();
    spi_port->setDataMode(SPI_MODE0);
    spi_port->setBitOrder(MSBFIRST);
#endif

And I also ended SPI properly in this portion of code:

void SIGFOXClass::end()
{
  pinMode(poweron_pin, LOW);
  delay(1);
  digitalWrite(chip_select_pin, LOW);
  delay(1);
  spi_port->beginTransaction(SPICONFIG);
  spi_port->transfer(0x05);
  spi_port->endTransaction();
  delay(1);
  digitalWrite(chip_select_pin, HIGH);
  delay(1);
  spi_port->end();
}

Then everything seems to work as expected!

Yanik

Thanks for taking the time to share your findings kickouille!

thank you so much kickouille!!! everything seems to work also in my code.

Dear kickouille,
I have same problems. I tried your solution and I followed your instructions but now I can not send any messages!? probably did something wrong but I can not see where.

I added SPI related lines on 2 places in Sigfox.cpp file (line 170 and 234) and changed completely inside of void SIGFOXClass::end().

Could you check and advise where I made mistake?
Any chance of providing complete Sigfox.cpp file?

Br

Marin

Thaks, kickouille, :slight_smile:

Works great your solution in my code, I was crazy trying to find one solution for deepsleep.

Hello,
can this change in Sigfox.cpp file the reason why is green LED on even on 2xAA batteries? AFAIK, LEDs should be off while on battery power, or not?

Thank you.

Hi tried kickouille solution but now messages are not sent.
Actually I replaced everything in #ifdef SIGFOX_SPI. Kickouille says add but it's actually a replacement right?
Thanks for any help

Hi,

I tried to make these changes in SigFox.cpp and it seems now working as expected.

Thanks for this input.