Giter Club home page Giter Club logo

Comments (7)

mobizt avatar mobizt commented on May 27, 2024

Please post your sketch here that I will try and investigate the problem.

from firebase-esp8266.

UltimatPronin avatar UltimatPronin commented on May 27, 2024

Here it is:
`#include "FirebaseESP8266.h"
#include <ESP8266WiFi.h>

#define FIREBASE_HOST "XXXXXX.firebaseio.com"
#define FIREBASE_AUTH "YYYYYYYYY"
#define FIREBASE_FCM_SERVER_KEY "ZZZZZZZZZZZZZZZZ"
#define FIREBASE_FCM_DEVICE_TOKEN_1 "XXXXXXXXXXXXXXX"
#define WIFI_SSID "RRRRRRRRRRRRRRR"
#define WIFI_PASSWORD "PPPPPPPPPPPPP"

//Define FirebaseESP8266 data object
FirebaseData firebaseData;

unsigned long sendDataPrevMillis = 0;
unsigned long sendMSGPrevMillis = 0;

String path = "/Devices";

uint16_t count = 0;

void setup()
{

Serial.begin(115200);

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);

firebaseData.fcm.begin(FIREBASE_FCM_SERVER_KEY);
firebaseData.fcm.addDeviceToken(FIREBASE_FCM_DEVICE_TOKEN_1);
//firebaseData.fcm.addDeviceToken(FIREBASE_FCM_DEVICE_TOKEN_2);
firebaseData.fcm.setPriority("high");
firebaseData.fcm.setTimeToLive(1000);

if (!Firebase.beginStream(firebaseData, path))
{
Serial.println("------------------------------------");
Serial.println("Can't begin stream connection...");
Serial.println("REASON: " + firebaseData.errorReason());
Serial.println("------------------------------------");
Serial.println();
}
}

void loop()
{
//This example uses the same Firebase Data object to read/store data (get, set, update, push and delete) and stream.
//This causes some delay (for start new SSL connection) for swiching between read/store and stream operation.
//For no delay, see Different_objects_stream.ino example which uses different Firebase Data object for read/store and stream data.

if (millis() - sendMSGPrevMillis > 10000){
sendMSGPrevMillis = millis();

firebaseData.fcm.setNotifyMessage("Notification"+String(random(0xffff)), "Hello World! " + String(random(0xffff)));

if (Firebase.sendMessage(firebaseData, 0))//send message to recipient index 0
{

    Serial.println("PASSED");
    Serial.println(firebaseData.fcm.getSendResult());
    Serial.println("------------------------------------");
    Serial.println();
}
else
{
    Serial.println("FAILED");
    Serial.println("REASON: " + firebaseData.errorReason());
    Serial.println("------------------------------------");
    Serial.println();
}

}

if (millis() - sendDataPrevMillis > 15000)
{
sendDataPrevMillis = millis();
count++;

Serial.println("------------------------------------");
Serial.println("Set string...");
if (Firebase.setString(firebaseData, path + "/String", "Hello World! " + String(count)))
{
  Serial.println("PASSED");
  Serial.println("PATH: " + firebaseData.dataPath());
  Serial.println("TYPE: " + firebaseData.dataType());
  Serial.print("VALUE: ");
  if (firebaseData.dataType() == "int")
    Serial.println(firebaseData.intData());
  else if (firebaseData.dataType() == "float")
    Serial.println(firebaseData.floatData(), 5);
  else if (firebaseData.dataType() == "double")
    Serial.println(firebaseData.doubleData(), 9);
  else if (firebaseData.dataType() == "boolean")
    Serial.println(firebaseData.boolData() == 1 ? "true" : "false");
  else if (firebaseData.dataType() == "string")
    Serial.println(firebaseData.stringData());
  else if (firebaseData.dataType() == "json")
    Serial.println(firebaseData.jsonData());
  Serial.println("------------------------------------");
  Serial.println();
}
else
{
  Serial.println("FAILED");
  Serial.println("REASON: " + firebaseData.errorReason());
  Serial.println("------------------------------------");
  Serial.println();
}

//Pause WiFi client from all Firebase calls and use shared SSL WiFi client
if (firebaseData.pauseFirebase(true))
{

  WiFiClientSecure client = firebaseData.getWiFiClient();
  //Use the client to make your own http connection...
}
else
{
  Serial.println("------------------------------------");
  Serial.println("Can't pause the WiFi client...");
  Serial.println("------------------------------------");
  Serial.println();
}
//Unpause WiFi client from Firebase task
firebaseData.pauseFirebase(false);

}

if (!Firebase.readStream(firebaseData))
{
Serial.println("------------------------------------");
Serial.println("Can't read stream data...");
Serial.println("REASON: " + firebaseData.errorReason());
Serial.println("------------------------------------");
Serial.println();
}

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

if (firebaseData.streamAvailable())
{
Serial.println("------------------------------------");
Serial.println("Stream Data available...");
Serial.println("STREAM PATH: " + firebaseData.streamPath());
Serial.println("EVENT PATH: " + firebaseData.dataPath());
Serial.println("DATA TYPE: " + firebaseData.dataType());
Serial.println("EVENT TYPE: " + firebaseData.eventType());
Serial.print("VALUE: ");
if (firebaseData.dataType() == "int")
Serial.println(firebaseData.intData());
else if (firebaseData.dataType() == "float")
Serial.println(firebaseData.floatData());
else if (firebaseData.dataType() == "boolean")
Serial.println(firebaseData.boolData() == 1 ? "true" : "false");
else if (firebaseData.dataType() == "string")
Serial.println(firebaseData.stringData());
else if (firebaseData.dataType() == "json")
Serial.println(firebaseData.jsonData());
Serial.println("------------------------------------");
Serial.println();
}
}`

