ESP32 WiFi Library – WiFi.softAPSubnetMask

Home / References / ESP32 Library / WiFi API / AP

Description

The softAPSubnetMask method is used to retrieve the subnet mask of the ESP32’s soft Access Point (AP). This method is part of the ESP32 WiFi Library and is essential for managing and configuring the network settings of the soft AP.


Syntax and Usage

The softAPSubnetMask method is used to get the subnet mask of the soft AP. It does not require any arguments.

IPAddress softAPSubnetMask();

Argument(s)

This method does not require any arguments.


Return Value

The softAPSubnetMask method returns the subnet mask of the soft AP in IPAddress format.


Example Codes

Example 1: Retrieving the Soft AP Subnet Mask

This code demonstrates how to use the softAPSubnetMask() method from the ESP32 AP Class to retrieve the subnet mask of a soft access point. It sets up an ESP32 as a Wi-Fi hotspot and prints the subnet mask to the serial monitor.

To use this code, upload it to your ESP32 board and open the Serial Monitor at 115200 baud. Ensure your ESP32 is properly connected, and observe the output to see the subnet mask of the configured soft AP.

/*
 * Author: Avant Maker
 * Date: February 14, 2025
 * Version: 1.0
 * Description: This example code demonstrates how to use 
 * softAPSubnetMask to retrieve and print the subnet mask of 
 * ESP32 soft AP.
 *
 * License: MIT 
 * 
 * Code Source: This example code is sourced from the Comprehensive 
 * Guide to the ESP32 Arduino Core Library, accessible on 
 * AvantMaker.com. For additional code examples and in-depth 
 * documentation related to the ESP32 Arduino Core Library, 
 * please visit:
 *
 * https://avantmaker.com/references/esp32-arduino-core-index/
 *
 * AvantMaker.com, your premier destination for all things 
 * DIY, AI, IoT, Smart Home, and STEM projects. We are dedicated 
 * to empowering makers,learners, and enthusiasts with the resources
 *  they need to bring their innovative ideas to life.
 */

#include <WiFi.h>

void setup() {
    Serial.begin(115200);

    // Configure the soft AP
    if (WiFi.softAP("AvantMaker-ESP32-AP", "12345678")) {
        Serial.println("Soft AP started");
    } else {
        Serial.println("Soft AP failed to start");
    }

    // Get and print the subnet mask
    IPAddress subnetMask = WiFi.softAPSubnetMask();
    Serial.print("Soft AP Subnet Mask: ");
    Serial.println(subnetMask);
}

void loop() {
    // Do nothing
}

AvantMaker Tutorial Suggestion

If you want to learn more about the ESP32’s WiFi capabilities, we’ve created a beginner-friendly guide that explains them in detail. Just click the link below, and you’ll be teleported to that page. It will clear up any confusion you may have while connecting your ESP32 to WiFi or setting it up as a WiFi access point (AP).

ESP32 Essential Guide – Network Section – WiFi Chapter

ESP32 Library Index

ESP32 Arduino Core Library


FAQ

Ready to experiment and explore more about ESP32? Visit our website’s All About ESP32 Resources Hub, packed with tutorials, guides, and tools to inspire your maker journey. Experiment, explore, and elevate your skills with everything you need to master this powerful microcontroller platform!

error: Content is protected !!