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

FirebaseStream and FirebasePush did not work together #96

Closed
loka17 opened this issue Apr 25, 2016 · 13 comments
Closed

FirebaseStream and FirebasePush did not work together #96

loka17 opened this issue Apr 25, 2016 · 13 comments

Comments

@loka17
Copy link

loka17 commented Apr 25, 2016

Hi,
I tried to run firebase stream example (FirebaseStream_ESP8266) on device and it worked as I expected.
After that, I tried to add a new feature in which the device push feedback message to firebase cloud after getting data from stream. I used FirebasePush to implement this. (I also tried FirebasePush separately and it worked fine.)
Unfortunately, it ended up with an exception.

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

and FirebasePush error message look like this one.

POST /feedbacks.json: -3

Did I make something incorrectly ?
Any help will be appreciated.

My modified code is as follow.

//
// Copyright 2015 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

// FirebaseStream_ESP8266 is a sample that stream bitcoin price from a
// public Firebase and optionally display them on a OLED i2c screen.

#include <Firebase.h>
#include <ESP8266WiFi.h>
//#include <Adafruit_GFX.h>
//#include <Adafruit_SSD1306.h>
#include <ArduinoJson.h>

//#define OLED_RESET 3
//Adafruit_SSD1306 display(OLED_RESET);

Firebase fbase("<my firebase cloud>");
FirebaseStream stream;

void setup() {
  Serial.begin(9600);

  //display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
  //display.display();

  // connect to wifi.
  WiFi.begin("SSID", "PASSWORD");
  Serial.print("connecting");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.print("connected: ");
  Serial.println(WiFi.localIP());
  stream = fbase.stream("/bitcoin/last");  
}


void loop() {
  if (stream.error()) {
    Serial.println("streaming error");
    Serial.println(stream.error().message());
  }

  if (stream.available()) {
     String event;
     auto type = stream.read(event);
     Serial.print("event: ");
     Serial.println(type);
     if (type == FirebaseStream::Event::PUT) {
       StaticJsonBuffer<200> buf;
       Serial.print("data: ");
       Serial.println(event);
       JsonObject& json = buf.parseObject((char*)event.c_str());
       String path = json["path"];
       float data = json["data"];       

       // TODO(proppy): parse JSON object.
       //display.clearDisplay();
       //display.setTextSize(2);
       //display.setTextColor(WHITE);
       //display.setCursor(0,0);
       //display.println(path.c_str()+1);
       //display.println(data);
       //display.display();

      //Added code: Send feedback to firebase cloud.
      FirebasePush fbPush = fbase.push("/feedbacks", "{\"received\":\"true\"}");
      if (fbPush.error()) {
            Serial.println("Firebase set failed");
            Serial.println(fbPush.error().message());  
            delay(100);
            return;
          }
          Serial.println(fbPush.name());
     }
  }   
}
@loka17 loka17 changed the title FirebaseStream and FirebasePush did not work together. FirebaseStream and FirebasePush did not work together Apr 25, 2016
@proppy
Copy link
Contributor

proppy commented Apr 25, 2016

Which version of the the arduino esp8266 core are you using?

See also #48

@loka17
Copy link
Author

loka17 commented Apr 25, 2016

Thanks for your reply.
I was using arduino esp8266 version 2.2.0 (installed using board manager) when reported this issue.
Now I am trying install the core from github as be mentioned in #48. (I have never done it before.)
I followed the instruction in "Using git version" (clone repository into hardware/esp8266com/esp8266, download binary tool, restart Arduino).
The issue is still the same (exception still occurred). But I am not sure it run with the new core or the old one, because below /hardware directory there're two versions of esp8266 core.

my Arduino15/packages/esp8266/hardware directory is as below.

hardware
|- esp8266
|- esp8266com

If I installed the core incorrectly, please give me some instructions.
(btw, I am using Arduino IDE version 1.6.8)

@proppy
Copy link
Contributor

proppy commented Apr 25, 2016

You should have two esp8266 board category to select from the 'Tools / Board' menu.

