Search networks and perform actions based on ones found

I have network names that I know and want the device to do something when it sees these networks I was using this code:

WiFiAccessPoint aps[20];
int found = WiFi.scan(aps, 20);
for (int i=0; i<found; i++) {

    WiFiAccessPoint& ap = aps[i];
    //if(ap.ssid == "FiOS-34K20"){!!!!
    Serial.print("SSID: ");
    Serial.print("Security: ");
    Serial.print("Channel: ");
    Serial.print("RSSI: ");

The part I am interested in I commented out and placed !!! next to, why would this if statement not work what kind of object is “ap.ssid” since this doesn’t work I am assuming it is not a string.

Hi @JDvetinno

The WiFiAccessPoint is a struct with ssid defined as char ssid[33]; so I don’t think that == is the right operator.

Try this instead:

if (0==strcmp(ap.ssid,"FiOS-34K20")) {

Thanks for the help! I will need to brush up on structures again, I have been dealing with python for too long lol!

This code as it is does throw the error “I Value required as left operand of assignment” just a heads up.

OK darn type on my code. You need a double equals there. Corrected!

1 Like

Yea that’s it now I understand that error a lot better also so something learned!

This is also a good example for the C/C++ practice @bko showed here to place the constant on the left side of the equality operator.
If you should happen to use the assignment operator (=) instead of equality (==) you will get a compiletime error and not a successful build producing a program that will behave in an unexpected manner.