After first call Firebase.sendMessage(firebaseData, 0) I got this errors:
Can't read stream data...
Fatal exception 3(LoadStoreErrorCause):
epc1=0x4021edc0, epc2=0x00000000, epc3=0x00000000, excvaddr=0x402604a3, depc=0x00000000

Exception (3):
epc1=0x4021edc0 epc2=0x00000000 epc3=0x00000000 excvaddr=0x402604a3 depc=0x00000000

stack>>>

ctx: cont
sp: 3ffffd30 end: 3fffffc0 offset: 01a0
3ffffed0: 3ffe895f 3ffeed30 ffffffff 3ffeee38
3ffffee0: 3ffe895f 3ffeed30 ffffffff 40202294
3ffffef0: 3fffff10 3ffeedc8 3fffff30 40210658
3fffff00: 3ffe8765 3fffff50 3ffeec00 40204a2a
3fffff10: 3ffef38c 3ffeed30 3ffeedc8 4020ffbc
3fffff20: 3ffe8765 3ffeedc8 3ffeec00 40201885
3fffff30: 53414552 203a4e4f 00203a00 402255e2
3fffff40: 3fffff64 3ffeec00 3fffff80 3ffeee38
3fffff50: 00000000 00000000 fffeec00 00000000
3fffff60: 00000000 fffeec00 00000000 00000000
3fffff70: fffeed30 3ffeec00 3ffeedc8 402011cd
3fffff80: 00000000 00000000 ffefef00 00000000
3fffff90: 00000000 00000000 00000001 3ffeee38
3fffffa0: 3fffdad0 00000000 3ffeee04 40210cd4
3fffffb0: feefeffe feefeffe 3ffe854c 401004e9
<<<stack<<<

Decoding stack results
0x40202294: FirebaseESP8266::errorToString(int, std::string&) at D:\Profile\User\Documents\Arduino\libraries\Firebase_ESP8266_Client\src\FirebaseESP8266.cpp line 3612
0x40210658: String::copy(char const*, unsigned int) at C:\Users\Ultimat\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.1\cores\esp8266\WString.cpp line 211
0x40204a2a: FirebaseData::errorReason() at D:\Profile\User\Documents\Arduino\libraries\Firebase_ESP8266_Client\src\FirebaseESP8266.cpp line 4847
0x4020ffbc: Print::println(char const*) at C:\Users\Ultimat\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.1\cores\esp8266\Print.cpp line 190
0x40201885: loop() at D:\Profile\User\Documents\Arduino\Tests\Stream_FCM/Stream_FCM.ino line 167
0x402255e2: std::basic_string , std::allocator >::~basic_string() at /workdir/arena/gcc/xtensa-lx106-elf/libstdc++-v3/include/bits/basic_string.h line 541
0x402011cd: setup() at D:\Profile\User\Documents\Arduino\Tests\Stream_FCM/Stream_FCM.ino line 61
0x40210cd4: loop_wrapper() at C:\Users\Ultimat\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.1\cores\esp8266\core_esp8266_main.cpp line 125

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

If two issues you open are the same can be close one?

from firebase-esp8266.

UltimatPronin avatar UltimatPronin commented on May 27, 2024

Really, I think issues are similar. You can close one of them.

UPDATE:
I determinate, if I copy all my sketch parts from many tabs in Arduino IDE to 1 big sketch tab - all working VERY GOOD. But If I split my sketck by many tabs - then I get ERRORS. Any Ideas? It is IDE BUG?

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

Multiple .ino files may lead to problems.
Try to declare global variables in one header file (.h file on any tab).
Then include this header file at the top of main sketch but not sure it help or not.

For big project and library developt I switch to Platformio on VS Code.

from firebase-esp8266.

UltimatPronin avatar UltimatPronin commented on May 27, 2024

Thank you for advice.

from firebase-esp8266.

mobizt avatar mobizt commented on May 27, 2024

As I test your posted sketch. No error for stack.

For stream, when FCM need to send new message, it will stop the stream connection and start new http connection to different uri due to they use the same WiFi client in Firebase Data object, and the FCM response from server is a bit slower than RTDB connection. During this time stream can't be connected and after FCM message complete it work, stream will be resumed and use time to re-connected to the stream path, you may miss stream data during this as normal behavior of multi-tasking with only one WiFi client.

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.