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);
}