Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 72bb39e

Browse files
committed
Added example for cloud messaging.
1 parent 72fb881 commit 72bb39e

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//
2+
// Copyright 2015 Google Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
// FirebaseCloudMessaging_Send_ESP8266 is a sample that shows sending
18+
// messages to firebase.
19+
20+
#include <ESP8266WiFi.h>
21+
22+
#include <FirebaseCloudMessaging.h>
23+
#include <FirebaseHttpClient.h>
24+
25+
// Set these to run example.
26+
#define WIFI_SSID "SSID"
27+
#define WIFI_PASSWORD "PASSWORD"
28+
29+
#define SERVER_KEY "key_from_dashboard"
30+
#define CLIENT_REGISTRATION_ID "key_from_client_after_registration"
31+
32+
void setup() {
33+
Serial.begin(9600);
34+
35+
// connect to wifi.
36+
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
37+
Serial.print("connecting");
38+
while (WiFi.status() != WL_CONNECTED) {
39+
Serial.print(".");
40+
delay(500);
41+
}
42+
Serial.println();
43+
Serial.print("connected: ");
44+
Serial.println(WiFi.localIP());
45+
46+
FirebaseCloudMessaging fcm(SERVER_KEY);
47+
FirebaseCloudMessage message =
48+
FirebaseCloudMessage::SimpleNotification("Hello World!", "What's happening?");
49+
FirebaseError error = fcm.SendMessageToUser(CLIENT_REGISTRATION_ID, message);
50+
if (error) {
51+
Serial.print("Error:");
52+
Serial.print(error.code());
53+
Serial.print(" :: ");
54+
Serial.println(error.message().c_str());
55+
} else {
56+
Serial.println("Sent OK!");
57+
}
58+
}
59+
60+
void loop() {
61+
}
62+

0 commit comments

Comments
 (0)