Code Monkey home page Code Monkey logo

Comments (22)

chander-60905 avatar chander-60905 commented on July 3, 2024 1

Please check every test case for 10-15 minutes to see if it crashes or not in NodeMcu esp8266 with 2.5.0 and noSpiffs.

//ino file

//FirebaseESP8266.h must be included before ESP8266WiFi.h
#include "FirebaseESP8266.h"
#include <ESP8266WiFi.h>

#define FIREBASE_HOST "Firebase Host"
#define FIREBASE_AUTH "Firebase Auth"
#define WIFI_SSID "ssid"
#define WIFI_PASSWORD "password"

//Define FirebaseESP8266 data object
FirebaseData firebaseData;
FirebaseData streamData; //If using single FirebaseData firebaseData; repeats stream loop every 2-3 seconds and using another FirebaseData streamData; works ok but crashes sometimes.

String path = "/LKV8zPLXYGXJ9gN75ecd8fJLwmE2/Device1"; // Setting path as "/User_id/Controller_1" crashes and Setting path as "/Controller_1" gives heap size approx 18800 in stream loop and Setting path as "/Firebase_User_id/Controller_1" gives free heap as 338080 in stream loop and crashes sometimes

// In last case tested setting FirebaseData streamData; and using path = "/LKV8zPLXYGXJ9gN75ecd8fJLwmE2/Device1", where LKV8zPLXYGXJ9gN75ecd8fJLwmE2 is my firebase user id works with free heap size 338416 but if leaves sketch running for 10-15 minutes and then pinDetails changes then crashes.

void setup() {

Serial.begin(115200);

pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D5, OUTPUT);
digitalWrite(D1, HIGH);
digitalWrite(D2, HIGH);
digitalWrite(D3, HIGH);
digitalWrite(D5, HIGH);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.reconnectWiFi(true);

if (Firebase.getInt(firebaseData, "/Controllers" + path + "/D1status"))
{
  Serial.print("D1 Status: ");
  if (firebaseData.dataType() == "int")
    Serial.println(firebaseData.intData());
    if (firebaseData.intData() == 0)
    {
      digitalWrite(D1, LOW);
    }
    else
    {
      digitalWrite(D1, HIGH);
    }
    Serial.println(ESP.getFreeHeap());
}
delay(100);

if (Firebase.getInt(firebaseData, "/Controllers" + path + "/D2status"))
{
  Serial.print("D2 Status: ");
  if (firebaseData.dataType() == "int")
    Serial.println(firebaseData.intData());
    if (firebaseData.intData() == 0)
    {
      digitalWrite(D2, LOW);
    }
    else
    {
      digitalWrite(D2, HIGH);
    }
    Serial.println(ESP.getFreeHeap());
}
delay(100);

if (Firebase.getInt(firebaseData, "/Controllers" + path + "/D3status"))
{
  Serial.print("D3 Status: ");
  if (firebaseData.dataType() == "int")
    Serial.println(firebaseData.intData());
    if (firebaseData.intData() == 0)
    {
      digitalWrite(D3, LOW);
    }
    else
    {
      digitalWrite(D3, HIGH);
    }
    Serial.println(ESP.getFreeHeap());
}
delay(100);

if (Firebase.getInt(firebaseData, "/Controllers" + path + "/D4status"))
{
  Serial.print("D4 Status: ");
  if (firebaseData.dataType() == "int")
    Serial.println(firebaseData.intData());
    if (firebaseData.intData() == 0)
    {
      digitalWrite(D5, LOW);
    }
    else
    {
      digitalWrite(D5, HIGH);
    }
    Serial.println(ESP.getFreeHeap());
}
delay(100);

String Updated_DataString = "{\"firmwareVersion\":\"1.0.0\", \"deviceOnline\":\"yes\"}";
Firebase.updateNodeSilent(firebaseData, "/Controllers" + path, Updated_DataString);
delay(100);

if (!Firebase.beginStream(streamData, "/Controllers" + path + "/pinDetails"))
{
  Serial.println("FAILED");
  Serial.println("REASON: " + streamData.errorReason());
  Serial.println("------------------------------------");
  Serial.println();
}
else
{
  Serial.println("PASSED");
  Serial.println("------------------------------------");
  Serial.println();
}

}

int Pin_Details;
String Button_Status;

