Nabto Edge Push Notification Quick Start
This quick start guide shows how to setup a ready-made Nabto Edge client and device for sending push notifications through Firebase Cloud Messaging (FCM). The example applications uses a pre-configured Firebase project, and so the configuration of Firebase is not needed for this example.
Nabto Cloud Configuration
To use Nabto Edge, you must first create a free account through the Nabto Cloud Console if not done already.
Once you have created an account, navigate to the Products page create a new Nabto Edge product. Note down the product ID.
In the “Configured Devices” tab, create a new device. From the device page, note the device ID. First time you start the device, it will generate an encryption key. The fingerprint of the derived public key must be configured on this page (described in next section how to obtain).
You are now ready to start building the Embedded device application.
Embedded Device Application
Follow the general build instructions on the Embedded SDK intro page to build the simple_push_device
application.
To run the application, use the product ID and device ID noted above and execute the following in a terminal:
$ ./_install/bin/simple_push_device pr-abcdefg de-hijklmn
Nabto Embedded SDK Version 5.11.0
Device: pr-abcdefg.de-hijklmn with fingerprint: [73e53042551c128a492cfd910b9ba67fffd2cab6c023b50c10992289f4c23d54]
Pick a category to trigger a push notification for
[i] info category
[w] warn category
[a] alert category
[q] Close the device and quit
The first time the device is run, it will generate a private key to use for secure communication with the Nabto Edge Basestation and Nabto Edge Client and store it locally in the device.key
file. When started, the device prints the associated fingerprint, which must be configured on the Nabto Cloud Console device page as described in the previous section.
Once the fingerprint is configured, the device will be allowed to attach to the basestation allowing it to send push notifications.
The device uses the IAM module to pair, authenticate, and store client configuration.
Two types of push notifications can be sent using this example:
- The IAM module provides a CoAP endpoint to send a test notification to a specific client paired with the device.
- Clients can subscribe to notification categories using CoAP endpoints in the IAM module, the device application can then send notifications to all clients subscribing to a particular category.
This example can send push notifications to clients subsribed to three different push notifications categories by entering its corresponding letter, eg.:
i
Sending FCM notification to all users subsribed to category Info
Sent all notifications for category Info
Pick a category to trigger a push notification for
[i] info category
[w] warn category
[a] alert category
[q] Close the device and quit
Currently, no clients are paired with the device, and so, no notifications will actually be sent until a client is paired.
Mobile Client Application
Push notification examples are available for Android with iOS coming soon. This example uses the local open pairing mode, so the client app must run on the same LAN the desktop based device application while pairing. Once the client is paired with the device, remote connections can be used.
Android application
Clone the github repository then build and run the app. This is done either graphically through Android Studio, or using gradle and adb from command-line:
git clone https://github.com/nabto/android-simple-push.git
cd android-simple-push
./gradlew build
adb install app/build/outputs/apk/debug/app-debug.apk
After opening the app, press pair new device
. The app now scans the local network for devices available for pairing. When your device is discovered, press pair
and type a username for your client on the device. The username can only contain lower case letters, numbers, and the characters: _
, .
, -
. When paired, go to the device settings page. From here you can subscribe to the three notification categories available for the device, as well as sending a test notification to the app.
When subscribed to a notification category, triggering push notifications from the device should result in notifications arriving on your Android device.
Making your own applications
Now that you have sent your first push notifications using Nabto Edge, you are ready to integrate it into your own applications. As noted earlier, the FCM project ID and registration token is sent to the device from the client application using the CoAP endpoint PUT /iam/users/:username/fcm
provided by the SDK. This means, the embedded device example will work equally well with your own Firebase project and mobile app.
Your next step should, therefore, be creating your own Firebase project and making it work with the example device. When your Firebase project is configured, you can modify the example mobile client application to ensure it is working before integration into your own applications.
Changing Firebase Project in Android Example
To change which Firebase project the Android example app uses, go to your Firebase project, and add the example App (the example package name is com.nabto.simplepush
). When added, download the google-services.json
file for your project. Use it to replace the existing file located at app/google-services.json
. Rebuild and run the app, and push notifications should now go through your own Firebase Project.