ESP8266에서 AP 이름을 Stand
으로 설정하고 MAC 주소에서 세미콜론을 뺀 값을 Stand5CCF7F238734
으로 설정하려고합니다.변수를 wifiManager.autoConnect()에 전달하여 AP 이름 지정
필자가 작성한 GetMyMacAddress()
기능은 분명히 작동하고 있으며, 직렬 출력이이를 보여줍니다.
wifiManager.autoConnect()
에 String 또는 char 변수를 전달할 때마다 컴파일러 오류가 발생합니다. 헤더 파일이 String 유형을 식별하더라도. 내가 ap2
(문자열 유형)를 전달하면
내가 macStr
또는 *macStr
'const를 숯불 *'에서 '문자'에서
잘못된 변환을 전달하는 경우 [-fpermissive]
내가 얻을 :
'WiFiManager :: autoConnect (String &)'에 대한 일치 기능이 없습니다.
,
내 코드 :
#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);
}
연결, 직렬 출력 : 당신이 AP2 String 객체를 사용하려는 경우, 당신이 const를 주조 등으로 문자 배열의 사용해야
connected...yeey :)
ap2 Stand5CCF7F238734 String
macStr Stand5CCF7F238734 Char
'wifiManager.autoConnect (ap2.c_str(), NULL);은 어떨까요? –