Electron doesn't go back into standby mode


#1

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?


#2

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


#4

Sorry about that. Here it is:

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.


#5

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

#6

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?


#7

Yes

Yes

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().

No

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” :wink:


#9

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


#10

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.


#11

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:


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?