-
-
Save kasperkamperman/d63a781b4832e909b29c1f74968004dc to your computer and use it in GitHub Desktop.
Question related to WiFi.scan callback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WiFiManager { | |
public: | |
boolean isWiFiDirectFlag = false; | |
boolean isNoWiFiFlag = false; | |
boolean isWiFiDirectRunningFor60Seconds = false; | |
// global because accessible from wifi_scan_callback and isStoredSSIDAvailable functions. | |
// we always set this, because maybe on the road WAPs will be added (without a reset) | |
WiFiAccessPoint storedWAPs[5]; | |
int storedWAPsAmount = 0; | |
bool isStoredSSIDFound = false; | |
//enum WiFiManagerState { RSSIINDICATORSTATE_CHECK, RSSIINDICATORSTATE_ON, RSSIINDICATORSTATE_ON_WAIT, RSSIINDICATORSTATE_OFF_WAIT, RSSIINDICATORSTATE_CHECK_WAIT }; | |
WiFiManager(); | |
virtual ~WiFiManager(); | |
void setup(); | |
void loop(); | |
void wifi_scan_callback(WiFiAccessPoint*, void*); | |
bool isStoredSSIDAvailable(); | |
//private: | |
}; | |
// end class initialisation | |
WiFiManager::WiFiManager() { | |
} | |
WiFiManager::~WiFiManager() { | |
}// | |
void WiFiManager::setup() { | |
Serial.println("hi"); | |
} | |
void WiFiManager::loop() { | |
//delay(1000); | |
} | |
void WiFiManager::wifi_scan_callback(WiFiAccessPoint* wap, void* data) | |
{ | |
WiFiAccessPoint& ap = *wap; | |
for (int i = 0; i < storedWAPsAmount; i++){ | |
if (strcmp(ap.ssid, storedWAPs[i].ssid) == 0) { | |
isStoredSSIDFound = true; | |
Serial.print("SSID: "); | |
Serial.println(ap.ssid); | |
Serial.print("Security: "); | |
Serial.println(ap.security); | |
Serial.print("Channel: "); | |
Serial.println(ap.channel); | |
Serial.print("RSSI: "); | |
Serial.println(ap.rssi); | |
} | |
} | |
} | |
bool WiFiManager::isStoredSSIDAvailable() { | |
// in the callback we compare scanned WAPs with the stored WAPs | |
// storedSSIDFound will be set to true if we have a match | |
// this is global so we can access this after a call to this function | |
isStoredSSIDFound = false; | |
//WiFi.scan(&WiFiManager::wifi_scan_callback); | |
WiFi.scan(&wifi_scan_callback); | |
return isStoredSSIDFound; | |
//int scannedWAPsAmount = | |
//Serial.print(scannedWAPsAmount); | |
//Serial.println(" APs scanned and compared."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment