Nabto Edge Push Notification Quick Start
This quick start guide shows how to run a ready-made Nabto Edge device example that sends push notifications through Firebase Cloud Messaging (FCM) and how to build a mobile client application of your own that receives them. Nabto does not provide a ready-made mobile client for push notifications. Instead, the Client Application section walks through the steps your own application must perform.
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).
Next, configure the Firebase project the notifications will be sent through.
Firebase Configuration
Push notifications are delivered by FCM, so a Firebase project is needed. Follow the Firebase configuration guide to create a project and give the Nabto Edge Basestation permission to send notifications through it. Note down the Firebase project ID, it is sent from your client application to the device later in this guide.
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.
Client Application
The device example is ready to send notifications, but it needs a client to send them to. This section describes what your own mobile application must do to receive push notifications from the device. All communication with the device goes through the IAM module CoAP endpoints, invoked using the Nabto Edge Client SDK for your platform.
Step 1: Integrate Firebase in your app
Add your app to the Firebase project created above and integrate the FCM client SDK following the Firebase guides for Android or iOS. Once integrated, the FCM SDK provides a registration token that uniquely identifies the app installation. Your app must be able to retrieve this token and must handle the FCM callback invoked when the token is refreshed.
Step 2: Pair with the device
The device example uses the local open pairing mode, so the client must run on the same LAN as the desktop based device application while pairing. Once paired, remote connections can be used. Pairing is done by invoking POST /iam/pairing/local-open, which the Android IAM Util and iOS IAM Util helper libraries wrap in a pairLocalOpen() function. The username chosen during pairing can only contain lower case letters, numbers and the characters _, . and -.
Step 3: Send the FCM configuration to the device
With a paired connection, send the Firebase project ID and the FCM registration token to the device using PUT /iam/users/:username/fcm. The request body is a CBOR encoded map with the keys ProjectId and Token:
{
"ProjectId": "my-firebase-project",
"Token": "<FCM registration token>"
}
The device stores this configuration with the user, so it must be sent again whenever FCM refreshes the registration token.
Step 4: Subscribe to notification categories
The device example defines the three categories Info, Warn and Alert. Your app can list the categories available on the device using GET /iam/notification-categories and choose which ones to receive using PUT /iam/users/:username/notification-categories with a CBOR encoded array of category names as body. A user with no categories set only receives test notifications.
Step 5: Test the setup
To verify the configuration without triggering an event on the device, invoke POST /iam/users/:username/fcm-test. The device sends a test notification to the user through the basestation and returns the FCM response, so any configuration problem is reported directly to the app.
When the test notification arrives, go back to the device terminal and enter the letter of a category the user subscribed to. The notification should arrive on your mobile device shortly after.
Next Steps
You have now sent push notifications from a Nabto Edge device to your own application. The device example works with any Firebase project and any client following the steps above, so the same CoAP calls carry over unchanged when integrating push notifications into your own device application. The Simple Push device example shows how the device reads the stored FCM configuration and categories from the IAM module and sends a notification to matching users. The push notification introduction describes the overall flow and the IAM CoAP API reference documents all endpoints used above.
