Skip to content

Instantly share code, notes, and snippets.

@SaimShuja
Created August 26, 2022 06:02
Show Gist options
  • Save SaimShuja/946bc163f379762079618883f6fcecfb to your computer and use it in GitHub Desktop.
Save SaimShuja/946bc163f379762079618883f6fcecfb to your computer and use it in GitHub Desktop.
open custom AP on esp8266 with AP_name, optional password, optional channel number, and option to hide AP
/*open custom ap on esp8266 with AP_name, optional password, optional channel number, and option to hide AP. */
void CreateAP(String NetworkName, String NetworkPassword = emptyString, int channel=1, bool hidden = false)
{
Serial.println("[Name] " + NetworkName);
Serial.println("[Password] " + NetworkPassword);
Serial.println("[channel] " + String(channel));
Serial.println("[hidden] " + String(hidden? "Yes" : "No"));
WiFi.mode(WIFI_AP);
int str_len = NetworkName.length() + 1;
Serial.println("[NetworkName] " + String(str_len));
char ssid[str_len];
NetworkName.toCharArray(ssid, str_len);
str_len = NetworkPassword.length() + 1;
Serial.println("[NetworkPassword] " + String(str_len));
char password[str_len];
NetworkPassword.toCharArray(password, str_len);
delay(2000);
Serial.println("[res] " + String(WiFi.softAP(ssid, password, channel, hidden)));
delay(2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment