# Does my Boron LTE sleep code make sense?

**URL:** <https://community.particle.io/t/does-my-boron-lte-sleep-code-make-sense/61069>\
**Category:** Firmware\
**Created:** [September 2, 2021, 6:18pm UTC](https://community.particle.io/t/does-my-boron-lte-sleep-code-make-sense/61069 "2021-09-02T18:18:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ML88](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@ML88](https://community.particle.io/u/ML88)\
**Post date:** [September 2, 2021, 6:18pm UTC](https://community.particle.io/t/does-my-boron-lte-sleep-code-make-sense/61069/1 "2021-09-02T18:18:22Z")

</div>

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:

```auto
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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![dreamER](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/dreamer/32/26550_2.png) [@dreamER](https://community.particle.io/u/dreamER)\
**Post date:** [September 3, 2021, 2:55am UTC](https://community.particle.io/t/does-my-boron-lte-sleep-code-make-sense/61069/2 "2021-09-03T02:55:41Z")

</div>

> [@ML88](#):
>
> bool notConnected()  
> {  
> return !Particle.connected();  
> }

In my understanding this part of your code is at least wired as is going to return 0 when is actually connected it’s some kind of:  
“ there’s no true that is not raining “  
😊  
Could you please use preformatted text functionality when you post the code and also (if you don’t mind) post entire code that will be much easier to provide any hints

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/6/4/64635adccc35238caa19e9b553ec3e98b163d026.png) [@system](https://community.particle.io/u/system)\
**Post date:** [March 4, 2022, 2:56pm UTC](https://community.particle.io/t/does-my-boron-lte-sleep-code-make-sense/61069/3 "2022-03-04T14:56:02Z")

</div>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
