# Electron doesn't go back into standby mode

**URL:** <https://community.particle.io/t/electron-doesnt-go-back-into-standby-mode/47200>\
**Category:** Troubleshooting\
**Created:** [January 22, 2019, 11:49pm UTC](https://community.particle.io/t/electron-doesnt-go-back-into-standby-mode/47200 "2019-01-22T23:49:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![lunchboxp](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@lunchboxp](https://community.particle.io/u/lunchboxp)\
**Post date:** [January 22, 2019, 11:49pm UTC](https://community.particle.io/t/electron-doesnt-go-back-into-standby-mode/47200/1 "2019-01-22T23:49:46Z")

</div>

I had my electron gathering some sensor data, then going into standby mode for 10 minutes. Everything was working fine at my house where I flashed the code and let the system run. The particle light would breath blue, gather data, then the light would turn off for 10 minutes while in standby mode. The data would be published to the console every 10 minutes as expected. To test further, I brought my electron with me while driving elsewhere, but I noticed my electron blinked green, then after a bit stayed breathing blue the entire time while I drove (~40 minutes). It never went back into standby mode, and data was never published during that time either. When I clicked the reset pin on the electron, it went back to behaving as it should though. Any ideas why is stopped functioning? And how I can fix this?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [January 23, 2019, 12:05am UTC](https://community.particle.io/t/electron-doesnt-go-back-into-standby-mode/47200/2 "2019-01-23T00:05:09Z")

</div>

No (or rather too many possibilities for) ideas without seeing your code.

---

<div class="post-metadata">

**Author:** ![lunchboxp](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@lunchboxp](https://community.particle.io/u/lunchboxp)\
**Post date:** [January 23, 2019, 12:12am UTC](https://community.particle.io/t/electron-doesnt-go-back-into-standby-mode/47200/4 "2019-01-23T00:12:12Z")

</div>

Sorry about that. Here it is:

[https://go.particle.io/shared\_apps/5c46b352fb743441a60005dc](https://go.particle.io/shared_apps/5c46b352fb743441a60005dc)

The general overview is a lot of sensors gathering data, sending it to the cloud, also storing it onto an sd card, then going into standby mode. Then repeat. I also plan on having the sensors be able to store on the sd card even if there is no cellular connection.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [January 23, 2019, 11:43am UTC](https://community.particle.io/t/electron-doesnt-go-back-into-standby-mode/47200/5 "2019-01-23T11:43:43Z")

</div>

I can’t see anything obvious to be causing this, but I’d have a few hints

- try `SYSTEM_THREAD(ENABLED)` - since the blocking happend while moving (probably crossing multiple cells) and that may have caused dropped connection that may not have fully been reestablished, resulting in hanging application thread
- with that you should wrap your publish instruction in a `if (Particle.connected())` check
- since you are not actually using Standby Sleep (aka deep sleep) but Stop Mode Sleep, you should stay away from `String` objects but rather use character arrays (aka C strings)
- use `snprintf()` to create “compound” strings
- this formula is written quite unfortunate `analogRead(light)*(3.3/4095.0)/10000.0)*1000000)/0.2)` - try to reduce divisions especially (BTW, division by 0.2 is better written as multiplication by 5)
- rework your indentation - as it is it’s quite confusing to follow the flow hierarchy
- to get a feeling where your code gets stuck, you should check the serial output. If that is inconclusive add some more `Serial.print()` statements that provide more detail

---

<div class="post-metadata">

**Author:** ![lunchboxp](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@lunchboxp](https://community.particle.io/u/lunchboxp)\
**Post date:** [January 23, 2019, 7:57pm UTC](https://community.particle.io/t/electron-doesnt-go-back-into-standby-mode/47200/6 "2019-01-23T19:57:36Z")

</div>

Thank you so much for this. I’ll try this. To confirm my understanding, my code is in automatic mode, so if a cellular connection is lost, the software will stop running until a connection is reestablished. By inserting SYSTEM\_THREAD(ENABLED), even if connection is lost, the system should keep running, correct?  
Then what happens if I try to go into sleep network standby mode but there is no cellular connection?

Also, does closing the browser showing the Particle console have any effect on how the hardware is run? I see the data isn’t published to the console anymore, but does it affect anything else?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [January 23, 2019, 8:06pm UTC](https://community.particle.io/t/electron-doesnt-go-back-into-standby-mode/47200/7 "2019-01-23T20:06:38Z")

</div>

> [@lunchboxp](#):
>
> if a cellular connection is lost, the software will stop running until a connection is reestablished.

Yes

> [@lunchboxp](#):
>
> By inserting SYSTEM\_THREAD(ENABLED), even if connection is lost, the system should keep running, correct?

Yes

> [@lunchboxp](#):
>
> Then what happens if I try to go into sleep network standby mode but there is no cellular connection?

This is up to your code. You can either wait for the connection to get reestablished to ensure your event can be sent, or you just ignore the fact and send the device to sleep. When it wakes up next time - with Stop Mode Sleep - it should just carry on trying to reestablish the connection and also run your `loop()`.

> [@lunchboxp](#):
>
> Also, does closing the browser showing the Particle console have any effect on how the hardware is run?

No

> [@lunchboxp](#):
>
> I see the data isn’t published to the console anymore, but does it affect anything else?

No, you _ **don't** _ see the data _ **isn't published** _ but you don't see _ **whether** _ the data is published.  
Your question is like: "Does a falling tree make a sound when noone is there to hear it" 😉

---

<div class="post-metadata">

**Author:** ![lunchboxp](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@lunchboxp](https://community.particle.io/u/lunchboxp)\
**Post date:** [January 23, 2019, 8:33pm UTC](https://community.particle.io/t/electron-doesnt-go-back-into-standby-mode/47200/9 "2019-01-23T20:33:39Z")

</div>

Ah I see, okay thank you. Is there a way to see all the published data, even if the browser is closed?

---

<div class="post-metadata">

**Author:** ![ninjatill](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/ninjatill/32/17370_2.png) [@ninjatill](https://community.particle.io/u/ninjatill)\
**Post date:** [January 23, 2019, 8:37pm UTC](https://community.particle.io/t/electron-doesnt-go-back-into-standby-mode/47200/10 "2019-01-23T20:37:20Z")

</div>

> [@lunchboxp](#):
>
> Is there a way to see all the published data, even if the browser is closed?

No. Publishes live momentarily and if you aren't there to catch it, then you cannot retrieve it after the fact. You need to have a device listening for the publishes; which could be a particle device, console, web app, or some other custom application. If you need to see a historical record, you should look into the Log functionality, specifically the Papertrail integration.

---

<div class="post-metadata">

**Author:** ![lunchboxp](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@lunchboxp](https://community.particle.io/u/lunchboxp)\
**Post date:** [January 24, 2019, 6:42pm UTC](https://community.particle.io/t/electron-doesnt-go-back-into-standby-mode/47200/11 "2019-01-24T18:42:57Z")

</div>

I took your advice. I let my system run overnight. It ran successfully for ~5 hours, even while I drove around with it. The led would breath cyan to gather data, then the led would turn off for 10 minutes and go into standby mode, just as expected. But it stopped working again overnight. When I checked in the morning (7 a.m.), the led was just breathing cyan and never going into standby mode. I left my console open to gather what should’ve data every 10 minutes, but instead saw the following:

 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/f/0/f07efdba1ec5b4826e37f5f7c5a995328d58fa7b.PNG)  
 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/c/1/c12363c1b31b230d3a6ab757f284a1e42f7fe36b.PNG)

Under device vitals it says I also had 3 disconnected events, so that might play a part.The typical pattern for the output should be deviceLocator -\> hook-sent -\> hook-response -\> Data. But that pattern seemed to stop overnight. From the output it looks like I was able to get the hook-response, but the data was never published. In my code I call for location before I publishing the data, so I think the problem lies somewhere between those two points. I’m wondering if the code got stuck in some sort of infinite loop somewhere, as the Electron was breathing cyan (connected to cloud), but never published the data. Maybe while trying to get location?
