Skip to content

Commit

Permalink
Add Stream performance test example
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Jan 29, 2025
1 parent a83cf0f commit e672e94
Show file tree
Hide file tree
Showing 21 changed files with 462 additions and 328 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/mobizt/FirebaseClient/.github%2Fworkflows%2Fcompile_library.yml?logo=github&label=compile) [![Github Stars](https://img.shields.io/github/stars/mobizt/FirebaseClient?logo=github)](https://github.com/mobizt/FirebaseClient/stargazers) ![Github Issues](https://img.shields.io/github/issues/mobizt/FirebaseClient?logo=github)

![GitHub Release](https://img.shields.io/github/v/release/mobizt/FirebaseClient) ![Arduino](https://img.shields.io/badge/Arduino-v1.5.3-57C207?logo=arduino) ![PlatformIO](https://badges.registry.platformio.org/packages/mobizt/library/FirebaseClient.svg) ![GitHub Release Date](https://img.shields.io/github/release-date/mobizt/FirebaseClient)
![GitHub Release](https://img.shields.io/github/v/release/mobizt/FirebaseClient) ![Arduino](https://img.shields.io/badge/Arduino-v1.5.4-57C207?logo=arduino) ![PlatformIO](https://badges.registry.platformio.org/packages/mobizt/library/FirebaseClient.svg) ![GitHub Release Date](https://img.shields.io/github/release-date/mobizt/FirebaseClient)

[![GitHub Sponsors](https://img.shields.io/github/sponsors/mobizt?logo=github)](https://github.com/sponsors/mobizt)

Expand Down Expand Up @@ -802,17 +802,15 @@ If the size of payload string from the async reseut is large, to access the inte

<br>

The `SSE mode (HTTP Streaming)` event payload might contain many events data due to the events are constantly changing. The data in this case can be obtained from the specific index.

The specific `Realtime Database` server response payload and `SSE mode (HTTP Streaming)` event data (`RealtimeDatabaseResult`) can be obtained from `AsyncResult::to<RealtimeDatabaseResult>()` which are included the following.

- `bool RealtimeDatabaseResult::isStream()` returns true if the result is from `SSE mode (HTTP Streaming)` task.

- `String RealtimeDatabaseResult::event(<index>)` returns the `SSE mode (HTTP Streaming)` event type strings at the specific index which included `put`, `patch`, `keep-alive`, `cancel` and `auth_revoked`.
- `String RealtimeDatabaseResult::event()` returns the `SSE mode (HTTP Streaming)` event type strings include `put`, `patch`, `keep-alive`, `cancel` and `auth_revoked`.

- `String RealtimeDatabaseResult::dataPath(<index>)` returns the `SSE mode (HTTP Streaming)` event data path (at the specific index) which is the relative path of the changed value in the database. The absolute path of the changed value can be obtained from the concatenation of `AsyncResult::path()` and `RealtimeDatabaseResult::dataPath(<index>)` e.g. `AsyncResult::path() + "/" + RealtimeDatabaseResult::dataPath(<index>)`.
- `String RealtimeDatabaseResult::dataPath()` returns the `SSE mode (HTTP Streaming)` event data path which is the relative path of the changed value in the database. The absolute path of the changed value can be obtained from the concatenation of `AsyncResult::path()` and `RealtimeDatabaseResult::dataPath()` e.g. `AsyncResult::path() + "/" + RealtimeDatabaseResult::dataPath()`.

- `realtime_database_data_type RealtimeDatabaseResult::type(<index>)` returns the `realtime_database_data_type` enum (see below) at the specific index represents the type of `Realtime Database` response payload and event data (`HTTP Streaming`).
- `realtime_database_data_type RealtimeDatabaseResult::type()` returns the `realtime_database_data_type` enum (see below) represents the type of `Realtime Database` response payload and event data (`HTTP Streaming`).

- `RealtimeDatabaseResult::name()` returns the name (random UID) of the node that will be creaated after from `RealtimeDatabase::Push`.

Expand Down Expand Up @@ -2032,6 +2030,7 @@ The following section will provide the basic (bare minimum) code example and the
* [SimpleNoAuth](/examples/RealtimeDatabase/Simple/SimpleNoAuth/)
* [StreamDatabaseSecret](/examples/RealtimeDatabase/Simple/StreamDatabaseSecret/)
* [StreamNoAuth](/examples/RealtimeDatabase/Simple/StreamNoAuth/)
* [Simple](/examples/RealtimeDatabase/StreamPerformanceTest/)
* [Sync](/examples/RealtimeDatabase/Sync/)
* [CustomPushID](/examples/RealtimeDatabase/Sync/CustomPushID/)
* [ETAG](/examples/RealtimeDatabase/Sync/ETAG/)
Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@
│ │ ├───SimpleNoAuth
│ │ ├───StreamDatabaseSecret
│ │ └───StreamNoAuth
│ ├───StreamPerformancetest
│ └───Sync
│ ├───CustomPushID
│ ├───ETAG
Expand Down
32 changes: 12 additions & 20 deletions examples/RealtimeDatabase/Async/Callback/Stream/Stream.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* ABOUT:
*
* The non-blocking (async) example to listen to the changes of value (from a node) stores in your database
* The non-blocking (async) example to listen to the changes of value (from a node) stores in your database
* via SSE Streaming connection.
*
* This example uses the UserAuth class for authentication, and the DefaultNetwork class for network interface configuration.
Expand Down Expand Up @@ -195,25 +195,17 @@ void printResult(AsyncResult &aResult)
{
Serial.println("----------------------------");
Firebase.printf("task: %s\n", aResult.uid().c_str());

// The Stream payload might contain many events data due to
// the events are constantly changing.
Firebase.printf("event count: %d\n", RTDB.eventCount());
for (uint32_t i = 0; i < RTDB.eventCount(); i++)
{
Firebase.printf("event: %s\n", RTDB.event(i).c_str());
Firebase.printf("path: %s\n", RTDB.dataPath(i).c_str());
Firebase.printf("data: %s\n", RTDB.to<const char *>(i));
Firebase.printf("type: %d\n", RTDB.type(i));
Serial.println();

// The stream event from RealtimeDatabaseResult can be converted to the values as following.
bool v1 = RTDB.to<bool>(i);
int v2 = RTDB.to<int>(i);
float v3 = RTDB.to<float>(i);
double v4 = RTDB.to<double>(i);
String v5 = RTDB.to<String>(i);
}
Firebase.printf("event: %s\n", RTDB.event().c_str());
Firebase.printf("path: %s\n", RTDB.dataPath().c_str());
Firebase.printf("data: %s\n", RTDB.to<const char *>());
Firebase.printf("type: %d\n", RTDB.type());

// The stream event from RealtimeDatabaseResult can be converted to the values as following.
bool v1 = RTDB.to<bool>();
int v2 = RTDB.to<int>();
float v3 = RTDB.to<float>();
double v4 = RTDB.to<double>();
String v5 = RTDB.to<String>();
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* ABOUT:
*
* The non-blocking (async) example to listen to the changes of values (from various nodes) store in your database
* The non-blocking (async) example to listen to the changes of values (from various nodes) store in your database
* via SSE Streaming connection.
*
* This example uses the UserAuth class for authentication, and the DefaultNetwork class for network interface configuration.
Expand Down Expand Up @@ -212,25 +212,17 @@ void printResult(AsyncResult &aResult)
{
Serial.println("----------------------------");
Firebase.printf("task: %s\n", aResult.uid().c_str());

// The Stream payload might contain many events data due to
// the events are constantly changing.
Firebase.printf("event count: %d\n", RTDB.eventCount());
for (uint32_t i = 0; i < RTDB.eventCount(); i++)
{
Firebase.printf("event: %s\n", RTDB.event(i).c_str());
Firebase.printf("path: %s\n", RTDB.dataPath(i).c_str());
Firebase.printf("data: %s\n", RTDB.to<const char *>(i));
Firebase.printf("type: %d\n", RTDB.type(i));
Serial.println();

// The stream event from RealtimeDatabaseResult can be converted to the values as following.
bool v1 = RTDB.to<bool>(i);
int v2 = RTDB.to<int>(i);
float v3 = RTDB.to<float>(i);
double v4 = RTDB.to<double>(i);
String v5 = RTDB.to<String>(i);
}
Firebase.printf("event: %s\n", RTDB.event().c_str());
Firebase.printf("path: %s\n", RTDB.dataPath().c_str());
Firebase.printf("data: %s\n", RTDB.to<const char *>());
Firebase.printf("type: %d\n", RTDB.type());

// The stream event from RealtimeDatabaseResult can be converted to the values as following.
bool v1 = RTDB.to<bool>();
int v2 = RTDB.to<int>();
float v3 = RTDB.to<float>();
double v4 = RTDB.to<double>();
String v5 = RTDB.to<String>();
}
else
{
Expand Down
30 changes: 11 additions & 19 deletions examples/RealtimeDatabase/Async/Callback/StreamGSM/StreamGSM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -248,25 +248,17 @@ void printResult(AsyncResult &aResult)
{
Serial.println("----------------------------");
Firebase.printf("task: %s\n", aResult.uid().c_str());

// The Stream payload might contain many events data due to
// the events are constantly changing.
Firebase.printf("event count: %d\n", RTDB.eventCount());
for (uint32_t i = 0; i < RTDB.eventCount(); i++)
{
Firebase.printf("event: %s\n", RTDB.event(i).c_str());
Firebase.printf("path: %s\n", RTDB.dataPath(i).c_str());
Firebase.printf("data: %s\n", RTDB.to<const char *>(i));
Firebase.printf("type: %d\n", RTDB.type(i));
Serial.println();

// The stream event from RealtimeDatabaseResult can be converted to the values as following.
bool v1 = RTDB.to<bool>(i);
int v2 = RTDB.to<int>(i);
float v3 = RTDB.to<float>(i);
double v4 = RTDB.to<double>(i);
String v5 = RTDB.to<String>(i);
}
Firebase.printf("event: %s\n", RTDB.event().c_str());
Firebase.printf("path: %s\n", RTDB.dataPath().c_str());
Firebase.printf("data: %s\n", RTDB.to<const char *>());
Firebase.printf("type: %d\n", RTDB.type());

// The stream event from RealtimeDatabaseResult can be converted to the values as following.
bool v1 = RTDB.to<bool>();
int v2 = RTDB.to<int>();
float v3 = RTDB.to<float>();
double v4 = RTDB.to<double>();
String v5 = RTDB.to<String>();
}
else
{
Expand Down
30 changes: 11 additions & 19 deletions examples/RealtimeDatabase/Async/Callback/StreamPPP/StreamPPP.ino
Original file line number Diff line number Diff line change
Expand Up @@ -317,25 +317,17 @@ void printResult(AsyncResult &aResult)
{
Serial.println("----------------------------");
Firebase.printf("task: %s\n", aResult.uid().c_str());

// The Stream payload might contain many events data due to
// the events are constantly changing.
Firebase.printf("event count: %d\n", RTDB.eventCount());
for (uint32_t i = 0; i < RTDB.eventCount(); i++)
{
Firebase.printf("event: %s\n", RTDB.event(i).c_str());
Firebase.printf("path: %s\n", RTDB.dataPath(i).c_str());
Firebase.printf("data: %s\n", RTDB.to<const char *>(i));
Firebase.printf("type: %d\n", RTDB.type(i));
Serial.println();

// The stream event from RealtimeDatabaseResult can be converted to the values as following.
bool v1 = RTDB.to<bool>(i);
int v2 = RTDB.to<int>(i);
float v3 = RTDB.to<float>(i);
double v4 = RTDB.to<double>(i);
String v5 = RTDB.to<String>(i);
}
Firebase.printf("event: %s\n", RTDB.event().c_str());
Firebase.printf("path: %s\n", RTDB.dataPath().c_str());
Firebase.printf("data: %s\n", RTDB.to<const char *>());
Firebase.printf("type: %d\n", RTDB.type());

// The stream event from RealtimeDatabaseResult can be converted to the values as following.
bool v1 = RTDB.to<bool>();
int v2 = RTDB.to<int>();
float v3 = RTDB.to<float>();
double v4 = RTDB.to<double>();
String v5 = RTDB.to<String>();
}
else
{
Expand Down
30 changes: 11 additions & 19 deletions examples/RealtimeDatabase/Async/NoCallback/Stream/Stream.ino
Original file line number Diff line number Diff line change
Expand Up @@ -196,25 +196,17 @@ void printResult(AsyncResult &aResult)
{
Serial.println("----------------------------");
Firebase.printf("task: %s\n", aResult.uid().c_str());

// The Stream payload might contain many events data due to
// the events are constantly changing.
Firebase.printf("event count: %d\n", RTDB.eventCount());
for (uint32_t i = 0; i < RTDB.eventCount(); i++)
{
Firebase.printf("event: %s\n", RTDB.event(i).c_str());
Firebase.printf("path: %s\n", RTDB.dataPath(i).c_str());
Firebase.printf("data: %s\n", RTDB.to<const char *>(i));
Firebase.printf("type: %d\n", RTDB.type(i));
Serial.println();

// The stream event from RealtimeDatabaseResult can be converted to the values as following.
bool v1 = RTDB.to<bool>(i);
int v2 = RTDB.to<int>(i);
float v3 = RTDB.to<float>(i);
double v4 = RTDB.to<double>(i);
String v5 = RTDB.to<String>(i);
}
Firebase.printf("event: %s\n", RTDB.event().c_str());
Firebase.printf("path: %s\n", RTDB.dataPath().c_str());
Firebase.printf("data: %s\n", RTDB.to<const char *>());
Firebase.printf("type: %d\n", RTDB.type());

// The stream event from RealtimeDatabaseResult can be converted to the values as following.
bool v1 = RTDB.to<bool>();
int v2 = RTDB.to<int>();
float v3 = RTDB.to<float>();
double v4 = RTDB.to<double>();
String v5 = RTDB.to<String>();
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,25 +211,17 @@ void printResult(AsyncResult &aResult)
{
Serial.println("----------------------------");
Firebase.printf("task: %s\n", aResult.uid().c_str());

// The Stream payload might contain many events data due to
// the events are constantly changing.
Firebase.printf("event count: %d\n", RTDB.eventCount());
for (uint32_t i = 0; i < RTDB.eventCount(); i++)
{
Firebase.printf("event: %s\n", RTDB.event(i).c_str());
Firebase.printf("path: %s\n", RTDB.dataPath(i).c_str());
Firebase.printf("data: %s\n", RTDB.to<const char *>(i));
Firebase.printf("type: %d\n", RTDB.type(i));
Serial.println();

// The stream event from RealtimeDatabaseResult can be converted to the values as following.
bool v1 = RTDB.to<bool>(i);
int v2 = RTDB.to<int>(i);
float v3 = RTDB.to<float>(i);
double v4 = RTDB.to<double>(i);
String v5 = RTDB.to<String>(i);
}
Firebase.printf("event: %s\n", RTDB.event().c_str());
Firebase.printf("path: %s\n", RTDB.dataPath().c_str());
Firebase.printf("data: %s\n", RTDB.to<const char *>());
Firebase.printf("type: %d\n", RTDB.type());

// The stream event from RealtimeDatabaseResult can be converted to the values as following.
bool v1 = RTDB.to<bool>();
int v2 = RTDB.to<int>();
float v3 = RTDB.to<float>();
double v4 = RTDB.to<double>();
String v5 = RTDB.to<String>();
}
else
{
Expand Down
30 changes: 11 additions & 19 deletions examples/RealtimeDatabase/Async/NoCallback/StreamGSM/StreamGSM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -247,25 +247,17 @@ void printResult(AsyncResult &aResult)
{
Serial.println("----------------------------");
Firebase.printf("task: %s\n", aResult.uid().c_str());

// The Stream payload might contain many events data due to
// the events are constantly changing.
Firebase.printf("event count: %d\n", RTDB.eventCount());
for (uint32_t i = 0; i < RTDB.eventCount(); i++)
{
Firebase.printf("event: %s\n", RTDB.event(i).c_str());
Firebase.printf("path: %s\n", RTDB.dataPath(i).c_str());
Firebase.printf("data: %s\n", RTDB.to<const char *>(i));
Firebase.printf("type: %d\n", RTDB.type(i));
Serial.println();

// The stream event from RealtimeDatabaseResult can be converted to the values as following.
bool v1 = RTDB.to<bool>(i);
int v2 = RTDB.to<int>(i);
float v3 = RTDB.to<float>(i);
double v4 = RTDB.to<double>(i);
String v5 = RTDB.to<String>(i);
}
Firebase.printf("event: %s\n", RTDB.event().c_str());
Firebase.printf("path: %s\n", RTDB.dataPath().c_str());
Firebase.printf("data: %s\n", RTDB.to<const char *>());
Firebase.printf("type: %d\n", RTDB.type());

// The stream event from RealtimeDatabaseResult can be converted to the values as following.
bool v1 = RTDB.to<bool>();
int v2 = RTDB.to<int>();
float v3 = RTDB.to<float>();
double v4 = RTDB.to<double>();
String v5 = RTDB.to<String>();
}
else
{
Expand Down
30 changes: 11 additions & 19 deletions examples/RealtimeDatabase/Async/NoCallback/StreamPPP/StreamPPP.ino
Original file line number Diff line number Diff line change
Expand Up @@ -318,25 +318,17 @@ void printResult(AsyncResult &aResult)
{
Serial.println("----------------------------");
Firebase.printf("task: %s\n", aResult.uid().c_str());

// The Stream payload might contain many events data due to
// the events are constantly changing.
Firebase.printf("event count: %d\n", RTDB.eventCount());
for (uint32_t i = 0; i < RTDB.eventCount(); i++)
{
Firebase.printf("event: %s\n", RTDB.event(i).c_str());
Firebase.printf("path: %s\n", RTDB.dataPath(i).c_str());
Firebase.printf("data: %s\n", RTDB.to<const char *>(i));
Firebase.printf("type: %d\n", RTDB.type(i));
Serial.println();

// The stream event from RealtimeDatabaseResult can be converted to the values as following.
bool v1 = RTDB.to<bool>(i);
int v2 = RTDB.to<int>(i);
float v3 = RTDB.to<float>(i);
double v4 = RTDB.to<double>(i);
String v5 = RTDB.to<String>(i);
}
Firebase.printf("event: %s\n", RTDB.event().c_str());
Firebase.printf("path: %s\n", RTDB.dataPath().c_str());
Firebase.printf("data: %s\n", RTDB.to<const char *>());
Firebase.printf("type: %d\n", RTDB.type());

// The stream event from RealtimeDatabaseResult can be converted to the values as following.
bool v1 = RTDB.to<bool>();
int v2 = RTDB.to<int>();
float v3 = RTDB.to<float>();
double v4 = RTDB.to<double>();
String v5 = RTDB.to<String>();
}
else
{
Expand Down
Loading

0 comments on commit e672e94

Please sign in to comment.