I am trying to get my ESP8266 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 output 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.
If I pass macStr
or *macStr
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; //WiFiManager -- Local intialization.
ap2 = ap + GetMyMacAddress();
//std::string ap2;
char *macStr = new char[ap2.length()+ 1 ];
strcpy(macStr, ap2.c_str());
//fetches ssid and pass from eeprom and tries to connect
//if connect fails it starts an access point with the specified name
//here "AutoConnectAP" and goes into a loop awaiting configuration
wifiManager.autoConnect( "Stand" );
//or use this for auto generated name ESP + ChipID
//wifiManager.autoConnect();
//if you get here you have connected to the WiFi
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]); // no :'s
// sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); // with :'s
return String(macStr);
}
When connected, the serial outputs:
connected...yeey :)
ap2 Stand5CCF7F238734 String
macStr Stand5CCF7F238734 Char