void loop() {
// put your main code here, to run repeatedly:
if (!Firebase.readStream(streamData))
{
Serial.println("--------------------------------");
Serial.println("Read stream...");
Serial.println("FAILED");
Serial.println("REASON: " + streamData.errorReason());
Serial.println("--------------------------------");
Serial.println();
Serial.println(ESP.getFreeHeap());
}

if (streamData.streamTimeout())
{
Serial.println("Stream timeout, resume streaming...");
Serial.println();
Serial.println(ESP.getFreeHeap());
}

if (streamData.streamAvailable())
{
Serial.print("Pin Details : ");
if (streamData.dataType() == "int")
Pin_Details = streamData.intData();
Serial.println(Pin_Details);

 switch(Pin_Details)
    {
      case 10:
      digitalWrite(D1, LOW);
      Button_Status = "{\"D1status\":0}"; //Sometimes Firebase.updateNodeSilent works in last case tested
      Firebase.updateNodeSilent(firebaseData, "/Controllers" + path, Button_Status);
      break;

      case 11:
      digitalWrite(D1, HIGH);
      Button_Status = "{\"D1status\":1}";
      Firebase.updateNodeSilent(firebaseData, "/Controllers" + path, Button_Status);
      break;

      case 20:
      digitalWrite(D2, LOW);
      Button_Status = "{\"D2status\":0}";
      Firebase.updateNodeSilent(firebaseData, "/Controllers" + path, Button_Status);
      break;

      case 21:
      digitalWrite(D2, HIGH);
      Button_Status = "{\"D2status\":1}";
      Firebase.updateNodeSilent(firebaseData, "/Controllers" + path, Button_Status);
      break;

      case 30:
      digitalWrite(D3, LOW);
      Button_Status = "{\"D3status\":0}";
      Firebase.updateNodeSilent(firebaseData, "/Controllers" + path, Button_Status);
      break;

      case 31:
      digitalWrite(D3, HIGH);
      Button_Status = "{\"D3status\":1}";
      Firebase.updateNodeSilent(firebaseData, "/Controllers" + path, Button_Status);
      break;

      case 50:
      digitalWrite(D5, LOW);
      Button_Status = "{\"D4status\":0}";
      Firebase.updateNodeSilent(firebaseData, "/Controllers" + path, Button_Status);
      break;

      case 51:
      digitalWrite(D5, HIGH);
      Button_Status = "{\"D4status\":1}";
      Firebase.updateNodeSilent(firebaseData, "/Controllers" + path, Button_Status);
      break;

      default:
      Button_Status = "";
      break;
  }
Serial.println(ESP.getFreeHeap());

}

}

from firebase-esp8266.

chander-60905 avatar chander-60905 commented on July 3, 2024 1

In last case tested after running for 10-15 minutes, Firebase.updateNodeSilent not works but o starting it works.

case 10:
digitalWrite(D1, LOW);
Button_Status = "{"D1status":0}"; //Sometimes Firebase.updateNodeSilent works in last case tested
Firebase.updateNodeSilent(firebaseData, "/Controllers" + path, Button_Status);
break;

from firebase-esp8266.

mobizt avatar mobizt commented on July 3, 2024

Can you make the example sketch that causes the error or share some part of your sketch? This library version is port from ESP32 which may required some fixes to prevent crash.

from firebase-esp8266.

chander-60905 avatar chander-60905 commented on July 3, 2024

ok i will post an example tomorrow morning and thank you for quick reply.

from firebase-esp8266.

mobizt avatar mobizt commented on July 3, 2024

Thank you I will investigate that and let you know.

from firebase-esp8266.

mobizt avatar mobizt commented on July 3, 2024

Ok now I know the cause.

Due to total header size at line 368 of FirebaseESP8266.cpp to send is set to 320 bytes which is too small for wide range of absolute node path in your case.

To fix the error, at line 368 of FirebaseESP8266.cpp change from

size_t headerSize = 320;

to

size_t headerSize = 500; //600 or any larger value but not too much

Hope this helps.

Anyhow, be aware of using multiple Firebase Data Objects in case of low free memory.

I will add option to change this in the next update.

Thank you for the good case that let me know the issue of long node path.

from firebase-esp8266.

chander-60905 avatar chander-60905 commented on July 3, 2024

ok i have tested and it is now working but if i use only one FirebaseData firebaseData; and then in loop if i update any node

case 10:
digitalWrite(D1, LOW);
Button_Status = "{"D1status":0}"; //Sometimes Firebase.updateNodeSilent works in last case tested
Firebase.updateNodeSilent(firebaseData, "/Controllers" + path, Button_Status);
break;

like this then it will keep repeating stream to that node and it if i use comment out //Firebase.updateNodeSilent(firebaseData, "/Controllers" + path, Button_Status); then it works only when database changes and if i use another FirebaseData streamData;
then it works only when database changes. can i do this with only one FirebaseData firebaseData; as free heap in this case is 32536 in stream loop and if i use FirebaseData streamData; free heap size is 18548 only and thank you for the quick fix.

from firebase-esp8266.

mobizt avatar mobizt commented on July 3, 2024

I may not clearly understand your post or misunderstand, please correct or re explain me again.

If you use only one Firebase Data object to lower mem usage and want to get stream together with read/update data at some interval in loop, the stream will stop or disconnected from server immediately when you read/update data because you use the same http or wifi client inside firebase data object to establish new connection.

In this usage way, you need to manage the time for readstream during the read/update cycle as in Stream.ino example.

