[GH-ISSUE #230] Using library within class #191

Closed
opened 2026-02-28 01:23:55 +03:00 by kerem · 1 comment
Owner

Originally created by @vman26 on GitHub (Sep 30, 2016).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/230

Hi,

I'm trying to use the library within a class,

The problem is I can't use the setAPCallback witin my class:
no matching function for call to 'WiFiManager::setAPCallback()'

I use:
wifiManager.setAPCallback(configModeCallback);

I have a class named:
WifiControl

this is the decleration in the header:
void configModeCallback (WiFiManager *myWiFiManager);

and the cpp:

void WifiControl::configModeCallback (WiFiManager *myWiFiManager) {
  Serial.println("Entered config mode");
  Serial.println(WiFi.softAPIP());
  //if you used auto generated SSID, print it
  Serial.println(myWiFiManager->getConfigPortalSSID());
  //entered config mode, make led toggle faster
  ticker.attach(0.2, tick);
}

I can't figure out how to fix it, any help out there?

Originally created by @vman26 on GitHub (Sep 30, 2016). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/230 Hi, I'm trying to use the library within a class, The problem is I can't use the setAPCallback witin my class: no matching function for call to 'WiFiManager::setAPCallback(<unresolved overloaded function type>)' I use: wifiManager.setAPCallback(configModeCallback); I have a class named: `WifiControl` this is the decleration in the header: `void configModeCallback (WiFiManager *myWiFiManager);` and the cpp: ``` void WifiControl::configModeCallback (WiFiManager *myWiFiManager) { Serial.println("Entered config mode"); Serial.println(WiFi.softAPIP()); //if you used auto generated SSID, print it Serial.println(myWiFiManager->getConfigPortalSSID()); //entered config mode, make led toggle faster ticker.attach(0.2, tick); } ``` I can't figure out how to fix it, any help out there?
kerem closed this issue 2026-02-28 01:23:56 +03:00
Author
Owner

@kluzzebass commented on GitHub (Jan 25, 2017):

Because of the way the callbacks are designed in WiFiManager, it's not possible to use class functions (static or otherwise) as callback functions; they simply have to be globally declared functions.

In most cases the required functionality could be solved by simply using boolean flags in the WiFiManager class instead of being clever and using callbacks.

The consequence is that the WiFiManager class cannot readily be used inside another class if you plan on using the callbacks.

<!-- gh-comment-id:275204011 --> @kluzzebass commented on GitHub (Jan 25, 2017): Because of the way the callbacks are designed in WiFiManager, it's not possible to use class functions (static or otherwise) as callback functions; they simply have to be globally declared functions. In most cases the required functionality could be solved by simply using boolean flags in the WiFiManager class instead of being clever and using callbacks. The consequence is that the WiFiManager class cannot readily be used inside another class if you plan on using the callbacks.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#191
No description provided.