Calling Particle functions while WiFi is off/disconnected

I would like my photon to be disconnected from the WiFi, upon response to a motion sensor I wish for the Photon to reconnect and respond to the result of a function. In response I would like the Photon to either return to WiFi off mode or to finish its run depending on what the user has input to the Particle.function.

I need my other code to continue running through this process. Is this possible? I have tried experimenting a little bit with SYSTEM_THREAD(ENABLED) and using if (Particle.connected && ResultOfFunction == 1) {state = end}
in various combinations but not had success.

The code is a bit mixed up at the moment but I’m happy to sort out a demo if needs be and post where I am at the moment, I am more interested in if it is possible and what methods are open to me though rather than direct code debugging.

Respond to what function?
Who would be calling that function?
How would the caller know when to call the function?

But for the topic title: There is no way to call a Particle.function() while the device is not connected.

Hi ScruffR,
Thanks for your response, your work rate on these forums is incredible.

The function is a Particle.function that I have been using to signal the start and end of the mic recording code you helped me on the other week. This works fine when WiFi/cloud is permanently connected of course, but we now wish for the code to run offline.

In order to let the Photon know that the run is over I have introduced a response to motion. Ideally I would like the Photon to:

  1. Detect this specific motion and reconnect to the cloud.
  2. Check the status of a Particle.function.
  3. Respond by either stopping or returning to its previous running state depending on this function.

While the user would:

  1. Enact this specific motion on the attached accelerometer.
  2. Type into console.particle to signal that the run should end (could be in either order if needs be).

The user would call that function on the console.particle and they call it when they want the recording to stop and after they have ‘notified’ photon that it is time to stop (by motion on accelo).

My efforts are to stop false positive results of the accelorometer from stopping the recording taking place and want the function to act as a safeguard for this. Perhaps not possible though and I’ll have to think of an alternative

So to recap, you don’t actually need the remote Particle.function() call to be issued before the Photon is already online but it can rather be assumed the device is already online due to the previously detected motion “start” pattern and the function call should just provide a secondary means to stop an ongoing task (i.e. recording).
Is this correct?

If so, then I’d not see much issue with that.
You wouldn’t check the Particle.function() but instead check a flag that can be set remotely by calling the Particle.function() (in addition/parallel to setting the same flag via your accelerometer pattern).

int stopTask = 0; // global flag to indicate a stop request

int stopFunction(const char* arg) {
  stopTask = atoi(arg);
  return stopTask;
void loop() {
  if (stopTask) finishTask();

(Call this function with a numeric value not-equal to zero to trigger the finishTask() function)

Your other problem with preventing false positives on the stop pattern via the accelerometer might be a bit more tricky depending on your chosen patterns.

Great. Thank you so much, I’ll look at getting that working now.

Hi ScruffR,

Very quickly got it working when using the flag, thanks a lot :slight_smile:

1 Like