Hello,
I am working on a project in which I seek to measure the water levels in wells in rural areas in my province. I have the flow of the program in a place where I am happy with it, but I have some concerns that I may not be sleeping correctly which may lead to unexpected errors. The basics of my code are as follows:
FuelGauge fuel;
float bVoltage1;
double bVoltage2;
SystemSleepConfiguration config;
void setup()
{
config.mode(SystemSleepMode::ULTRA_LOW_POWER);
//config.duration(86400s); //sleep for a day
config.duration(300s); //test values
}
void loop()
{
if(waitFor(notConnected, 90000))
{
SD_Measurements();
delay(2000);
System.sleep(config);
}
bVoltage1 = fuel.getSoC();
bVoltage2 = bVoltage1;
//measure water level, water temp
//post water level, temp and battery % to console and thingspeak
delay(2000);
System.sleep(config);
}
bool notConnected()
{
return !Particle.connected();
}
At the top I declare an object called config of class SystemSleepConfiguration, and in the setup I set config.mode(SystemSleepMode::ULTRA_LOW_POWER) because I like the current values that I see in the documentation relating to ULP mode. I set config.duration(); as 86400s to sleep for a day when actually deployed in the field, but for now I have been experimenting with different sleep values and timing with my phone to see if they are accurate. So far I am pleased with the accuracy of the wakeups, but I am wondering if there is anything else that I should be doing that I may have missed?
Also, at the top of the loop I have:
if(waitFor(notConnected, 90000))
{
SD_Measurements();
delay(2000);
System.sleep(config);
}
I am wondering if there is a better way to do this? I believe that when the Boron wakes back up from sleep the Particle.connect() function is called automatically which forces the Boron to attempt to connect. With my conditional, I am attempting to wait 90 seconds for the device to connect, and if it does not connect, I call my SD_Measurements() function which activates my sensors and does the measurements and then writes to SD card before going to sleep. Does my conditional make sense? I am using deviceOS 2.1.0 right now.
Thanks.