Skip to content

Commit

Permalink
Update callFunction in Cloud Functions for Firebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed May 22, 2021
1 parent 91f0e0a commit fa587b5
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 19 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Firebase Arduino Client Library for ESP8266 and ESP32


Google's Firebase Arduino Client Library for ESP8266 and ESP32 v2.2.2
Google's Firebase Arduino Client Library for ESP8266 and ESP32 v2.2.3


This library supports ESP8266 and ESP32 MCU from Espressif. The following are platforms in which the libraries are also available (RTDB only).
Expand Down Expand Up @@ -254,6 +254,8 @@ The supportedd MMU build flags in PlatformIO.

Disables default configuration and expects user-specified flags



### Test code for MMU

```cpp
Expand Down
17 changes: 15 additions & 2 deletions examples/CloudFunctions/CallFunction/CallFunction.ino
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void setup()
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h

Firebase.begin(&config, &auth);

Firebase.reconnectWiFi(true);
}

Expand All @@ -121,9 +121,22 @@ void callFunction()
{
//Assumed that the function named helloWorld is already created and deployed for project.

//In the function script file, values can be obtained from http trigger function request e.g. req as following.
//req.body.info.name
//req.body.info.age

//See the index.js in helloWorld.zip in CreateFunctionWithCallback

Serial.print("Call the Cloud Function... ");

if (Firebase.Functions.callFunction(&fbdo, FIREBASE_PROJECT_ID /* project id */, PROJECT_LOCATION /* location id */, "helloWorld" /* function name */, "" /* data pass to Cloud function */))
FirebaseJson json;
json.set("info/name", "Paul");
json.set("info/age", 30);

String payload;
json.toString(payload);

if (Firebase.Functions.callFunction(&fbdo, FIREBASE_PROJECT_ID /* project id */, PROJECT_LOCATION /* location id */, "helloWorld" /* function name */, payload.c_str() /* data pass to Cloud function (serialized JSON string) */))
Serial.printf("ok\n%s\n\n", fbdo.payload().c_str());
else
Serial.println(fbdo.errorReason());
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Firebase Arduino Client Library for ESP8266 and ESP32",
"version": "2.2.2",
"version": "2.2.3",
"keywords": "communication, REST, esp32, esp8266, arduino",
"description": "This client library provides the functions to work with Firebase Realtime database, Firestore, Storage and Cloud messaging.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=Firebase Arduino Client Library for ESP8266 and ESP32

version=2.2.2
version=2.2.3

author=Mobizt

Expand Down
4 changes: 2 additions & 2 deletions src/Firebase_ESP_Client.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Google's Firebase ESP Client Main class, Firebase_ESP_Client.cpp v2.2.2
* Google's Firebase ESP Client Main class, Firebase_ESP_Client.cpp v2.2.3
*
* This library supports Espressif ESP8266 and ESP32
*
* Created May 19, 2021
* Created May 22, 2021
*
* This work is a part of Firebase ESP Client library
* Copyright (c) 2021 K. Suwatchai (Mobizt)
Expand Down
6 changes: 3 additions & 3 deletions src/Firebase_ESP_Client.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#ifndef FIREBASE_CLIENT_VERSION
#define FIREBASE_CLIENT_VERSION "2.2.2"
#define FIREBASE_CLIENT_VERSION "2.2.3"
#endif

/**
* Google's Firebase ESP Client Main class, Firebase_ESP_Client.h v2.2.2
* Google's Firebase ESP Client Main class, Firebase_ESP_Client.h v2.2.3
*
* This library supports Espressif ESP8266 and ESP32
*
* Created May 19, 2021
* Created May 22, 2021
*
* This work is a part of Firebase ESP Client library
* Copyright (c) 2021 K. Suwatchai (Mobizt)
Expand Down
12 changes: 10 additions & 2 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Firebase Arduino Client Library for ESP8266 and ESP32


Google's Firebase Arduino Client Library for ESP8266 and ESP32 v2.2.2
Google's Firebase Arduino Client Library for ESP8266 and ESP32 v2.2.3


The default filessystem used in the library is flash and SD.
Expand Down Expand Up @@ -4077,12 +4077,20 @@ param **`locationId`** The project location.

param **`functionId`** The name of function.

param **`data`** The Input to be passed to the function.
param **`data`** The Input to be passed to the function (JSON serialized string).

return **`Boolean`** value, indicates the success of the operation.

Use FirebaseData.payload() to get the returned payload.

Ex. if data is {"info":{"name":"Paul","age":30}}

The values can be obtained from http trigger function request e.g. req as following.

req.body.info.name

req.body.info.age

This function requires OAuth2.0 authentication.

```cpp
Expand Down
1 change: 1 addition & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,7 @@ static const char fb_esp_pgm_str_566[] PROGMEM = "currentDocument";
static const char fb_esp_pgm_str_567[] PROGMEM = "updateTransforms";
static const char fb_esp_pgm_str_568[] PROGMEM = "transform";
static const char fb_esp_pgm_str_569[] PROGMEM = "exists";
static const char fb_esp_pgm_str_570[] PROGMEM = "\\\"";
#endif

static const unsigned char fb_esp_base64_table[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
Expand Down
13 changes: 10 additions & 3 deletions src/functions/FB_Functions.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Google's Cloud Functions class, Functions.cpp version 1.0.7
* Google's Cloud Functions class, Functions.cpp version 1.0.8
*
* This library supports Espressif ESP8266 and ESP32
*
* Created May 4, 2021
* Created May 22, 2021
*
* This work is a part of Firebase ESP Client library
* Copyright (c) 2021 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -50,9 +50,16 @@ bool FB_Functions::callFunction(FirebaseData *fbdo, const char *projectId, const
req.locationId = locationId;
req.functionId = functionId;

std::string find;
ut->appendP(find, fb_esp_pgm_str_3);
std::string replace;
ut->appendP(replace, fb_esp_pgm_str_570);
req.payload = data;
ut->replaceAll(req.payload, find, replace);

char *tmp = ut->strP(fb_esp_pgm_str_135);
fbdo->_ss.json.clear();
fbdo->_ss.json.add(tmp, data);
fbdo->_ss.json.add(tmp, req.payload.c_str());
fbdo->_ss.json.int_tostr(req.payload);
fbdo->_ss.json.clear();
ut->delS(tmp);
Expand Down
14 changes: 10 additions & 4 deletions src/functions/FB_Functions.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Google's Cloud Functions class, Functions.h version 1.0.7
* Google's Cloud Functions class, Functions.h version 1.0.8
*
* This library supports Espressif ESP8266 and ESP32
*
* Created May 4, 2021
* Created May 22, 2021
*
* This work is a part of Firebase ESP Client library
* Copyright (c) 2021 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -54,12 +54,18 @@ class FB_Functions
* @param projectId The Firebase project id (only the name without the firebaseio.com).
* @param locationId The project location.
* @param functionId The name of function.
* @param data The Input to be passed to the function.
* @param data The Input to be passed to the function (JSON serialized string).
*
* @return Boolean value, indicates the success of the operation.
*
* @note Use FirebaseData.payload() to get the returned payload.
*
* Ex. if data is {"info":{"name":"Paul","age":30}}
*
* The values can be obtained from http trigger function request e.g. req as following.
* req.body.info.name
* req.body.info.age
*
* This function requires OAuth2.0 authentication.
*
*/
Expand Down

0 comments on commit fa587b5

Please sign in to comment.