Boron successfully connects only once

Greetings,

I am perplexed by an issue I am having with a relatively simple sketch on my Boron:

#include <google-maps-device-locator.h>

GoogleMapsDeviceLocator locator;
SystemSleepConfiguration config;

void setup() {
}

void loop() {
  locator.publishLocation();
  delay(1001);
  config.mode(SystemSleepMode::ULTRA_LOW_POWER)
      .duration(3min);
    System.sleep(config);
}

This will successfully connect to the cloud and generate a response from the Google Maps API the first time it runs, but when it wakes from sleep, it does not succeed in getting on the cellular network (flashing green). If I add to the end of the sketch:

System.reset(RESET_NO_WAIT);

…then it will successfully complete every three minutes. I feel like I must be missing something basic – what is it?

@rryansilva ,

One thing you have to consider with cellular devices is the frequency you disconnect / reconnect to the network. In your sketch, you will cycle every 3 minutes or so. This may lead to your device getting “black listed” - while unlikely it is good to avoid. Try not to cycle connections less than 10 minutes apart.

Thanks, Chip

This is just for testing of the minimum sketch that demonstrates this behavior. The end use case will get on network no more than once every three hours.

@rryansilva ,

I have used this library with the Boron successfully so we should be able to get you connecting.

What Boron device (BRN402 for example) and what deviceOS release are you using?

Also, have you tried using logging to see what is going on?

Thanks,

Chip

Thanks so much for your reply! This is a BRN310 running 2.2.0. (Yes, I know it won’t be able to get a 3G network soon – that is OK for my use case. I also have a BRN402 that has trouble getting on the network at all, but that’s a separate matter.)

I have tried Cloud Debug, but it does not seem to have any trouble connecting, so I presume the issue is with my code. If I understand correctly, there is no way to run Cloud Debug while running other code, correct?

@rryansilva ,

Thanks for the information. I have a BRN402 but it should work similarly.

As for cloud debug, you can get most of the same information by setting the logging level to “ALL” and using the SerialLogHandler:

SerialLogHandler logHandler(LOG_LEVEL_ALL);        // All the loggings 

or, you can use the default logging level to get less messages.

I modified your code to add logging and inserted a few statements to see what is going on. My device also failed to connect the first time but was successful in the next two attempts. I believe what is going on here is that there is a timeout for the reconnection of about 30 seconds. If your device does not connect in that time, the program execution will progress and your geolocation will not reflect the current state.

I inserted this line into the code just after sleep that fixed the issue:

while(!Particle.connected()) Particle.process();

This works but the cellular modem does not seem to be happy, as it went through a series of resets before finally connecting. The Logs showed this as:

0000200975 [ncp.client] INFO: Using internal SIM card
0000206893 [gsm0710muxer] INFO: Starting GSM07.10 muxer
0000206893 [gsm0710muxer] INFO: Openning mux channel 0
0000206894 [gsm0710muxer] INFO: GSM07.10 muxer thread started
0000206898 [gsm0710muxer] INFO: Openning mux channel 1
0000212258 [gsm0710muxer] INFO: Openning mux channel 2
0000219452 [ncp.client] ERROR: Failed to enter data mode
0000219452 [net.ppp.client] ERROR: Failed to dial
0000219778 [gsm0710muxer] INFO: Stopping GSM07.10 muxer
0000219779 [gsm0710muxer] INFO: Gracefully stopping GSM07.10 muxer
0000219779 [gsm0710muxer] INFO: Closing all muxed channels
0000219780 [gsm0710muxer] INFO: Closing mux channel 1
0000219780 [gsm0710muxer] INFO: Closing mux channel 2
0000219781 [gsm0710muxer] INFO: Muxed channel 3 already closed
0000219782 [gsm0710muxer] INFO: Muxed channel 4 already closed
0000219782 [gsm0710muxer] INFO: GSM07.10 muxer thread exiting
0000219783 [gsm0710muxer] INFO: GSM07.10 muxer stopped
0000219784 [ncp.client] ERROR: Failed to enter data mode
0000219785 [net.ppp.client] ERROR: Failed to dial

That said, if you were going to run this code for a while with sleep of only 3minutes, you need to change your sleep configuration to maintain your connection to the network as described here:

I believe that this may be at the core of your issue, so I changed the sleep configuration and this code works well for me:

 #include <google-maps-device-locator.h>

GoogleMapsDeviceLocator locator;
SystemSleepConfiguration config;

void setup() {
}

void loop() {
  locator.publishLocation();
  delay(1001);
  config.mode(SystemSleepMode::ULTRA_LOW_POWER)
      .duration(3min)
      .network(NETWORK_INTERFACE_CELLULAR, SystemSleepNetworkFlag::INACTIVE_STANDBY);
System.sleep(config);
}

If you start sleeping for longer than 10 minutes, you will not need to keep the network active but, at that point, I would recommend you use additional steps to control connection to the Particle cloud and make sure the modem is shut down gracefully before sleeping - topics for another day.

Let us know how this works for you.

Chip

Thank you so much for having such a thorough look at this.

So you think the issue is due largely to the fact that my testing interval is so short? That when I move to 3 hour intervals the behavior may be different? I had not considered this. Thanks again for your help.

@rryansilva ,

Yes, In my experience, you will want to update your sketch in order to get the lowest power consumption.

  1. You will likely want to change the system mode to semi-automatic or manual.

  2. Then turn threading on

  3. Explicitly connect to and disconnect from Particle

  4. Make sure you have a shut down process that includes explicitly turning off the cellular modem.

You should be able to get things working smoothly with a 3 hour period.

Thanks,

Chip