Problem with connectivity and sampling with system mode manual

I tried finding an answer, but it eluded me. So I’ve set my system to SYSTEM_MODE(MANUAL) as I need to perform some Timer functions as well. I’m trying to keep the Particle.process as far a part as possible and the documentation said 20s should be fine so I chose 19s. But I’m still seeing that the first timer is not being sampled as I thought but there’s a few mS in between. Also I can’t get it to flash with these settings.

#include "SparkIntervalTimer/SparkIntervalTimer.h"
#include "math.h"
#include "application.h"
//if this is defined then serial will work
#define SERIALout
SYSTEM_MODE(MANUAL);	//Just to have the blink start immediately
unsigned long interval=19000; 
IntervalTimer myTimer;
void setup() {
  // this is 8 * 512 samples, just reads ADC
  myTimer.begin(getData, 244, uSec);
  #ifdef SERIALout
  #ifdef setKertsiWifi
    if(!(WiFi.hasCredentials())) {
      WiFi.setCredentials("XXXXXXX", "XXXXXXX");
  //this one is defined
  #ifdef testHomeWifi
      WiFi.setCredentials("XXXXXX", "XXXXXX");
  //Particle.publish("biletappi", passData);
  //begin the measurements
  if (!Particle.connected()) {
void loop() {
  //check if 19 seconds have passed and it is time to read the sensor
  unsigned long currentMillis = millis(); // grab current time
  // check if "interval" time has passed
  //Serial.println(currentMillis - previousMillis);
  if (unsigned long)(currentMillis - previousMillis) >= interval) {
    blockingCheck = true;
    if (Particle.connected()) {
    } else {
    //save the "current" time
    previousMillis = millis();
  #ifdef SERIALout    
  passData = " TEST: " + String(outputTester) + " TEST2: " + String(outputTester2) + " no: "+outputter;
void getData() {
  outputTester2 = micros();
  // ... everything else is commented out

I did look at this:

I’m missing something.

Is this a copy-past of your original code with some alterations?
There are some errors with the parentheses and curly braces.

I can’t see the declaration outputTester2 - is it set volatile?

What’s the reason that you keep clearing credentials? The device can store several sets of credentials at a time.

To keep the cloud connection alive, you should call Particle.process() at least once per 10 seconds. But it will still not be very responsive for Particle.variable() retrieval and definetly too little for reliable OTA flashing.

I’d also think that the IntervalTimer interrupts are relatively low priority, so missing some during connection seems possible.

1 Like

Thanks for the info, I could do the Processing possibly every 5 seconds after I’m done with the heavy lifting.

No I hadn’t set outputTester2 to volatile, I’ll try that.

Credential clearing was for the purpose of testing, I’m sending this device away where I can’t get to it for months so I’m going to put a few different credentials on it, which are going to different from my wifi. I think the reference says 5 credentials for photon.