To make sure you're using the right one, edit platform.txt under the both esp8266/esp8266 and esp8266com/esp8266 directory and change the name= property to be:

  • name=ESP8266 Modules (stable) for esp8266
  • name=ESP8266 Modules (master) for esp8266com

That way you could easily identify them from the 'Board' menu.

Hope that helps.

@loka17
Copy link
Author

loka17 commented Apr 25, 2016

After changing the name= property in platform.txt files of both version, it turns out that from the "Tools/Board" menu only the stable version is shown.

That means the core which is cloned from github is not recognised by Arduino IDE.

I am pretty sure that I have done all steps described in "Using git version".
Is there any extra config needed ?

Thanks.

@proppy
Copy link
Contributor

proppy commented Apr 25, 2016

what is the content of the esp8266com directory?

@loka17
Copy link
Author

loka17 commented Apr 25, 2016

The esp8266com directory tree is as below.

esp8266com
   |--esp8266
        |--boards.txt
        |--bootloaders
        |--cores
        |--doc
        |--ISSUE_TEMPLATE.md
        |--libraries
        |--LICENSE
        |--package
        |--platform.txt
        |--programmers.txt
        |--README.md
        |--tests
        |--tools
        |--variants

and tools directory after download binary tools contains these files and sub-directory.

tools
   |--build.py
   |--dist
   |--espota.py
   |--esptool
   |--get.py
   |--mkspiffs
   |--sdk
   |--xtensa-lx106-elf

@proppy
Copy link
Contributor

proppy commented Apr 25, 2016

Can you try to remove the stable directory from hardware temporarily?

@loka17
Copy link
Author

loka17 commented Apr 26, 2016

Simply removing the stable directory did not work. ESP8266 board definition on Tools/Board has gone away.
However if I change folder's name of master directory from esp8266com/esp8266 into esp8266/2.2.0 (which is the same as stable one), it will be recognised in Tools/Board.

So I think that the directory name is configured somewhere.

Moreover, after removing stable directory and changing master directory's name so that it's recognised by Arduino, I ran the above code. The program still be crashed by Exception (28).

@proppy
Copy link
Contributor

proppy commented Apr 29, 2016

Let's merge the discussion with #48 since I believe this is the same issue.

@proppy proppy closed this as completed Apr 29, 2016
@proppy
Copy link
Contributor

proppy commented May 19, 2016

I think this is fixed with arduino-esp8266 master (esp8266/Arduino@43fb139).

I was able to run successfully the following sketch:


FirebaseArduino FirebaseStream;

void setup() {
  Serial.begin(9600);

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

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

int n = 0;
void loop() {
  Serial.println("loop");
  Firebase.setInt("data", n++);
  if (Firebase.failed()) {
    Serial.println(Firebase.error());
  }
  int data = Firebase.getInt("data");
  if (Firebase.failed()) {
    Serial.println(Firebase.error());
  }
  Serial.print("data: ");
  Serial.println(data);
  Serial.print("heap: ");
  if (FirebaseStream.available()) {
    FirebaseObject event = FirebaseStream.readEvent();
    Serial.print("event: ");
    Serial.println(event.getString("event"));
    Serial.print("path: ");
    Serial.println(event.getString("path"));
    Serial.print("data: ");
    Serial.println(event.getInt("data"));
  }
  Serial.println(ESP.getFreeHeap());
  delay(1000);
}

@loka17 can you try again?

@loka17
Copy link
Author

loka17 commented May 20, 2016

I was also able to run successfully the above sketch with arduino-esp8266 master (esp8266/Arduino@43fb139).
I am going to try some more patterns to check if the issue still exists.

@proppy
Copy link
Contributor

proppy commented May 23, 2016

@loka17 Thanks! don't hesitate to report your findings here.

@BahmanK
Copy link

BahmanK commented Apr 30, 2017

I'm using the same code and still getting Exception (28):
epc1=0x4020815a epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

Error.

I am positive that FirebaseStream.available break the code. Once I comment out that if, everything works fine.

What else should I do to debug the issue?

Thanks,

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants