3
votes

I am currently developing an Android app and I would like to include Firebase Cloud Messaging. I was planning to have a Raspberry Pi checking a website every 5 Minutes or so and sending push notifications when something changed. In the official documentation they say that I need an 'app-server' in order to send messages via Firebase.

Does that mean I need to have my Raspi up and running as a server 24/7 and need a static IP / Domain for it? Or is it enough to have my Raspi send the message via the Api (https://fcm.googleapis.com/fcm/send) as I only need downstream messages?

Any help and explanation would be highly appreciated as I can't find a definite answer in any thread or documentation.

3
While its not "required" its highly recommended that its sent from a server and makes it easier when you have a server. your Pi can be the server and send the message since your app does not need to send data to the server and is only interested in info the server says it needstyczj
But I don't need the Raspberry Pi to be always online and have a static IP / domain?GreenSmurf
well if your pi is off and it sends the message who is going to send it? So yes if your pi is the one that sends the message it always has to be ontyczj
But I don't need to have it online all the time, do I? Wouldn't it be enough to have it online whenever it needs to send a message?GreenSmurf
I am just going by your description where you say you check every 5 min and send a push when something changes. if your pi is off its not going to check the website and also not send a message.tyczj

3 Answers

3
votes

You don't as such need an app-server for just one device. If you have some sort of internet connectivity on your Raspberry Pi device, all you need to do is make a request to the firebase API.

Firebase (Google servers) will handle the rest by pushing notifications to all the registered devices.

1
votes

Sending downstream messages (messages to devices) requires that you specify the FCM server key. This key allows sending FCM messages on your behalf, so should only be used on environments you trust.

Typically this means a server that you control. But the recently launched Cloud Functions for Firebase can also serve as such a trusted environment. After all: only developers who have access to your Firebase project can access your Cloud Functions code, and those developers can already send messages using the Notification panel in the Firebase console.

Any device you control in your own environment is also fine as a trusted environment. It doesn't have to have a fixed IP address, since the FCM server typically receives its instructions through XMPP or (more commonly these days) through the Firebase Database. Both of these approaches initiate the connections from the trusted device to Google's servers, so can run without accepting incoming connections.

0
votes

You don't need any server to implement FCM.