ok so i wanted to set up a way to send notifs from my raspi at home to my phone because idk i was bored. And I didn’t particularly want to use any third party solutions… so it was time to tune up some ancient open-source project.

Here’s how you get your own notification server

Make an android signing key

oh yeah we’re going to be doing some COOL stuff here.

keytool -genkey -v -keystore android.keystore -alias android -keyalg RSA -keysize 2048 -validity 10000

make sure you note where you put it. You’ll need it.

Go and get android studio

https://developer.android.com/studio

Enjoy the massive size. Download the SDK for android 30.

Clone the repo

Clone https://git.ihatebeinga.live/IHBAGang/notify somewhere

Open it with android studio. You’ll want to open the “build.gradle” file inside android/Notify

Register with google’s firebase

Yes yes i know, but i think it’s the only way to actually mess with play services.

https://console.firebase.google.com/u/0/

Create a new project, call it whatever it doesn’t matter.

Once you’ve done that, go to develop -> realtime database and create one.

Set the rules to

{
  "rules": {
    "tokens": {
      "$token": {
        ".write": "root.child('users').child(auth.uid).child('token').val() == $token",
        ".read": "root.child('users').child(auth.uid).child('token').val() == $token",
      }
    },
    "users": {
      "$uid": {
        ".read": "auth.uid == $uid",
        ".write": "auth.uid == $uid"
      }
    }
  }
}

Now go develop->authentication and turn on anonymous authentication

Shoving it into the app

Ok cool now settings->apps. Create an app. Give it the package name com.kevinbedi.notify and use keytool -list -v -keystore android.keystore -alias android to get your SHA1.

Download the google-services.json and override the one in the repo at android/Notify/app/

Now back in android studio go build->generate signed bundle

Select “APK”, next, give it your keystore details, next, select “release” and check “v2 signature”

Let it spend an eternity building.

Then install the APK on your device

Setting up the server

Clone that repo onto your server of choice, and npm i inside the server directory.

We need to set some stuff up now - back in the firebase console:

Go to settings->service account and create a private key - it’ll download a file.

Copy the contents of the file to server/serviceAccountKey.json

Now create a file config.json of the form

{
  "serverKey": "copy this from config->cloud messaging in firebase",
  "database": "the url from the database area of firebase"
}

Cool now we’ve got everything.

Start the server

node server.js will start it.

Now we need to test it

In another window navigate to node

npm i, change the URL inside notify.js to whatever you’re running it on. It defaults to port 3000.

Now you can

node app.js -r <code from the app>
node app.js -t "test"

and it should work