For example you read/update data every 5 minutes and each time use 1 minute for that job, then you have 4 minutes of idle time to allow stream to work before next read/update cycle start again.

This means during 1 minute of read/update data, you will miss any data that being monitor in database that may change at that time.

This is the problem when you have only one communication channel which need to share to several tasks which this also occurred in other Firebase library i.e. developed by FirebaseExtend.

To work around, you may need to manually read json data at path being stream and keep in SD or SPIFS before you read/update data at other database paths and later compare to the stream data that read from readStream when streamAvailable to determine any changes take place during you read/update data.

I personally move to ESP32 even time for establish new http connection is slower than ESP8266 but I use update function to save the time.

from firebase-esp8266.

chander-60905 avatar chander-60905 commented on July 3, 2024

ok so i think i am good at using two firebase data object as i have sufficient free heap memory 16928 after all the operations are done.

As if now i was testing the whole sketch on Mobile internet as hotspot, it is working all ok. but today i used my broadband router wifi hotspot and esp connected and got ip address but neither firebase nor stream is working. can i know why

from firebase-esp8266.

chander-60905 avatar chander-60905 commented on July 3, 2024

i am getting errors like
Read stream...
FAILED
REASON: connection lost

Read stream...
FAILED
REASON: connection refused

but i can use internet using router wifi hotspot on my laptop and mobile phones.

from firebase-esp8266.

mobizt avatar mobizt commented on July 3, 2024

connection lost means WiFi connection is lost
connection refused means WiFi connected but no data return from that Access point or router.
All above means esp8266 could not connect to internet.

Try the following.

Reset your router or turn off (unplug) for 3 minutes and try again.
Make sure your router doesn't block port 443.
Try to setup soft AP on your computer and let esp8266 connect to that soft AP.
Try other routers.

from firebase-esp8266.

chander-60905 avatar chander-60905 commented on July 3, 2024

ok i will try an let you know but as for i tested Ping is working on router wifi using esp.

#include <ESP8266WiFi.h>
#include <ESP8266Ping.h>

const char* ssid = "ssid";
const char* password = "passphrase";

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

// We start by connecting to a WiFi network

Serial.println();
Serial.println("Connecting to WiFi");

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}

Serial.println();
Serial.print("WiFi connected with ip ");
Serial.println(WiFi.localIP());

Serial.print("Pinging ip ");
Serial.println(remote_ip);

if(Ping.ping("www.google.com")) {
Serial.println("Success!!");
} else {
Serial.println("Error :(");
}
}

void loop() { }

i will also try with some other router

from firebase-esp8266.

mobizt avatar mobizt commented on July 3, 2024

It doesn't mean this can access SSL port 443.

from firebase-esp8266.

chander-60905 avatar chander-60905 commented on July 3, 2024

ok esp connects and firebase runs for soft ap through laptop but not directly from router wifi. Can i use other port than 443 and if not than how to enable port 443 on router

from firebase-esp8266.

mobizt avatar mobizt commented on July 3, 2024

This ssl port is used to connect to Firebase server so we can't change.
I think that this may relate to low memory as in this post esp8266/Arduino#4593 but I'm not sure. Please try to use only one Firebase Data Object for higher free memory and test.

from firebase-esp8266.

chander-60905 avatar chander-60905 commented on July 3, 2024

ok i have tested using single Firebase Data Object and setting lwIP variant to v2 lower memory or v2 Higher Bandwidth does not connect firebase to router wifi but connects to normal mobile wifi hotspot and setting lwIP variant to v2 IPv6 lower memory or v2 IPv6 Higher bandwidth connects firebase to router wifi without changing any configuration on router and also to mobile wifi hotspot but firebase stops streaming after some time. so i think there is no problem with the router wifi.

from firebase-esp8266.

mobizt avatar mobizt commented on July 3, 2024

Did you try fix ip, multi wifi AP. May be and may be not to confirm that router is not the problem depend on its function or algorithm based on its firewall.

Why not test different devices (esp8266 or router)? Because this relate to local network problem.

from firebase-esp8266.

chander-60905 avatar chander-60905 commented on July 3, 2024

ok i will test and let you know

from firebase-esp8266.

mobizt avatar mobizt commented on July 3, 2024

Thanks for your information. This actually relate to esp8266 core SDK or your router settings, not relate to this library.

from firebase-esp8266.

chander-60905 avatar chander-60905 commented on July 3, 2024

ok i have tested and after setting lwIP variant to v2 IPv6 lower memory works for both router wifi and mobile wifi hotspot. so is it okay to change nodemcu esp8266 from lwIP variant v2 lower memory to lwIP variant to v2 IPv6 lower memory.

from firebase-esp8266.

mobizt avatar mobizt commented on July 3, 2024

Your info is good for everyone that work with esp8266 wifi
Thank you.

from firebase-esp8266.

chander-60905 avatar chander-60905 commented on July 3, 2024

Thank you for your help once again.

from firebase-esp8266.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.