Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Firebase stream and firebase setString causing crash! #266

Closed
BahmanK opened this issue May 29, 2017 · 11 comments
Closed

Firebase stream and firebase setString causing crash! #266

BahmanK opened this issue May 29, 2017 · 11 comments

Comments

@BahmanK
Copy link

BahmanK commented May 29, 2017

Hi folks,

On LinkNode R8 (relay board equipped with ESP 8266), I am writing an application that I need to run "setString" while firebase streaming. However, as soon as I run "setString" after firebase stream begin function, the board crashes (error shown below). The interesting part is that, sometimes it sets the values in database and it crashes afterwards and sometimes it doesn't even set the value.

I tried many different solutions offered on other relevant issues with no luck. Below is the error code, my code and settings. Any help appreciated.

Error:
Exception (28):
epc1=0x40207f26 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

ctx: cont
sp: 3fff1070 end: 3fff14b0 offset: 01a0

stack>>>
3fff1210: 402012ee 000003e8 3fff03cc 40207f26
3fff1220: 3fff0208 00000000 3fff03cc 40202355

Code:

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

// Set these to run example.
#define FIREBASE_HOST "xxx"
#define FIREBASE_AUTH "xxx"
#define WIFI_SSID "xxx"
#define WIFI_PASSWORD "xxx"

String eventType, eventPath, eventData;
FirebaseArduino FirebaseStream, FirebaseShaboo;

// Setup-----------------------------------------------------------------------------------------------
void setup() {
Serial.begin(9800);
pinMode(13, OUTPUT);
pinMode(14, OUTPUT);

byte mac[6];
WiFi.macAddress(mac);

// connect to wifi.
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());

FirebaseShaboo.begin(FIREBASE_HOST, FIREBASE_AUTH);
delay(1000);
FirebaseShaboo.setString("message", "Bahoo");
delay(1000);

//Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
FirebaseStream.begin(FIREBASE_HOST, FIREBASE_AUTH);
FirebaseStream.stream("/test");

}

int n = 0;
bool set_en = 0;
void loop() {

if (FirebaseStream.available()) {
FirebaseObject event = FirebaseStream.readEvent();

Serial.print("event: ");
eventType = event.getString("type");
Serial.println(eventType);  
eventPath = event.getString("path");
Serial.print("path: ");
Serial.println(eventPath);
eventData = event.getString("data");
Serial.print("data: ");
Serial.println(eventData);

if (eventType.indexOf("patch")>=0){
  Serial.print("patch received: ");
}

if(eventData.indexOf("off")>=0){
   digitalWrite(13, LOW);
   digitalWrite(14, LOW);   
   Serial.println("OFF,OFF");

} else if(eventData.indexOf("on")>=0){
digitalWrite(13, HIGH);
digitalWrite(14, HIGH);
Serial.println("ON,ON");
} else if(eventData.indexOf("send")>=0){
set_en = 1;
}
}
Serial.println(ESP.getFreeHeap());
delay(1000);
if (set_en == 1){
set_en = 0;
FirebaseShaboo.setString("message", "Nikki");
delay(1000);
}
Serial.println("Loop");
}

Settings:
image

@slowpoison4
Copy link

Hi!
I've had similar problems while using nested loops in esp8266. Try using yield() in your void loop at places where it might take time to execute a certain command. This is because esp8266 does all it's background communication without our knowledge since the front end Arduino code doesn't really help in knowing about it either.

@RaemondBW
Copy link
Contributor

RaemondBW commented Aug 18, 2017

This is a duplicate of #48. As far as I know there isn't a solution.

@proppy
Copy link
Contributor

proppy commented Sep 8, 2017

Yes, this looks similar to #48

@kotl
Copy link
Collaborator

kotl commented Apr 8, 2018

This should be tried again. Due to the following change in upstream repo:
esp8266/Arduino@bf5a0f2

And prior changes in this repo that uses external ArduinoJson, this problem might no longer exist.

@proppy
Copy link
Contributor

proppy commented Apr 9, 2018

@kotl woot! maybe we can keep the streaming connection open thanks to this change now?

@kotl
Copy link
Collaborator

kotl commented Apr 10, 2018

I tested a sketch that I used before when I tried to fix it. It works beautifully now with two instances of FirebaseArduino where one is used for streaming and the other one for setting values. Still 10k of heap left.

FirebaseArduino MyFirebaseStream;
FirebaseArduino MyFirebase;

So I think you can close this one as fixed, including everything else that's open due to crashes with streaming or simultaneous connections.

It is probably good idea to recommend everyone to use 2.4.1:
https://github.com/esp8266/Arduino/tree/2.4.1
As that's release where it was fixed.

The only concern I have left is with intermittent _canReuse still being set to false sometimes in ESP8266HTTPClient.cpp, but I can't reproduce it consistently. I have some ideas to fix this, but really need to reproduce it consistently first.

@proppy
Copy link
Contributor

proppy commented Apr 10, 2018

@kotl I wonder if we could keep two WebSecureClient in the FirebaseArduino instance to make it possible to use both stream and regular call w/ the global instance.

@jorgewilliams21
Copy link

Hi, I have a similar code and I'm using the version 2.4.1 and it works :)

@kotl
Copy link
Collaborator

kotl commented May 1, 2018

I have refactored it and code is working and almost ready. Probably in several weeks I will send pull request when I finish the unit tests. You can check it out in my fork: https://github.com/kotl/firebase-arduino

@kotl
Copy link
Collaborator

kotl commented May 9, 2018

Pull request #330

@proppy
Copy link
Contributor

proppy commented Jun 15, 2018

Closing now that #330 is merged.

@proppy proppy closed this as completed Jun 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants