A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/soft-access-point-class.html below:

Website Navigation


Soft Access Point Class — ESP8266 Arduino Core documentation

Table of Contents Set up Network

This section describes functions to set up and configure ESP8266 in the soft access point (soft-AP) mode.

softAP

Set up a soft access point to establish a Wi-Fi network.

The simplest version (an overload in C++ terms) of this function requires only one parameter and is used to set up an open Wi-Fi network.

To set up pre-shared key protected network, or to configure additional network parameters, use the following overload:

WiFi.softAP(ssid, psk, channel, hidden, max_connection)

The first parameter of this function is required, remaining four are optional.

Meaning of all parameters is as follows:

Function will return true or false depending on result of setting the soft-AP.

Notes:

softAPConfig

Configure the soft access point’s network interface.

softAPConfig (local_ip, gateway, subnet)

All parameters are the type of IPAddress and defined as follows:

Function will return true or false depending on result of changing the configuration.

Example code:

#include <ESP8266WiFi.h>

IPAddress local_IP(192,168,4,22);
IPAddress gateway(192,168,4,9);
IPAddress subnet(255,255,255,0);

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

  Serial.print("Setting soft-AP configuration ... ");
  Serial.println(WiFi.softAPConfig(local_IP, gateway, subnet) ? "Ready" : "Failed!");

  Serial.print("Setting soft-AP ... ");
  Serial.println(WiFi.softAP("ESPsoftAP_01") ? "Ready" : "Failed!");

  Serial.print("Soft-AP IP address = ");
  Serial.println(WiFi.softAPIP());
}

void loop() {}

Example output:

Setting soft-AP configuration ... Ready
Setting soft-AP ... Ready
Soft-AP IP address = 192.168.4.22
Manage Network

Once soft-AP is established you may check the number of stations connected, or shut it down, using the following functions.

softAPgetStationNum

Get the count of the stations that are connected to the soft-AP interface.

WiFi.softAPgetStationNum()

Example code:

Serial.printf("Stations connected to soft-AP = %d\n", WiFi.softAPgetStationNum());

Example output:

Stations connected to soft-AP = 2

Note: the maximum number of stations that may be connected to ESP8266 soft-AP is 4 by default. This can be changed from 0 to 8 via the max_connection argument of the softAP method.

softAPdisconnect

Disconnect stations from the network established by the soft-AP.

WiFi.softAPdisconnect(wifioff)

Function will set currently configured SSID and pre-shared key of the soft-AP to null values. The parameter wifioff is optional. If set to true it will switch the soft-AP mode off.

Function will return true if operation was successful or false if otherwise.

Network Configuration

Functions below provide IP and MAC address of ESP8266’s soft-AP.

softAPIP

Return IP address of the soft access point’s network interface.

Returned value is of IPAddress type.

Example code:

Serial.print("Soft-AP IP address = ");
Serial.println(WiFi.softAPIP());

Example output:

Soft-AP IP address = 192.168.4.1
softAPmacAddress

Return MAC address of soft access point. This function comes in two versions, which differ in type of returned values. First returns a pointer, the second a String.

Pointer to MAC
WiFi.softAPmacAddress(mac)

Function accepts one parameter mac that is a pointer to memory location (an uint8_t array the size of 6 elements) to save the mac address. The same pointer value is returned by the function itself.

Example code:

uint8_t macAddr[6];
WiFi.softAPmacAddress(macAddr);
Serial.printf("MAC address = %02x:%02x:%02x:%02x:%02x:%02x\n", macAddr[0], macAddr[1], macAddr[2], macAddr[3], macAddr[4], macAddr[5]);

Example output:

MAC address = 5e:cf:7f:8b:10:13
MAC as a String

Optionally you can use function without any parameters that returns a String type value.

Example code:

Serial.printf("MAC address = %s\n", WiFi.softAPmacAddress().c_str());

Example output:

MAC address = 5E:CF:7F:8B:10:13

For code samples please refer to separate section with examples dedicated specifically to the Soft Access Point Class.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4