Thursday, March 24, 2016

NodeMCU exercise: get my IP address

NodeMCU (ESP8266) + ESP8266 core for Arduino example to get my IP address after connected to WiFi.


#include <ESP8266WiFi.h>

const char* ssid = "your WiFi ssid";
const char* password = "xxxxxxxx";
byte mac[6];

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

  Serial.print("\nStart...\n");
  WiFi.macAddress(mac);
  Serial.print("MAC: ");
  Serial.print(mac[0],HEX);
  Serial.print(":");
  Serial.print(mac[1],HEX);
  Serial.print(":");
  Serial.print(mac[2],HEX);
  Serial.print(":");
  Serial.print(mac[3],HEX);
  Serial.print(":");
  Serial.print(mac[4],HEX);
  Serial.print(":");
  Serial.println(mac[5],HEX);
  Serial.println();
  
  WiFi.begin(ssid, password);
  Serial.print("Connecting WIFI ");
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
 
  Serial.println("");
  Serial.println("connected");  
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  // put your main code here, to run repeatedly:

}

3 comments:

  1. Good example.Simple but useful.I`ve been stuck in ESP8266 to ESP8266 communication for a long time, Expect your further development can enlighten me.

    ReplyDelete
  2. thx for this useful code. I already got the ip address, but I cant access it to send or receive data from the web.
    Appreciate ur help :)

    ReplyDelete
  3. thank for example. I can got the ip address.

    ReplyDelete