Running Pressure Sensor While Particle Photon is in offline mode

Hello! I’m currently working on a project and I’m having trouble running my function while my particle photon is in offline mode (when the device is not connected to the cloud), I’m running this in MANUAL system mode. The function while online is to read the pressure sensor value and outputs red LED light or green LED light depending on the sensor values. And I want the offline mode to be doing the same thing and when I get to offline mode, it takes about 45 secs to a minute delay (it doesn’t immediately changes light according to the sensor value as the online mode would do). Have any idea what might be happening here? While in online, it works perfectly. It’s just while in offline mode. Thank you for your help in advanced!

Here is my loop under MANUAL system mode.

void loop()
{
    while(Particle.connected()==false)
    {
        Particle.process();
        function1(); //just turning red or green led according to the sensor value
        Particle.process();

    }
    while(Particle.connected()==true)
    {   
        Particle.process();
        function(); //just turning red or green led according to the sensor value
        Particle.process();
    }
 }

@IsaacG It generally helps if you can include a little more of your code. Is SYSTEM_THREAD(ENABLED); ?
Also, in setup() did you connect to the Particle cloud? With SYSTEM_MODE(MANUAL); it is up to the application to connect to WiFi and the cloud and to then keep the connection alive by regularly giving the connection handler some time by calling Particle.process(); If you haven’t attempted or have not been successful in connecting to the Particle cloud then the while loop will never get executed and hence neither will your function!

2 Likes

You should not keep the code flow trapped in loop() by long running loops like yours.
There are other tasks that may want to be attended to, even when not connected or running MANUAL mode.
A bettwer way is to do it like this

void loop() {
  if (Particle.connected()) {
    connectedJobs();
  }
  else {
    disconnectedJobs();
  }
  Particle.process();
}

Also your active functions should adhere to a non-blocking scheme.

3 Likes

Thank you for the responses. I apologize for late response. So, the function that I want to work is working good while both online and offline. Now, the issue is I can’t flash my code via cloud. I have my SYSTEM in MANUAL mode and have my SYSTEM_THREAD(ENABLED). Does system thread have something to do with not being able to flash the code via cloud? I can flash the code via usb connected through my terminal/ commands windows.

@IsaacG, OTA requires that the Photon be connected to the cloud. In SYSTEM MANUAL mode you would need to make sure the device is online to receive an OTA.

My device is connected to the cloud. The issue is while it’s online, I cannot perform on the air flashing. And also, when I flash it while device is connected to cloud, the web IDE fails to flash successfully and the particle photon start giving out red color SOS signal. Does it harm my device?

@IsaacG, OTA’s are not queued by the cloud unless your Photon is part of a product. Is the device online while you try to flash? If it is and it still fails then your code may be preventing the OTA, especially if you are using other threads or heavy interrupts.

1 Like

@peekay123 My device is online while I try to flash. What kind of behaviors in code would cause preventing the OTA? Basically, I have created two other functions which I call them in my loop. Each function reads sensor value and do an action (turn on or off the leds) accordingly. Also, after I try to flash the code, it fails and my devices start blinking red SOS signal.

@IsaacG, odd. Witht SYSTEM_THREAD(ENABLED) you shouldn’t have issues. Can you post your code?

Hey @peekay123 i’ve sent you a direct message if that’s alright for my code.

1 Like