Getting 0 and -1 from CellularSignal

I’m trying to return the cellular signal strength of my Boron using CellularSignal, but I’m getting “-1” reading from .getStrength and .getQuality and I’m getting “0” reading from getStrengthValue and getQualityValue no matter where I place my device (inside or outside).

Code snippets:

CellularSignal sig = Cellular.RSSI();

double getStrength = 0;
double getQuality = 0;
double getStrengthValue = 0;
double getQualityValue = 0;

getStrength = sig.getStrength();
getQuality = sig.getQuality();
getStrengthValue = sig.getStrengthValue();
getQualityValue = sig.getQualityValue();

Particle.variable(“getStrength”, getStrength);
Particle.variable(“getQuality”, getQuality);
Particle.variable(“getStrengthValue”, getStrengthValue);
Particle.variable(“getQualityValue”, getQualityValue);

2020-12-28_13-38-36

Any help?

How often are you executing this code?
Particle.variable() is only ever called once for each individual variable - not each time the value of the variable changes.

The variables that you register with Particle.variable() need to be global too (or you provide a function that “calculates” the value on the fly) - but local variables are no good.

/*

  • CellularSignal Test
  • Description:
  • Author:
  • Date:
    */

CellularSignal sig = Cellular.RSSI();

double getStrength = 0;
double getQuality = 0;
double getStrengthValue = 0;
double getQualityValue = 0;

void setup() {

Particle.variable(“getStrength”, getStrength);
Particle.variable(“getQuality”, getQuality);
Particle.variable(“getStrengthValue”, getStrengthValue);
Particle.variable(“getQualityValue”, getQualityValue);

}

void loop() {
getStrength = sig.getStrength();
getQuality = sig.getQuality();
getStrengthValue = sig.getStrengthValue();
getQualityValue = sig.getQualityValue();
}

The problem is that CellularSignal is a container that holds the strength and quality values returned from Cellular.RSSI(). Since this is a global variable in your code, the values are retrieved only once, at global object construction, when the cellular connection is not up yet, so there are no strength values. You need to make this a local variable in loop, not a global.

CellularSignal sig = Cellular.RSSI();

That worked! Thank you so much!