From 01fa33e5ae1cddd57b7f3453ed14da9cdfb7685a Mon Sep 17 00:00:00 2001 From: suwatchai Date: Sat, 4 May 2019 12:18:21 +0700 Subject: [PATCH] Add support FCM --- src/FirebaseESP8266.cpp | 11 ++++++++--- src/FirebaseESP8266.h | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/FirebaseESP8266.cpp b/src/FirebaseESP8266.cpp index ab087e96..de759d7c 100644 --- a/src/FirebaseESP8266.cpp +++ b/src/FirebaseESP8266.cpp @@ -3215,7 +3215,7 @@ bool FirebaseESP8266::sendFCMMessage(FirebaseData &dataObj, uint8_t messageType) if (dataObj._http.http_connected()) forceEndHTTP(dataObj); - res = dataObj.fcm.fcm_connect(dataObj._http, _host, _port); + res = dataObj.fcm.fcm_connect(dataObj._http); if (!res) { @@ -4623,9 +4623,14 @@ String FCMObject::getSendResult() return _sendResult.c_str(); } -bool FCMObject::fcm_connect(FirebaseHTTPClient &netClient, const std::string &host, uint16_t port) +bool FCMObject::fcm_connect(FirebaseHTTPClient &netClient) { - int httpConnected = netClient.http_begin(ESP8266_FIREBASE_STR_120, port); + char *host = new char[100]; + memset(host, 0, 100); + strcpy_P(host, ESP8266_FIREBASE_STR_120); + int httpConnected = netClient.http_begin(host, _port); + + delete[] host; if (!httpConnected) return false; diff --git a/src/FirebaseESP8266.h b/src/FirebaseESP8266.h index 7e365523..a087fce2 100644 --- a/src/FirebaseESP8266.h +++ b/src/FirebaseESP8266.h @@ -364,7 +364,7 @@ class FCMObject friend FirebaseData; private: - bool fcm_connect(FirebaseHTTPClient &netClient, const std::string &host, uint16_t port); + bool fcm_connect(FirebaseHTTPClient &netClient); bool fcm_send(FirebaseHTTPClient &netClient, int &httpcode, uint8_t messageType); @@ -391,6 +391,7 @@ class FCMObject std::string _sendResult = ""; int _ttl = -1; uint16_t _index = 0; + uint16_t _port = 443; std::vector _deviceToken; };