Hello i am new to NodeMCU (ESP8266) i am building a small program to connect with WIFI (with internet) and if internet is not available i want to process request over IP address.

I am using firebase as a database / server to fetch the status. And process command through a URL like if internet is connected then no problem i can update firebase entry, but with same network (LAN) connection over wifi i want to process i need to have static IP. But the concern is i am not able to make this IP address static, and if i make it static then my NodeMCU is not able to connect with firebase.

Here is how my code looks like:

#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#include <ESP8266WebServer.h>

#define FIREBASE_HOST "pushst-56f2c.firebaseio.com"
#define FIREBASE_AUTH "mhBpzrNyhhwEGwmFxkVFTIEylwrXMw0gm"
#define PATH "/clients/devicename/watermotor"

IPAddress ip(192, 168, 1, 223);  //Node static IP
IPAddress dns(192, 168, 1, 223);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);

char ssid[] = "MyNetwork";   
char password[] = "Qwert98!!"; 

int wifiStatus = WL_IDLE_STATUS;

ESP8266WebServer server(80);

void setup() { 

      Serial.print("Your are connecting to;");

      WiFi.begin(ssid, password);
      WiFi.config(ip, dns, gateway, subnet);

      while (WiFi.status() != WL_CONNECTED) {
        digitalWrite(WIFI_CONNECT_LED, HIGH);

      wifiStatus = WiFi.status();

      if(wifiStatus == WL_CONNECTED){
          digitalWrite(WIFI_CONNECT_LED, LOW);

         Serial.println("Your IP address is: ");

         Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
         Firebase.set("/clients/devicename/watermotor/name", "Motor");
         Firebase.set("/clients/devicename/watermotor/relay_status", "off");
         Firebase.set("/clients/devicename/watermotor/device_status", "online");

         server.on("/on", handleOnRequest); //Associate the handler function
         server.on("/off", handleOffRequest); //Associate the handler function

         server.begin(); //Start the server
        Serial.println("WiFi not connected");


void loop() { 
    if (Firebase.failed()) {
      Serial.println("streaming error");

    if (Firebase.available()) {
        Serial.print("Firebase available");
        FirebaseObject event = Firebase.readEvent();

I am not sure if its there is some problem with FirebaseLibrary or its just the ESP8266!

Any suggestions will be helpful, thanks in advance! :)

  • 1
    why same IP for esp8266 and DNS? – Juraj Feb 22 '18 at 14:44
  • Its just for reference, i can keep any @Juraj – user3201500 Feb 22 '18 at 15:53
  • it should be the address of the DNS server which can resolve the name of the firebase host – Juraj Feb 22 '18 at 16:49
  • Not getting you @Juraj any example? – user3201500 Feb 22 '18 at 18:01
  • example? just fill in the IP address of the DNS server which is usually the address of the router/gateway IPAddress dns(192,168,1,1); (if this is right) – Juraj Feb 22 '18 at 18:30

You have wrong DNS server IP address. In your sketch it is the same as the static IP address you assign to esp. Then the name of the firebase host can't be resolved by DNS.

The DNS server is usually the router/gateway.

IPAddress dns(192,168,1,1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.