0

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 http://192.168.1.223/on?pin=04 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.begin(115200); 
 delay(100);
 Serial.println();
 Serial.println();
 Serial.print("Your are connecting to;");
 Serial.println(ssid);
 WiFi.begin(ssid, password);
 WiFi.config(ip, dns, gateway, subnet);
 while (WiFi.status() != WL_CONNECTED) {
 digitalWrite(WIFI_CONNECT_LED, HIGH);
 delay(500);
 Serial.print(".");
 }
 wifiStatus = WiFi.status();
 if(wifiStatus == WL_CONNECTED){
 digitalWrite(WIFI_CONNECT_LED, LOW);
 Serial.println("Your IP address is: ");
 Serial.println(WiFi.localIP()); 
 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");
 Firebase.stream(PATH);
 server.on("/on", handleOnRequest); //Associate the handler function
 server.on("/off", handleOffRequest); //Associate the handler function
 server.begin(); //Start the server
 }
 else{
 Serial.println("");
 Serial.println("WiFi not connected");
 }
}
void loop() { 
 server.handleClient();
 if (Firebase.failed()) {
 Serial.println("streaming error");
 Serial.println(Firebase.error());
 delay(1000);
 return;
 }
 if (Firebase.available()) {
 Serial.println();
 Serial.print("Firebase available");
 Serial.println();
 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! :)

ReyAnthonyRenacia
17.7k6 gold badges42 silver badges63 bronze badges
asked Feb 22, 2018 at 13:27
2
  • is FIREBASE_AUTH your supersecret token? It's not so secret anymore Commented Feb 22, 2018 at 14:10
  • Yes it works fine if i dont put Static IP. Commented Feb 22, 2018 at 14:10

1 Answer 1

0

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)
answered Feb 24, 2018 at 11:31
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.