Hello,
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.
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:
Detect this specific motion and reconnect to the cloud.
Check the status of a Particle.function.
Respond by either stopping or returning to its previous running state depending on this function.
While the user would:
Enact this specific motion on the attached accelerometer.
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.