|
| 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 | +#defineWIFI_SSID"SSID" |
| 27 | +#defineWIFI_PASSWORD"PASSWORD" |
| 28 | + |
| 29 | +#defineSERVER_KEY"key_from_dashboard" |
| 30 | +#defineCLIENT_REGISTRATION_ID"key_from_client_after_registration" |
| 31 | + |
| 32 | +voidsetup() { |
| 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 | + FirebaseCloudMessagingfcm(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 | +voidloop() { |
| 61 | +} |
| 62 | + |