Hi all,
I'm having problem with my esp8266. Sketch
#if defined(ESP32)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#endif
#include <Firebase_ESP_Client.h>
// Provide the token generation process info.
#include <addons/TokenHelper.h>
/* 1. Define the WiFi credentials */
#define WIFI_SSID "XXXXX"
#define WIFI_PASSWORD "xxxxx"
/** 2. Define the Service Account credentials (required for token generation)
*
* This information can be taken from the service account JSON file.
*
* To download service account file, from the Firebase console, goto project settings,
* select "Service accounts" tab and click at "Generate new private key" button
*/
#define FIREBASE_PROJECT_ID "app-xe-bus"
#define FIREBASE_CLIENT_EMAIL "firebase-adminsdk-8gsww@app-xe-bus.iam.gserviceaccount.com"
const char PRIVATE_KEY[] PROGMEM = "-----BEGIN PRIVATE KEY-----XXXXXXXX-----END PRIVATE KEY-----\n";
/* 3. Define the ID token for client or device to send the message */
#define DEVICE_REGISTRATION_ID_TOKEN "XXXXXXX"
//Define the user Email and password that alreadey registerd or added in your project */
/* 4. Define the Firebase Data object */
FirebaseData fbdo;
/* 5. Define the FirebaseAuth data for authentication data */
FirebaseAuth auth;
/* 6. Define the FirebaseConfig data for config data */
FirebaseConfig config;
unsigned long lastTime = 0;
int count = 0;
void sendMessage();
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();
Serial.printf("Firebase Client v%s\n\n", FIREBASE_CLIENT_VERSION);
/* Assign the user sign in credentials */
/* Assign the sevice account credentials and private key (required) */
config.service_account.data.client_email = FIREBASE_CLIENT_EMAIL;
config.service_account.data.project_id = FIREBASE_PROJECT_ID;
config.service_account.data.private_key = PRIVATE_KEY;
/* Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback; // see addons/TokenHelper.h
Firebase.begin(&config, &auth);
Firebase.reconnectWiFi(true);
}
void loop()
{
// Firebase.ready() should be called repeatedly to handle authentication tasks.
if (Firebase.ready() && (millis() - lastTime > 60 * 1000 || lastTime == 0))
{
lastTime = millis();
sendMessage();
}
}
void sendMessage()
{
Serial.print("Send Firebase Cloud Messaging... ");
// Read more details about HTTP v1 API here https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages
FCM_HTTPv1_JSON_Message msg;
msg.token = DEVICE_REGISTRATION_ID_TOKEN;
msg.notification.body = "Notification body";
msg.notification.title = "Notification title";
// For the usage of FirebaseJson, see examples/FirebaseJson/BasicUsage/Create.ino
FirebaseJson payload;
// all data key-values should be string
payload.add("temp", "28");
payload.add("unit", "celsius");
payload.add("timestamp", "1609815454");
msg.data = payload.raw();
if (Firebase.FCM.send(&fbdo, &msg)) // send message to recipient
Serial.printf("ok\n%s\n\n", Firebase.FCM.payload(&fbdo).c_str());
else
Serial.println(fbdo.errorReason());
count++;
}
Here is my error after being decoded:
Decoding stack results
0x40216dc4: HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\DellHMD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/HardwareSerial.h line 193
0x4020ded4: UtilsClass::calCRC(char const*) at C:\Users\DellHMD\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/FB_Utils.h line 1460
0x40210b08: Firebase_Signer::authChanged(fb_esp_cfg_t*, fb_esp_auth_signin_provider_t*) at C:\Users\DellHMD\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src\signer\Signer.cpp line 228
0x40204ae8: MB_String::clear() at C:\Users\DellHMD\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/json/MB_String.h line 1155
0x40206cc4: Firebase_ESP_Client::begin(fb_esp_cfg_t*, fb_esp_auth_signin_provider_t*) at C:\Users\DellHMD\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/json/MB_String.h line 474
0x40204ac1: MB_String::allocate(unsigned int, bool) at C:\Users\DellHMD\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/json/MB_String.h line 1693
0x40204b40: MB_String::copy(char const*, unsigned int) at C:\Users\DellHMD\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/json/MB_String.h line 1719
0x40204ec9: setup() at C:\Users\DellHMD\Desktop\notification_sender/notification_sender.ino line 77
0x40218304: loop_wrapper() at C:\Users\DellHMD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\core_esp8266_main.cpp line 198
This is the exception after I initialized FirebaseAuth auth.
Decoding stack results
0x40216de4: HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\DellHMD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/HardwareSerial.h line 193
0x4020def4: UtilsClass::calCRC(char const*) at C:\Users\DellHMD\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/FB_Utils.h line 1460
0x40210b28: Firebase_Signer::authChanged(fb_esp_cfg_t*, fb_esp_auth_signin_provider_t*) at C:\Users\DellHMD\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src\signer\Signer.cpp line 228
0x40204ae8: MB_String::clear() at C:\Users\DellHMD\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/json/MB_String.h line 1155
0x40206ce4: Firebase_ESP_Client::begin(fb_esp_cfg_t*, fb_esp_auth_signin_provider_t*) at C:\Users\DellHMD\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/json/MB_String.h line 474
0x40204ac1: MB_String::allocate(unsigned int, bool) at C:\Users\DellHMD\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/json/MB_String.h line 1693
0x40204b40: MB_String::copy(char const*, unsigned int) at C:\Users\DellHMD\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/json/MB_String.h line 1719
0x40204eeb: setup() at C:\Users\DellHMD\Desktop\notification_sender/notification_sender.ino line 80
0x40218324: loop_wrapper() at C:\Users\DellHMD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\core_esp8266_main.cpp line 198
I upgraded the library to the latest version and this is the new error:
Decoding stack results
0x4020e20c: UtilsClass::calCRC(char const*) at C:\Users\DellHMD\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/FB_Utils.h line 1461
0x40210fd4: Firebase_Signer::authChanged(fb_esp_cfg_t*, fb_esp_auth_signin_provider_t*) at C:\Users\DellHMD\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src\signer\Signer.cpp line 237
0x40204ae8: MB_String::clear() at C:\Users\DellHMD\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/json/MB_String.h line 1213
0x40206d7c: Firebase_ESP_Client::begin(fb_esp_cfg_t*, fb_esp_auth_signin_provider_t*) at C:\Users\DellHMD\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src\Firebase.cpp line 88
0x40100ae4: malloc(size_t) at C:\Users\DellHMD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\umm_malloc\umm_malloc.cpp line 821
0x40204ac1: MB_String::allocate(unsigned int, bool) at C:\Users\DellHMD\Documents\Arduino\libraries\Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32\src/json/MB_String.h line 1751
0x40204eeb: setup() at C:\Users\DellHMD\Desktop\notification_sender/notification_sender.ino line 80
0x40218ba0: loop_wrapper() at C:\Users\DellHMD\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266\core_esp8266_main.cpp line 198
Looks like it's in: void replaceFirebasePath(MB_String &path)
\src\signer\Signer.cpp line 237
Strange. This file does not contain a function named "auth_changed()" and does not call "replaceFirebasePath()"
\src\Firebase.cpp line 88
There is no function call on line 88.
On line 86 there is a call to: Signer.checkAuthTypeChanged(config, auth);
That function DOES exist in Signer.cpp and contains line 237.
Looks like your stack dump doesn't match the current sources.
I copied all the neccesary infomation from json file and pasted into the sketch. I got the json file from firebase -> Service accounts -> Generate new private key.