Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HELP #157

Closed
riskiadi opened this issue Oct 28, 2020 · 5 comments
Closed

HELP #157

riskiadi opened this issue Oct 28, 2020 · 5 comments
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@riskiadi
Copy link

this is my firebase cloud messaging payload

"notification": {
    "title": "Title",
    "body": "xxx",
    "sound": "notification.mp3",
    "android_channel_id" : "my-channel_id",
    "click_action" : "FLUTTER_NOTIFICATION_CLICK"
  },

how do i customize notification <android_channel_id> in firebaseData1.fcm.setNotifyMessage( ) ?

@riskiadi riskiadi added help wanted Extra attention is needed question Further information is requested labels Oct 28, 2020
@mobizt
Copy link
Owner

mobizt commented Oct 28, 2020

I will add option to let the user to provide the custom JSON payload rather than strict only to title, icon, body and click action.
I will update and inform you soon.

@riskiadi
Copy link
Author

riskiadi commented Oct 28, 2020

oh and also, i found bug, when send FCM 3 times it will eror exception 29, for (Firebase Cloud Messaging) with delay 1000ms

@mobizt
Copy link
Owner

mobizt commented Oct 28, 2020

No bugs about this exception, you need to post your code here.

@riskiadi
Copy link
Author

riskiadi commented Oct 28, 2020

this is not my code, this is example code from your library loop 3times every 1second.. after 3 times i got exception

/*

*/

//This example shows how to send Firebase Cloud Messaging.

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

#define WIFI_SSID "YOUR_WIFI_AP"
#define WIFI_PASSWORD "YOUR_WIFI_PASSWORD"
#define FIREBASE_HOST "YOUR_FIREBASE_PROJECT.firebaseio.com" //Without http:// or https:// schemes
#define FIREBASE_AUTH "YOUR_FIREBASE_DATABASE_SECRET"

#define FIREBASE_FCM_SERVER_KEY "YOUR_FIREBASE_PROJECT_CLOUD_MESSAGING_SERVER_KEY"
#define FIREBASE_FCM_DEVICE_TOKEN_1 "RECIPIENT_DEVICE_TOKEN"
#define FIREBASE_FCM_DEVICE_TOKEN_2 "ANOTHER_RECIPIENT_DEVICE_TOKEN"

FirebaseData firebaseData1;

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

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

//Set the size of WiFi rx/tx buffers in the case where we want to work with large data.
firebaseData1.setBSSLBufferSize(1024, 1024);

//Set the size of HTTP response buffers in the case where we want to work with large data.
firebaseData1.setResponseSize(1024);

firebaseData1.fcm.begin(FIREBASE_FCM_SERVER_KEY);

firebaseData1.fcm.addDeviceToken(FIREBASE_FCM_DEVICE_TOKEN_1);

firebaseData1.fcm.addDeviceToken(FIREBASE_FCM_DEVICE_TOKEN_2);

firebaseData1.fcm.setPriority("high");

firebaseData1.fcm.setTimeToLive(1000);

sendMessage();

}

void loop()
{

if (millis() - lastTime > 60 * 1000)
{
    lastTime = millis();

    sendMessage();
}

}

void sendMessage()
{

Serial.println("------------------------------------");
Serial.println("Send Firebase Cloud Messaging...");

firebaseData1.fcm.setNotifyMessage("Notification", "Hello World! " + String(count));

firebaseData1.fcm.setDataMessage("{\"myData\":" + String(count) + "}");

//if (Firebase.broadcastMessage(firebaseData1))
//if (Firebase.sendTopic(firebaseData1))
if (Firebase.sendMessage(firebaseData1, 0))//send message to recipient index 0
{

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

count++;

}

@mobizt
Copy link
Owner

mobizt commented Oct 29, 2020

Now the issue was fixed in the latest update (v 3.0.1)

Now you can use

firebaseData1.fcm.addCustomNotifyMessage("title", "Title");
firebaseData1.fcm.addCustomNotifyMessage("body", "xxx");
firebaseData1.fcm.addCustomNotifyMessage("click_action", "FLUTTER_NOTIFICATION_CLICK");
firebaseData1.fcm.addCustomNotifyMessage("sound", "notification.mp3");
firebaseData1.fcm.addCustomNotifyMessage("android_channel_id", "my-channel_id");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants