Boron getStrength and getQuality

Currently my code checks the signal strength and quality every 10 minutes and passes it on to a cloud variable, which is working fine.
CellularSignal sig = Cellular.RSSI();
float strength = sig.getStrength();
float quality = sig.getQuality();
The caveat here is that when the Boron boots up, I have to wait 10 minutes before that data is available. Any suggestions on how to have it available right after the Boron connects to the cloud? From what is in the documentation it looks like the getStrength and getQuality can be blocked for an indeterminate amount of time while the system thread is busy trying to reconnect to cellular so making the call more frequently doesn’t seem to be a good idea.
Any suggestions greatly appreciated!

You should be able to make the first call after Cellular.ready() returns true, however I’d wait until Particle.connected() plus about 10 more seconds.

Additionally, I’d also make the call to Cellular.RSSI() from a worker thread instead of from the loop thread, because it can block if the system thread is using the cellular modem already.

This library handles background publish which is a different blocking problem, but you can use the same technique to run the RSSI in the background.

In some cases you will want two threads, one for publish and one for RSSI, or sometimes you can do both in a single thread.

Thanks @rickkas7 I’ll give it a try.

Sorry still trying to learn this stuff, work this be ok? Also, by “worker thread” do you mean creating a Thread thread(“testThread”, threadFunction) or just moving it outside of the loop function?

SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);

const unsigned long interval = 10000; // wait 10 seconds after Particle.connected
double strength;
double quality;
bool initialCellCheck = false;
bool waitingForCell = false;
unsigned long waitingMillis;

void setup()
{
  Particle.variable("CellStrength", strength);
  Particle.variable("CellQuality", quality);
  Particle.connect();
}

void loop()
{
  if (initialCellCheck == false)
  {

    if (Cellular.ready() == true)
    {
      if (Particle.connected && waitingForCell == false)
      {
        waitingMillis = millis();
        waitingForCell = true;
      }
      unsigned long currentMillis = millis();
      if (currentMillis - waitingMillis >= interval)
      {
        system_display_rssi();
        initialCellCheck = true;
      }
    }
  }
}

void system_display_rssi()
{
  CellularSignal sig = Cellular.RSSI();
  strength = sig.getStrength();
  quality = sig.getQuality();
}

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.