Skip to content

Instantly share code, notes, and snippets.

@kasperkamperman
Created July 14, 2016 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasperkamperman/ba5ff1dbc8b3a2840718bde502131ae8 to your computer and use it in GitHub Desktop.
Save kasperkamperman/ba5ff1dbc8b3a2840718bde502131ae8 to your computer and use it in GitHub Desktop.
other attempt
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();
private:
static void handle_ap(WiFiAccessPoint* wap, WiFiManager* self);
void next(WiFiAccessPoint& ap);
bool isStoredSSIDAvailable();
};
// end class initialisation
WiFiManager::WiFiManager() {
}
WiFiManager::~WiFiManager() {
}//
void WiFiManager::setup() {
Serial.println("hi");
}
void WiFiManager::loop() {
//delay(1000);
bool check = isStoredSSIDAvailable();
if(check) Serial.println("checked");
delay(1000);
}
// This is the callback passed to WiFi.scan()
// It makes the call on the `self` instance - to go from a static
// member function to an instance member function.
void WiFiManager::handle_ap(WiFiAccessPoint* wap, WiFiManager* self)
{
self->next(*wap);
}
void WiFiManager::next(WiFiAccessPoint& ap)
{
Serial.print("SSID: ");
Serial.println(ap.ssid);
// if ((ap.rssi < 0) && (ap.rssi > strongest_rssi)) {
// strongest_rssi = ap.rssi;
// strcpy(strongest_ssid, ap.ssid);
// }
}
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(handle_ap, this);
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