-1

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
gre_gor
  • 6,669
  • 9
  • 47
  • 52
user1213320
  • 650
  • 1
  • 6
  • 13

1 Answers1

2

If you want to use ap2 String object, you need to use it's char array with const casting like :

wifiManager.autoConnect((const char*)ap2.c_str());

I did not understand why you're using dynamic allocated macStr, ap2's char array will be enough to handle it. Despite that, still if you want to use it, try like :

wifiManager.autoConnect((const char*)macStr);

Good luck!

cagdas
  • 1,634
  • 2
  • 14
  • 27
  • WORKS NOW. wifiManager.autoConnect((const char*)ap2.c_str()); did the trick. I have still got to find a really good ref on the different data types and conversion. – user1213320 Oct 15 '16 at 20:14