2

enter image description here

This is the Serial of my arduino it doesn't show anything what am I doing wrong in my code? Arduino Code

#include <SoftwareSerial.h>
    #include <ESP8266WiFi.h>
    #include <WiFiClient.h> 
    #include <ESP8266WebServer.h>

    const char* host = "WiFi_Robot4_NodeMCU";
    const char* ssid = "EarthQuakeBot";

    ESP8266WebServer server(80);

    void setup() {
      IPAddress ip;  
      Serial.begin(115200);
       ip = WiFi.localIP();
      Serial.println(ip);
    delay(100);
    // Connecting WiFi

      WiFi.mode(WIFI_AP);
      WiFi.softAP(ssid);
    // Starting WEB-server

         server.on ( "/", HTTP_handleRoot );
         server.onNotFound ( HTTP_handleRoot );
         server.begin();    

    }

    void loop() {

    }

How to display the localIP of nodemcu esp8266 in Serial using Arduino?

woofMaranon
  • 144
  • 3
  • 15

1 Answers1

0

The code works without delay, just copy it (SoftwareSerial is commented out and a text line as print support is added, never use the delay with the Esps):

    //#include <SoftwareSerial.h>
    #include <ESP8266WiFi.h>
    #include <WiFiClient.h>
    #include <ESP8266WebServer.h>

    const char* host = "WiFi_Robot4_NodeMCU";
    const char* ssid = "EarthQuakeBot";

    ESP8266WebServer server(80); 

    void HTTP_handleRoot() {
            // Some code here
            }

    void setup() {
      IPAddress ip;
      Serial.begin(115200);
      ip = WiFi.localIP();
      Serial.print("This is my ip: ");
      Serial.println(ip);

      // Connecting WiFi

      WiFi.mode(WIFI_AP);
      WiFi.softAP(ssid);
      // Starting WEB-server

      server.on ( "/", HTTP_handleRoot );
      server.onNotFound ( HTTP_handleRoot );
      server.begin();
    }

    void loop() {
    }

and displays (oh wonder) the following:

This is my ip: 0.0.0.0

If using the nodeMCU in AP_Mode (as an access point) you have to assign all the relevant data yourself.Thereis noself assign function, you do it like:

  Serial.begin(115200);
 .....    
   WiFi.softAPConfig(apIP, apGateway, apSubnet);
   WiFi.mode(WIFI_AP);
   WiFi.softAP(ssid);
 .........
   ip = WiFi.localIP();
   Serial.print("This is my ip: ");
   Serial.println(ip);

Work through the library examples and follow a good tutorial like: https://tttapa.github.io/ESP8266/Chap01 - ESP8266.html Hope this helps you and other beginners

Codebreaker007
  • 2,911
  • 1
  • 10
  • 22
  • This code works in the following (tested) environments Windows(7-10), MacOSX, Arduino IDE 1.8.12 and ESP8266Community Edition1.6.3. So check your environment and the com port (driver) It should print at least the line "This is my IP". Switch on File -> preferences -> compiler warnings ALL and post all warnings/errors you get (edit your question) Helping is hard without detailed feedback – Codebreaker007 Mar 13 '20 at 07:12
  • what USB chip do you use? CH340 needs some time – Juraj Mar 14 '20 at 12:51