ESP8266 IP to String Conversion

Converting ESP8266 IP address to string or character array. There is simple way to convert IP address to string is using toString() function.

WiFi.localIP().toString();

IP address to string

What is IP Address?

An Internet Protocol address (IP address) is a numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication. An IP address serves two principal functions: host or network interface identification and location addressing.

What is MAC Address?

A media access control address (MAC address) of a device is a unique identifier assigned to a network interface controller (NIC). For communications within a network segment, it is used as a network address for most IEEE 802 network technologies, including Ethernet, Wi-Fi, and Bluetooth.

How do you find your IP address of ESP8266?

You can get IP address of ESP8266 using WiFi.localIP(); when esp is connected to WiFi Router.

When ESP8266 is in access point mode then ESP has default IP address 192.168.4.1 .

Arduino ESP8266 Example for IP address conversion

The code to connect to a wireless access point is relatively straightforward: enter the SSID and the password of the network you want to connect to

/*
 * https://circuits4you.com
 * 
 * Connecting NodeMCU ESP8266 to WiFi and
 * Get IP address to String
 */
 
#include <ESP8266WiFi.h>        // Include the Wi-Fi library

const char* ssid     = "SSID";         // The SSID (name) of the Wi-Fi network you want to connect to
const char* password = "PASSWORD";     // The password of the Wi-Fi network
String IPaddress;
void setup() {
  Serial.begin(115200);         // Start the Serial communication to send messages to the computer
  delay(10);
  Serial.println('\n');
  
  WiFi.begin(ssid, password);             // Connect to the network
  Serial.print("Connecting to ");
  Serial.print(ssid);

  while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
    delay(500);
    Serial.print('.');
  }

  Serial.println('\n');
  Serial.println("Connection established!");  
  Serial.print("IP address:\t");
  Serial.println(WiFi.localIP());         // Send the IP address of the ESP8266 to the computer
  IPaddress =  WiFi.localIP().toString();
}

void loop() { 
  
}

Results

More about IP address

 

Leave a Reply