MKRFox lowpower.sleep not working

Hi,

I can’t get the lowpower to work… The board goes to sleep indefinitely. Replacing sleep with delay works fine.

Anybody an idea what can cause this? Simple setup with a onewire temperature sensor.

Here’s the code. I’m new at this so probably some stupid mistake. Any help is appreciated.

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

#define UINT16_t_MAX 65536
#define INT16_t_MAX UINT16_t_MAX/2

// Set debug to false to enable continuous mode
// and disable serial prints
int debug = false;
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

typedef struct attribute ((packed)) sigfox_message {
uint8_t status;
int16_t moduleTemperature;
int16_t ExtTemperature1;
int16_t ExtTemperature2;
uint8_t lastMessageStatus;
} SigfoxMessage;

int16_t convertoFloatToInt16(float value, long max, long min) {
float conversionFactor = (float) (INT16_t_MAX) / (float)(max - min);
return (int16_t)(value * conversionFactor);
}

// stub for message which will be sent
SigfoxMessage msg;

void setup() {

if (debug == true) {

Serial.begin(9600);
while (!Serial) {}
}

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();
// }
// start sensors
sensors.begin();
}

void loop()
{
msg.status = 1;
// if we get here it means that an event was received

// lees temperaturen uit

sensors.requestTemperatures(); // Send the command to get temperature readings
float temperature1 = sensors.getTempCByIndex(0);
float temperature2 = sensors.getTempCByIndex(1);

msg.ExtTemperature1 = convertoFloatToInt16(temperature1, 60, -60);
msg.ExtTemperature2 = convertoFloatToInt16(temperature2, 60, -60);

SigFox.begin();
delay(100);

// interne temperatuur bordje
float temperature = SigFox.internalTemperature();
msg.moduleTemperature = convertoFloatToInt16(temperature, 60, -60);

if (debug == true) {
Serial.println("temp1: " + String(temperature1));
Serial.println("temp2: " + String(temperature2));
Serial.println("Internal temp: " + String(temperature));
Serial.println(String(msg.moduleTemperature));
}

// Clears all pending interrupts
SigFox.status();
delay(1);

SigFox.beginPacket();
SigFox.write((uint8_t*)&msg, 12);

msg.lastMessageStatus = SigFox.endPacket();

if (debug == true) {
Serial.println("Status: " + String(msg.lastMessageStatus));
}

SigFox.end();

if (debug == true) {
// spin forever, so we can test that the backend is behaving correctly
while (1) {}
}

//Sleep for 15 minutes
LowPower.sleep(15 * 60 * 1000);

}

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

Try to add this line to your setup function :
LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, dummy, CHANGE);

Sorry for replying so late but this won't compile LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, dummy, CHANGE); ^ exit status 1 'dummy' was not declared in this scope

Thanks for the tip, I keep on looking

OK... noob error

You have to add the dummy function in your sketch

void dummy() { // This function will be called once on device wakeup // You can do some little operations here (like changing variables which will be used in the loop) // Remember to avoid calling delay() and long running functions since this functions executes in interrupt context }

what do you have to put in the dummy function ? a reboot / reset operation ? or keep empty like this and it'll start auto the loop void ?

ghurbain: what do you have to put in the dummy function ? a reboot / reset operation ? or keep empty like this and it'll start auto the loop void ?

it could be any simple thing. Just declare a variable there. Something like:

void dummy() { volatile int aaa=0; }

Hello,

I've had the same problem with the waking up from lowpower.sleep().

It seems that you have to use Serial1 (connected to pins 13&14, which are the TX & RX connectors) instead of the normal USB connector as the USB port may get confused during wakeup. I just ordered this FTDI- Adapter and hope that it will allow me serial print out. Otherwise, I will just connect the mkr fox to a battery and not have ANY SERIAL connection, thus sending the data directly to SigFox. Another thing I also read is that you may have problems with the computer recognizing the port, then you may need to install the correct driver for the FT232RL driver.

I got this information from the Author Antine de Chassey and the Video. I hope my conclusion is right and will keep you posted :)

So I connected the FTDI - USB and installed the corresponding driver. The Port shows on Arduino 1.8.13. However, I was not able to communicate with my Arduino at all (need to verify if maybe the driver is not working correctly/ was the wrong one/ connected the pins wrong). Consequently, I quit the serial communication and send the data directly to SigFox after the Arudino woke up from deepSleep() and made the measurements it successfully transmitted the data to SigFox. I had the code running for 24h just to verify if any hick-ups occurred.

Strangely when using the Sigfox commands the power consumption in deepSleep rose from 13uA to 60uA. Any one knows, why this might happen?

Kind regards,