[GH-ISSUE #238] set SSID in autoConnect() with name+MAC #197

Closed
opened 2026-02-28 01:23:57 +03:00 by kerem · 3 comments
Owner

Originally created by @mickeypop on GitHub (Oct 14, 2016).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/238

I am trying to get my Wemos D1 mini to set the AP name to Stand + the MAC address minus the semicolons, like Stand5CCF7F238734.

The GetMyMacAddress() function i wrote is clearly working, the serial out shows that.

Every time I try to pass a String or char variable to wifiManager.autoConnect() I get compiler errors. Even though the header file identifies String type the C file say const char.

if i pass macStr or *macStr (char type)
   invalid conversion from 'char' to 'const char' [-fpermissive]*

if i pass ap2 (String type) i get:
   no matching function for call to 'WiFiManager::autoConnect(String&)'

My code;

#include `<ESP8266WiFi.h>` 
#include `<DNSServer.h>`
#include `<ESP8266WebServer.h>`
#include `<WiFiManager.h>` 

String ap = "Stand";
String ap2;
uint8_t mac[6];
char const macStr[19] = {0};

void setup() {
    Serial.begin(115200);
    WiFiManager wifiManager; 

    ap2 = ap + GetMyMacAddress();

    //std::string ap2;  // tried but more errors
    char *macStr = new char[ap2.length()+ 1 ];
    strcpy(macStr, ap2.c_str());

    wifiManager.autoConnect( "Stand" );       // works but not what i want
    //wifiManager.autoConnect( ap2 );         // cannot pass var to set SSID ???
    //wifiManager.autoConnect( *macStr );  // cannot pass var to set SSID ???
    //wifiManager.autoConnect( macStr );    // cannot pass var to set SSID ???

    Serial.println("connected...yeey :)");
    Serial.print("ap2"); Serial.print("    " ); Serial.print( ap2); Serial.println(" String");
    Serial.print("macStr"); Serial.print(" "); Serial.print( macStr ); Serial.println(" Char");
}

void loop() {   }

String GetMyMacAddress()
{   uint8_t mac[6];
    char macStr[18] = {0};
    WiFi.macAddress(mac);
    sprintf(macStr, "%02X%02X%02X%02X%02X%02X", mac[0],  mac[1], mac[2], mac[3], mac[4], mac[5]);
    return  String(macStr);
}

Serial out Returns: when connected
   connected...yeey :)
   ap2     Stand5CCF7F238734 String
   macStr Stand5CCF7F238734 Char

How can i pass the ap2 or macStr to set the AP SSID name?

Originally created by @mickeypop on GitHub (Oct 14, 2016). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/238 I am trying to get my Wemos D1 mini to set the AP name to Stand + the MAC address minus the semicolons, like **Stand5CCF7F238734**. The GetMyMacAddress() function i wrote is clearly working, the serial out shows that. Every time I try to pass a String or char variable to wifiManager.autoConnect() I get compiler errors. Even though the header file identifies String type the C file say const char. if i pass macStr or `*`macStr (char type) &nbsp;&nbsp;&nbsp;**invalid conversion from 'char' to 'const char*' [-fpermissive]** if i pass ap2 (String type) i get: &nbsp;&nbsp;&nbsp;**no matching function for call to 'WiFiManager::autoConnect(String&)'** My code; ``` #include `<ESP8266WiFi.h>` #include `<DNSServer.h>` #include `<ESP8266WebServer.h>` #include `<WiFiManager.h>` String ap = "Stand"; String ap2; uint8_t mac[6]; char const macStr[19] = {0}; void setup() { Serial.begin(115200); WiFiManager wifiManager; ap2 = ap + GetMyMacAddress(); //std::string ap2; // tried but more errors char *macStr = new char[ap2.length()+ 1 ]; strcpy(macStr, ap2.c_str()); wifiManager.autoConnect( "Stand" ); // works but not what i want //wifiManager.autoConnect( ap2 ); // cannot pass var to set SSID ??? //wifiManager.autoConnect( *macStr ); // cannot pass var to set SSID ??? //wifiManager.autoConnect( macStr ); // cannot pass var to set SSID ??? Serial.println("connected...yeey :)"); Serial.print("ap2"); Serial.print(" " ); Serial.print( ap2); Serial.println(" String"); Serial.print("macStr"); Serial.print(" "); Serial.print( macStr ); Serial.println(" Char"); } void loop() { } String GetMyMacAddress() { uint8_t mac[6]; char macStr[18] = {0}; WiFi.macAddress(mac); sprintf(macStr, "%02X%02X%02X%02X%02X%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); return String(macStr); } ``` Serial out Returns: when connected &nbsp;&nbsp; connected...yeey :) &nbsp;&nbsp; ap2 &nbsp;&nbsp;&nbsp; Stand5CCF7F238734 String &nbsp;&nbsp; macStr Stand5CCF7F238734 Char How can i pass the ap2 or macStr to set the AP SSID name?
kerem closed this issue 2026-02-28 01:23:58 +03:00
Author
Owner

@kentaylor commented on GitHub (Oct 16, 2016):

This line and the following creates a string variable and calls autoconnect successfully so you could copy that construct. It is odd that the value of a const is changed but it is possible.

I'd recommend against using autoconnect for these reasons. If you are happy with using the ChipID rather than the MAC address as your variable in the AP name then this library already does that without modification.

<!-- gh-comment-id:254066272 --> @kentaylor commented on GitHub (Oct 16, 2016): This [line](https://github.com/tzapu/WiFiManager/blob/fd15f986d3ab5831c543aadbd5cb07805f7b5c9f/WiFiManager.cpp#L127) and the following creates a string variable and calls autoconnect successfully so you could copy that construct. It is odd that the value of a const is changed but it is [possible](https://en.wikipedia.org/wiki/Const_%28computer_programming%29#Consequences). I'd recommend against using autoconnect for these [reasons](https://github.com/kentaylor/WiFiManager#configuration-portal-initiation-not-automatic). If you are happy with using the ChipID rather than the MAC address as your variable in the AP name then [this library](https://github.com/kentaylor/WiFiManager) already does that without modification.
Author
Owner

@tzapu commented on GitHub (Oct 17, 2016):

Hi, try with wifiManager.autoConnect( ap2.c_str() );

Does that work?
Cheers

<!-- gh-comment-id:254164364 --> @tzapu commented on GitHub (Oct 17, 2016): Hi, try with `wifiManager.autoConnect( ap2.c_str() );` Does that work? Cheers
Author
Owner

@mickeypop commented on GitHub (Oct 17, 2016):

wifiManager.autoConnect( ap2.c_str() ); got it working.
i was not aware of the .c_str() operator is has been a while since i needed and string minipulation.

Time to bone up i guess.

<!-- gh-comment-id:254305135 --> @mickeypop commented on GitHub (Oct 17, 2016): wifiManager.autoConnect( ap2.c_str() ); got it working. i was not aware of the .c_str() operator is has been a while since i needed and string minipulation. Time to bone up i guess.
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#197
No description provided.