# Recovering from Electron running out of data

**URL:** https://community.particle.io/t/recovering-from-electron-running-out-of-data/26612
**Category:** Firmware
**Created:** [October 18, 2016, 11:26pm UTC](https://community.particle.io/t/recovering-from-electron-running-out-of-data/26612 "2016-10-18T23:26:40Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![hwestbrook](https://avatars.discourse-cdn.com/v4/letter/h/5f9b8f/32.png) [@hwestbrook](https://community.particle.io/u/hwestbrook)
#### Post date: [October 18, 2016, 11:26pm UTC](https://community.particle.io/t/recovering-from-electron-running-out-of-data/26612/1 "2016-10-18T23:26:40Z")

</div>

Hi All,

I’ve implemented @zoltan-fedor’s fix [here](https://github.com/spark/firmware/issues/687), which works well for the scenarios where the sim gets unplugged or the antenna comes off or the device gets kicked off the network during some maintenance.

However, it did not work for when an Electron of mine ran out of data. In this scenario the device ran out of data, then went into the flashing blue mode. I increased the data, but the device never reconnected, even though I could see it was cycling in and out of deep sleep mode.

Are there certain scenarios where the modem has to be power cycled beyond a deep sleep? I’m trying to decide if I need an external watchdog that can remove power from the electron for a period of time.

Also, is there a system event for this scenario? Right now I am using “setup\_update”, but I am wondering if being rejected by the cell tower has a different firmware event.

---

<div class="post-metadata">

### Author: ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)
#### Post date: [October 18, 2016, 11:34pm UTC](https://community.particle.io/t/recovering-from-electron-running-out-of-data/26612/2 "2016-10-18T23:34:55Z")

</div>

I’ve never tested it with running out of data, and blinking blue is not what I would have expected to happen, but this code sample has a pile of techniques for dealing with breaking out blinking blue, resetting the modem, and other things that can be helpful for robustness:

> **[rickkas7/electronsample](https://github.com/rickkas7/electronsample)**
>
> electronsample - Particle Electron sample code for fault tolerance and problem debugging

---

<div class="post-metadata">

### Author: ![hwestbrook](https://avatars.discourse-cdn.com/v4/letter/h/5f9b8f/32.png) [@hwestbrook](https://community.particle.io/u/hwestbrook)
#### Post date: [October 19, 2016, 12:34am UTC](https://community.particle.io/t/recovering-from-electron-running-out-of-data/26612/3 "2016-10-19T00:34:08Z")

</div>

What would you expect to happen, if not blink blue?

---

<div class="post-metadata">

### Author: ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)
#### Post date: [October 19, 2016, 4:42pm UTC](https://community.particle.io/t/recovering-from-electron-running-out-of-data/26612/4 "2016-10-19T16:42:45Z")

</div>

I figured you get blinking cyan. You still should be able to reach the cellular network (blinking green) but you wouldn’t be able to get to the cloud (breathing cyan) since IP data would be blocked. But that’s just a guess, I don’t actually know what happens.  
Edit: Now that I think about it, maybe the entire SIM gets deactivated when you hit the limit, so you would be stuck at blinking green. And there’s a thing at least in 0.4.8 where if you get stuck in blinking green it sometimes goes into blinking blue. So maybe that’s what’s happening.

---

<div class="post-metadata">

### Author: ![joky](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@joky](https://community.particle.io/u/joky)
#### Post date: [October 19, 2016, 4:53pm UTC](https://community.particle.io/t/recovering-from-electron-running-out-of-data/26612/5 "2016-10-19T16:53:03Z")

</div>

Hi,  
did you try the ApplicationWatchdog to recover from Listening-Mode?  
`ApplicationWatchdog wd(180000, watchdogCallback);`

I had some issues with SIM cards (contact issue, SIM disabled), the ApplicationWatchdog successfully reset the electron.

regards

---

<div class="post-metadata">

### Author: ![hwestbrook](https://avatars.discourse-cdn.com/v4/letter/h/5f9b8f/32.png) [@hwestbrook](https://community.particle.io/u/hwestbrook)
#### Post date: [October 19, 2016, 6:05pm UTC](https://community.particle.io/t/recovering-from-electron-running-out-of-data/26612/6 "2016-10-19T18:05:41Z")

</div>

@joky, yes, I am using both the application watchdog and an event handler to put my device into SLEEP\_MODE\_DEEP when there is a connectivity issue. This works well for situations like sim card gets unplugged, antenna is removed, etc. It doesn’t seem to work when the data limit is exceeded.

@rickkas7, I have yet to try your firmware, but my firmware implements most of what yours does for smart reboot, with the exception of `AT+CFUN=16`. Do you know why this command would be more beneficial than a SLEEP\_MODE\_DEEP reboot?

Really, what I am trying to decide is whether the Electron is capable of recovering itself from all of the cellular data connectivity issue edge cases. It seems to do OK for most of them, but I keep finding additional issues, like this one. I think in the end I will have to add an external power cycle watchdog to my device in order to protect against unknown edge cases.

---

<div class="post-metadata">

### Author: ![joky](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@joky](https://community.particle.io/u/joky)
#### Post date: [October 19, 2016, 6:44pm UTC](https://community.particle.io/t/recovering-from-electron-running-out-of-data/26612/7 "2016-10-19T18:44:11Z")

</div>

I see. My product should never go into listening mode. Never. Never ever.

Yes, it is quite comfortable for developing on my desk, but it is a big pain if the product goes into listening mode at any remote site.

---

<div class="post-metadata">

### Author: ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)
#### Post date: [October 19, 2016, 7:48pm UTC](https://community.particle.io/t/recovering-from-electron-running-out-of-data/26612/8 "2016-10-19T19:48:55Z")

</div>

No, SLEEP\_MODE\_DEEP is good for resetting the modem. I only tried the AT+CFUN=16 as an experiment. Both seem to work.

---

<div class="post-metadata">

### Author: ![hwestbrook](https://avatars.discourse-cdn.com/v4/letter/h/5f9b8f/32.png) [@hwestbrook](https://community.particle.io/u/hwestbrook)
#### Post date: [October 19, 2016, 9:46pm UTC](https://community.particle.io/t/recovering-from-electron-running-out-of-data/26612/9 "2016-10-19T21:46:13Z")

</div>

@rickkas7, Is there anything in your code that does more than SLEEP\_MODE\_DEEP to reboot the modem? Looks like you are calling Cellular.off(), but does this do anything more than what SLEEP\_MODE\_DEEP does?

---

<div class="post-metadata">

### Author: ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)
#### Post date: [October 19, 2016, 9:51pm UTC](https://community.particle.io/t/recovering-from-electron-running-out-of-data/26612/10 "2016-10-19T21:51:17Z")

</div>

No, it’s not necessary to turn cellular off; that’s done automatically with SLEEP\_MODE\_DEEP as long as you’re not also using SLEEP\_NETWORK\_STANDBY. SLEEP\_MODE\_DEEP should be sufficient, I think.
