Photon - offline mode

I’m trying to run my photon in offline (semi-automatic) mode. However, I find it still takes a long time to start up and it handshaking with the web service. I want it to be able to work and run my code with weak or no wifi.

Currently, I have these two lines in setup, I find that putting them at the top of the script causes it not to compile. The LED does go white when it finally starts up, but it’s super slow to start and spends a lot of time in fast blinking green with occasional red flashes before startup.

SYSTEM_MODE(SEMI_AUTOMATIC);

boolean connectToCloud = false;

Here’s all of my code:

How can I get it to run reliable with no wifi whatsoever? Thanks.

SYSTEM_MODE(SEMI_AUTOMATIC) is not supposed to be placed inside any function (in your case setup()) but at the very top of your main project file.

And if you define boolean connectToCloud = false inside of setup() it’ll only exist in there and nowhere else.

1 Like

That’s what I thought, but it doesn’t compile if I put it at the top of the script. Moving it inside setup seems to compile and run, and it doesn’t show up in the console now, so I thought it was working but apparently somethings not right.

Any idea why the code would fail to compile in the web IDE with the mode function at the very top?

Thanks.

If you are using Web IDE you can always post a SHARE THIS REVISION link for us to have a look at your original code and possibly see/locate other issues.

1 Like

https://go.particle.io/shared_apps/5b9d7d49c3cbfa4c9c0010f2

Here’s the sharable link to the code. Thanks.

OK, having a look at your code now.

  1. You need to move SYSTEM_MODE() to the top of the sketch - as I already said and I mean it.
  2. You have strip.show() inside several loops. that are supposed to first update all the LEDs and only after that’s done (aka outside the loop) you should call strip.show() once.
  3. While it won’t make a lot of difference in this case, you are using the wrong operator in this (voltageArray[i] > 4100 | voltageArray[i] < 3600). You need the logical OR operator || not the binary |.
  4. Whenever you have a loop that may potentially keep your code trapped, you may either add a Particle.process() call or go with SYSTEM_THREAD(ENABLED)
  5. After a Wire.requestFrom() you may consider adding some short delay before checking Wire.available()
  6. Are the required I2C pull-ups in place?

Try this one
https://go.particle.io/shared_apps/5bab482c3242a9571a000f9c

2 Likes

Sorry for the late reply, thanks so much for the code review.

Yeah, I2C pullups are on one of the chips, and communication there has been alright far as I can tell, although I’m firing it up today to work on your suggestions and the whole system seems to have gone haywire with my cell voltages all reading 65000 (or so).

Of course I foolishly sealed things up inside the case thinking I was done with development, b/c it worked alright on the bench, sigh.

I’ll work on this more and report back if there are further issues. I can confirm that the code compiles now with SYSTEM_MODE() up top, for some reason, and it must have been something else, when I tried it this way originally it wouldn’t compile and the error referenced this function as not being defined.

Thanks again.

Just noticed you made a revised version for me, thanks! That clarifies several things. I’ll flash it and do a bit more testing on the hardware.