Improving Electron Connection Success Rate

All, I have a bunch of Electrons which are solar powered so, they spend most of the day napping with the Cellular radio off to save power. Once an hour, they wake and connect to send the hour’s data. Based on the number of devices and the number of hours during their workday, I am getting about 99.25% success rate. Thing is that I would like to get better if I could as even this rate causes about 3 alerts a day.

The full code can be found here: https://github.com/chipmc/Cellular-Pressure

But, the commands I use to connect are:

      Cellular.on();  // Turn on the radio
      Particle.connect(); // Start the connection process
      waitFor(Particle.connected,60000);   // Give us up to 60 seconds to connect
      Particle.process(); // Process just in case

Since the connection process is blocking, I am not sure I want my device unresponsive to counts for more than 60 seconds.

I have looked at @rickkas7’s excellent electronsample code but, the connection code does not like the fact that my device sleeps most of the hour and I get a lot of resets.

Any suggestions for improvement? 1-2 less alerts a day would be nice and as the number of devices grows, it could become 10-20.

Thanks,

Chip

Since you are counting in an ISR the blocking wait wouldn’t cause you to miss any triggers.

When you check the return value of waitFor() you can do things from time to time but still carry on waiting after these actions
e.g. like this

  // wait for *up to* 5 minutes
  for (int retry = 0; retry < 5 && !waitFor(Particle.connected,60000); retry++) {
    // do important stuff at least once a minute
  }

@ScruffR,

Great idea and you are correct, my ISR will register the counts but will need to service the interrupt flag. would this work?

  // wait for *up to* 5 minutes
  for (int retry = 0; retry < 30 && !waitFor(Particle.connected,10000); retry++) {
    if(intFlag) recordCount(); // service the interrupt every 10 seconds
  }

Also, is there any other factor other than the length of time allowed for connecting that can improve the odds of success?

Thanks,

Chip

I’d use a numeric value and increment that in the ISR to make sure you won’t miss any of potentially multiple counts during the 10sec period.
In your recordCount() function you can then roll-up all counts at once.

Other then that, this looks as if it should work.

1 Like