You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+82-1Lines changed: 82 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -196,7 +196,88 @@ This function must be called in the `loop()` of the Arduino program. It continuo
196
196
197
197
#### `ember.channelWrite(channel, value)`
198
198
This function sends data to a specific channel in the Firebase Realtime Database. The first argument, `channel`, is the channel number (e.g., `EMBER_BUTTON_OFF`), and the second argument, `value`, is the data being sent. In the example, it's used to update the channel with the button status (e.g., turning the button OFF).
199
+
200
+
### FCM Notifications
201
+
202
+
The EmberIoT library also supports **Firebase Cloud Messaging (FCM)** for sending push notifications directly from your microcontroller to registered users or devices.
203
+
This allows your IoT device to send alerts, status updates, or messages to your mobile app or other connected devices through Firebase.
204
+
205
+
To learn how to configure your Firebase project and service account, refer to the [Firebase project setup tutorial](FIREBASE_SETUP.md).
206
+
207
+
#### Example: Sending a Simple Notification
208
+
209
+
````C++
210
+
#include <Arduino.h>
211
+
#include <EmberIotNotifications.h>
212
+
213
+
// Your Firebase service account email (created during setup)
This is the constructor that initializes the `FCMEmberNotifications` instance using your Firebase service account credentials.
250
+
It authenticates your device with Firebase Cloud Messaging, allowing it to send push notifications.
251
+
252
+
- `accountEmail`: The service account email created in your Firebase project.
253
+
- `privateKey`: The private key string associated with the service account (in PEM format).
254
+
255
+
#### `notifications.init(userUid)`
256
+
This function initializes the FCM notification service and defines the recipient of the messages.
257
+
258
+
- `userUid`: The Firebase Authentication User UID of the recipient. This is the unique user identifier from your Firebase project's Authentication section.
259
+
260
+
> **Note:**
261
+
> If you are already using other EmberIot functionality (such as the Data Channels),
262
+
> you should call `notifications.init()` **passing your existing `EmberIot` instance instead of the `userUid`**.
263
+
> This automatically links the notifications to the already initialized EmberIot instance, decreasing memory usage.
This optional function adds extra information about the device sending notifications.
267
+
268
+
- `deviceId`: The `DEVICE_ID` registered for this board in EmberIot. This allows the receiving app to know which device sent the notification.
269
+
- `titlePrefix`: A short text added as a prefix to every notification title sent from this device, helping distinguish messages between multiple devices.
270
+
271
+
#### `notifications.send(title, body)`
272
+
This function sends a Firebase Cloud Messaging notification with a specified title and message body to the user defined in `notifications.init()`.
273
+
274
+
- `title`: The title of the notification displayed to the user.
275
+
- `body`: The message content shown in the notification.
276
+
277
+
#### `notifications.loop()`
278
+
This function must be called inside the main `loop()` of your Arduino program.
279
+
It maintains the connection to the Firebase Cloud Messaging service and processes any pending background tasks required for notifications to work correctly.
280
+
200
281
## How it Works - What even is a Data Channel?
201
282
202
283
In this library, a data channel represents a stream of data received from a specific location in the Firebase Realtime Database.
@@ -211,4 +292,4 @@ To send updates, the library uses the same REST API to perform HTTP requests—m
211
292
212
293
- [X] Compatibility with ESP8266
213
294
- [ ] Add option for LAN communication, for when there's no network connection
0 commit comments