Skip to content

Instantly share code, notes, and snippets.

@lonelybinary
Created June 18, 2023 00:51
Show Gist options
  • Save lonelybinary/4a780f5b4c4f3d8105685a65e10fa01a to your computer and use it in GitHub Desktop.
Save lonelybinary/4a780f5b4c4f3d8105685a65e10fa01a to your computer and use it in GitHub Desktop.
Arduino ESP32 WIFI - Soft Access Point
// Soft AP DHCP Server is enabled by default.
#include <WiFi.h>
#include <WiFiAP.h>
/*
Please provide the definition for the Soft AP SSID and Password.
The password should consist of at least 8 characters.
Alternatively, if no password is specified, the network will be open.
*/
const char *ssid = "lonelybinary";
const char *password = "password";
// Manual IP Configuration for Soft AP
IPAddress AP_LOCAL_IP(192, 168, 1, 1);
IPAddress AP_GATEWAY_IP(192, 168, 1, 254);
IPAddress AP_NETWORK_MASK(255, 255, 255, 0);
void setup()
{
Serial.begin(115200);
Serial.println("Configuring access point...");
WiFi.softAPConfig(AP_LOCAL_IP, AP_GATEWAY_IP, AP_NETWORK_MASK);
WiFi.softAPsetHostname("lonelybinary");
// To initiate the Soft AP, pause the program if the initialization process encounters an error.
if (!WiFi.softAP(ssid, password))
{
Serial.println("Soft AP creation failed.");
while (1);
}
Serial.print("AP Name SSID: ");
Serial.println(WiFi.softAPSSID());
Serial.print("AP IP Address: ");
Serial.println(WiFi.softAPIP());
Serial.print("AP Hostname: ");
Serial.println(WiFi.softAPgetHostname());
Serial.print("AP Mac Address: ");
Serial.println(WiFi.softAPmacAddress());
Serial.print("AP Subnet: ");
Serial.println(WiFi.softAPSubnetCIDR());
}
void loop()
{
Serial.print("Num of Connected Clients : ");
Serial.println(WiFi.softAPgetStationNum());
delay(5000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment