RSSI code snippet not working

I found the following code snippet, but when I add it to my code, I get an error “Signal is ambiguous”. Not sure what’s wrong…


char* levels[6] = {"Poor", "Low", "Medium", "Good", "Very Good", "Great"};
char Signal[17];   // Used to communicate Wireless RSSI and Description


int getWiFiStrength()               
{
    int wifiRSSI = WiFi.RSSI();
    if (wifiRSSI > 0) {
        sprintf(Signal, "Error");
    }else {
        int strength = map(wifiRSSI, -127, -1, 0, 5);
        sprintf(Signal, "%s: %d", levels[strength], wifiRSSI);
    }
    return 1;
}

What device, what deviceOS are you using? (please always add as much detail as possible. There’s no such thing as too much information)

1 Like

See parallel discussion here

Fragmenting one overarching/common question into multiple threads isn't best practice.

However, when you use Web IDE, you should click the SHOW RAW button to see more background info about the error message.
Ambiguity errors usually are caused by multiple use of the same name for different purposes and the first step to remedy such an issue is to try renaming the offending variable.

Thanks. I will continue this issue in this thread. The other thread was started regarding wifi going offline.

I have this code, but still can’t figure out how to write the sprintf line :frowning:

int rssi = 0;
char data[16];

void wifi_status() {    
    rssi = WiFi.RSSI();
    snprintf( //I can't figure out the syntax of this line
    Particle.publish("rssi", data, PRIVATE);
    Blynk.virtualWrite(V50, rssi);
}

In my setup I have:

    Particle.variable("RSSI", &rssi, INT);
1 Like

OK, then you may want to read up on printf() first.
This will provide you with the basics of formatting strings

Once that has become clear you can apply that insight to snprintf() where s stands for Storage and n for max Number of characters.

Armed with that insight you will be able to interpret how and why the code above does what it does and can solve your immediate question and will also be able to re-apply that insight over and over of further questions that may arise.

BTW, about this

this is the old syntax.
The modern version would be this

  Particle.variable("RSSI", rssi);

I believe the reason Signal is ambiguous is that there’s a class named Signal.

Renaming the global variable and every it’s used to signal (lower-case) should solve that problem. Or to be even safer, “mySignal” or something like that.

1 Like