Skip to content

Commit a83cf0f

Browse files
committed
Fix multiple Stream events parsing issue
1 parent 0bbe7af commit a83cf0f

19 files changed

Lines changed: 365 additions & 215 deletions

File tree

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
![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)
44

5-
![GitHub Release](https://img.shields.io/github/v/release/mobizt/FirebaseClient) ![Arduino](https://img.shields.io/badge/Arduino-v1.5.2-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)
5+
![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)
66

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

9-
Revision `2025-01-28`
9+
Revision `2025-01-29`
1010

1111
## Table of Contents
1212

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

803803
<br>
804804

805+
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.
806+
805807
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.
806808

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

809-
- `String RealtimeDatabaseResult::event()` returns the `SSE mode (HTTP Streaming)` event type strings include `put`, `patch`, `keep-alive`, `cancel` and `auth_revoked`.
811+
- `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`.
810812

811-
- `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()`.
813+
- `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>)`.
812814

813-
- `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`).
815+
- `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`).
814816

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

examples/RealtimeDatabase/Async/Callback/Stream/Stream.ino

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* ABOUT:
33
*
4-
* The non-blocking (async) example to listen to the changes of value (from a node) stores in your database
4+
* The non-blocking (async) example to listen to the changes of value (from a node) stores in your database
55
* via SSE Streaming connection.
66
*
77
* This example uses the UserAuth class for authentication, and the DefaultNetwork class for network interface configuration.
@@ -195,17 +195,25 @@ void printResult(AsyncResult &aResult)
195195
{
196196
Serial.println("----------------------------");
197197
Firebase.printf("task: %s\n", aResult.uid().c_str());
198-
Firebase.printf("event: %s\n", RTDB.event().c_str());
199-
Firebase.printf("path: %s\n", RTDB.dataPath().c_str());
200-
Firebase.printf("data: %s\n", RTDB.to<const char *>());
201-
Firebase.printf("type: %d\n", RTDB.type());
202-
203-
// The stream event from RealtimeDatabaseResult can be converted to the values as following.
204-
bool v1 = RTDB.to<bool>();
205-
int v2 = RTDB.to<int>();
206-
float v3 = RTDB.to<float>();
207-
double v4 = RTDB.to<double>();
208-
String v5 = RTDB.to<String>();
198+
199+
// The Stream payload might contain many events data due to
200+
// the events are constantly changing.
201+
Firebase.printf("event count: %d\n", RTDB.eventCount());
202+
for (uint32_t i = 0; i < RTDB.eventCount(); i++)
203+
{
204+
Firebase.printf("event: %s\n", RTDB.event(i).c_str());
205+
Firebase.printf("path: %s\n", RTDB.dataPath(i).c_str());
206+
Firebase.printf("data: %s\n", RTDB.to<const char *>(i));
207+
Firebase.printf("type: %d\n", RTDB.type(i));
208+
Serial.println();
209+
210+
// The stream event from RealtimeDatabaseResult can be converted to the values as following.
211+
bool v1 = RTDB.to<bool>(i);
212+
int v2 = RTDB.to<int>(i);
213+
float v3 = RTDB.to<float>(i);
214+
double v4 = RTDB.to<double>(i);
215+
String v5 = RTDB.to<String>(i);
216+
}
209217
}
210218
else
211219
{

examples/RealtimeDatabase/Async/Callback/StreamConcurentcy/StreamConcurentcy.ino

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* ABOUT:
33
*
4-
* The non-blocking (async) example to listen to the changes of values (from various nodes) store in your database
4+
* The non-blocking (async) example to listen to the changes of values (from various nodes) store in your database
55
* via SSE Streaming connection.
66
*
77
* This example uses the UserAuth class for authentication, and the DefaultNetwork class for network interface configuration.
@@ -212,17 +212,25 @@ void printResult(AsyncResult &aResult)
212212
{
213213
Serial.println("----------------------------");
214214
Firebase.printf("task: %s\n", aResult.uid().c_str());
215-
Firebase.printf("event: %s\n", RTDB.event().c_str());
216-
Firebase.printf("path: %s\n", RTDB.dataPath().c_str());
217-
Firebase.printf("data: %s\n", RTDB.to<const char *>());
218-
Firebase.printf("type: %d\n", RTDB.type());
219-
220-
// The stream event from RealtimeDatabaseResult can be converted to the values as following.
221-
bool v1 = RTDB.to<bool>();
222-
int v2 = RTDB.to<int>();
223-
float v3 = RTDB.to<float>();
224-
double v4 = RTDB.to<double>();
225-
String v5 = RTDB.to<String>();
215+
216+
// The Stream payload might contain many events data due to
217+
// the events are constantly changing.
218+
Firebase.printf("event count: %d\n", RTDB.eventCount());
219+
for (uint32_t i = 0; i < RTDB.eventCount(); i++)
220+
{
221+
Firebase.printf("event: %s\n", RTDB.event(i).c_str());
222+
Firebase.printf("path: %s\n", RTDB.dataPath(i).c_str());
223+
Firebase.printf("data: %s\n", RTDB.to<const char *>(i));
224+
Firebase.printf("type: %d\n", RTDB.type(i));
225+
Serial.println();
226+
227+
// The stream event from RealtimeDatabaseResult can be converted to the values as following.
228+
bool v1 = RTDB.to<bool>(i);
229+
int v2 = RTDB.to<int>(i);
230+
float v3 = RTDB.to<float>(i);
231+
double v4 = RTDB.to<double>(i);
232+
String v5 = RTDB.to<String>(i);
233+
}
226234
}
227235
else
228236
{

examples/RealtimeDatabase/Async/Callback/StreamGSM/StreamGSM.ino

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,25 @@ void printResult(AsyncResult &aResult)
248248
{
249249
Serial.println("----------------------------");
250250
Firebase.printf("task: %s\n", aResult.uid().c_str());
251-
Firebase.printf("event: %s\n", RTDB.event().c_str());
252-
Firebase.printf("path: %s\n", RTDB.dataPath().c_str());
253-
Firebase.printf("data: %s\n", RTDB.to<const char *>());
254-
Firebase.printf("type: %d\n", RTDB.type());
255-
256-
// The stream event from RealtimeDatabaseResult can be converted to the values as following.
257-
bool v1 = RTDB.to<bool>();
258-
int v2 = RTDB.to<int>();
259-
float v3 = RTDB.to<float>();
260-
double v4 = RTDB.to<double>();
261-
String v5 = RTDB.to<String>();
251+
252+
// The Stream payload might contain many events data due to
253+
// the events are constantly changing.
254+
Firebase.printf("event count: %d\n", RTDB.eventCount());
255+
for (uint32_t i = 0; i < RTDB.eventCount(); i++)
256+
{
257+
Firebase.printf("event: %s\n", RTDB.event(i).c_str());
258+
Firebase.printf("path: %s\n", RTDB.dataPath(i).c_str());
259+
Firebase.printf("data: %s\n", RTDB.to<const char *>(i));
260+
Firebase.printf("type: %d\n", RTDB.type(i));
261+
Serial.println();
262+
263+
// The stream event from RealtimeDatabaseResult can be converted to the values as following.
264+
bool v1 = RTDB.to<bool>(i);
265+
int v2 = RTDB.to<int>(i);
266+
float v3 = RTDB.to<float>(i);
267+
double v4 = RTDB.to<double>(i);
268+
String v5 = RTDB.to<String>(i);
269+
}
262270
}
263271
else
264272
{

examples/RealtimeDatabase/Async/Callback/StreamPPP/StreamPPP.ino

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -317,17 +317,25 @@ void printResult(AsyncResult &aResult)
317317
{
318318
Serial.println("----------------------------");
319319
Firebase.printf("task: %s\n", aResult.uid().c_str());
320-
Firebase.printf("event: %s\n", RTDB.event().c_str());
321-
Firebase.printf("path: %s\n", RTDB.dataPath().c_str());
322-
Firebase.printf("data: %s\n", RTDB.to<const char *>());
323-
Firebase.printf("type: %d\n", RTDB.type());
324-
325-
// The stream event from RealtimeDatabaseResult can be converted to the values as following.
326-
bool v1 = RTDB.to<bool>();
327-
int v2 = RTDB.to<int>();
328-
float v3 = RTDB.to<float>();
329-
double v4 = RTDB.to<double>();
330-
String v5 = RTDB.to<String>();
320+
321+
// The Stream payload might contain many events data due to
322+
// the events are constantly changing.
323+
Firebase.printf("event count: %d\n", RTDB.eventCount());
324+
for (uint32_t i = 0; i < RTDB.eventCount(); i++)
325+
{
326+
Firebase.printf("event: %s\n", RTDB.event(i).c_str());
327+
Firebase.printf("path: %s\n", RTDB.dataPath(i).c_str());
328+
Firebase.printf("data: %s\n", RTDB.to<const char *>(i));
329+
Firebase.printf("type: %d\n", RTDB.type(i));
330+
Serial.println();
331+
332+
// The stream event from RealtimeDatabaseResult can be converted to the values as following.
333+
bool v1 = RTDB.to<bool>(i);
334+
int v2 = RTDB.to<int>(i);
335+
float v3 = RTDB.to<float>(i);
336+
double v4 = RTDB.to<double>(i);
337+
String v5 = RTDB.to<String>(i);
338+
}
331339
}
332340
else
333341
{

examples/RealtimeDatabase/Async/NoCallback/Stream/Stream.ino

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,25 @@ void printResult(AsyncResult &aResult)
196196
{
197197
Serial.println("----------------------------");
198198
Firebase.printf("task: %s\n", aResult.uid().c_str());
199-
Firebase.printf("event: %s\n", RTDB.event().c_str());
200-
Firebase.printf("path: %s\n", RTDB.dataPath().c_str());
201-
Firebase.printf("data: %s\n", RTDB.to<const char *>());
202-
Firebase.printf("type: %d\n", RTDB.type());
203-
204-
// The stream event from RealtimeDatabaseResult can be converted to the values as following.
205-
bool v1 = RTDB.to<bool>();
206-
int v2 = RTDB.to<int>();
207-
float v3 = RTDB.to<float>();
208-
double v4 = RTDB.to<double>();
209-
String v5 = RTDB.to<String>();
199+
200+
// The Stream payload might contain many events data due to
201+
// the events are constantly changing.
202+
Firebase.printf("event count: %d\n", RTDB.eventCount());
203+
for (uint32_t i = 0; i < RTDB.eventCount(); i++)
204+
{
205+
Firebase.printf("event: %s\n", RTDB.event(i).c_str());
206+
Firebase.printf("path: %s\n", RTDB.dataPath(i).c_str());
207+
Firebase.printf("data: %s\n", RTDB.to<const char *>(i));
208+
Firebase.printf("type: %d\n", RTDB.type(i));
209+
Serial.println();
210+
211+
// The stream event from RealtimeDatabaseResult can be converted to the values as following.
212+
bool v1 = RTDB.to<bool>(i);
213+
int v2 = RTDB.to<int>(i);
214+
float v3 = RTDB.to<float>(i);
215+
double v4 = RTDB.to<double>(i);
216+
String v5 = RTDB.to<String>(i);
217+
}
210218
}
211219
else
212220
{

examples/RealtimeDatabase/Async/NoCallback/StreamConcurentcy/StreamConcurentcy.ino

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,25 @@ void printResult(AsyncResult &aResult)
211211
{
212212
Serial.println("----------------------------");
213213
Firebase.printf("task: %s\n", aResult.uid().c_str());
214-
Firebase.printf("event: %s\n", RTDB.event().c_str());
215-
Firebase.printf("path: %s\n", RTDB.dataPath().c_str());
216-
Firebase.printf("data: %s\n", RTDB.to<const char *>());
217-
Firebase.printf("type: %d\n", RTDB.type());
218-
219-
// The stream event from RealtimeDatabaseResult can be converted to the values as following.
220-
bool v1 = RTDB.to<bool>();
221-
int v2 = RTDB.to<int>();
222-
float v3 = RTDB.to<float>();
223-
double v4 = RTDB.to<double>();
224-
String v5 = RTDB.to<String>();
214+
215+
// The Stream payload might contain many events data due to
216+
// the events are constantly changing.
217+
Firebase.printf("event count: %d\n", RTDB.eventCount());
218+
for (uint32_t i = 0; i < RTDB.eventCount(); i++)
219+
{
220+
Firebase.printf("event: %s\n", RTDB.event(i).c_str());
221+
Firebase.printf("path: %s\n", RTDB.dataPath(i).c_str());
222+
Firebase.printf("data: %s\n", RTDB.to<const char *>(i));
223+
Firebase.printf("type: %d\n", RTDB.type(i));
224+
Serial.println();
225+
226+
// The stream event from RealtimeDatabaseResult can be converted to the values as following.
227+
bool v1 = RTDB.to<bool>(i);
228+
int v2 = RTDB.to<int>(i);
229+
float v3 = RTDB.to<float>(i);
230+
double v4 = RTDB.to<double>(i);
231+
String v5 = RTDB.to<String>(i);
232+
}
225233
}
226234
else
227235
{

examples/RealtimeDatabase/Async/NoCallback/StreamGSM/StreamGSM.ino

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,17 +247,25 @@ void printResult(AsyncResult &aResult)
247247
{
248248
Serial.println("----------------------------");
249249
Firebase.printf("task: %s\n", aResult.uid().c_str());
250-
Firebase.printf("event: %s\n", RTDB.event().c_str());
251-
Firebase.printf("path: %s\n", RTDB.dataPath().c_str());
252-
Firebase.printf("data: %s\n", RTDB.to<const char *>());
253-
Firebase.printf("type: %d\n", RTDB.type());
254-
255-
// The stream event from RealtimeDatabaseResult can be converted to the values as following.
256-
bool v1 = RTDB.to<bool>();
257-
int v2 = RTDB.to<int>();
258-
float v3 = RTDB.to<float>();
259-
double v4 = RTDB.to<double>();
260-
String v5 = RTDB.to<String>();
250+
251+
// The Stream payload might contain many events data due to
252+
// the events are constantly changing.
253+
Firebase.printf("event count: %d\n", RTDB.eventCount());
254+
for (uint32_t i = 0; i < RTDB.eventCount(); i++)
255+
{
256+
Firebase.printf("event: %s\n", RTDB.event(i).c_str());
257+
Firebase.printf("path: %s\n", RTDB.dataPath(i).c_str());
258+
Firebase.printf("data: %s\n", RTDB.to<const char *>(i));
259+
Firebase.printf("type: %d\n", RTDB.type(i));
260+
Serial.println();
261+
262+
// The stream event from RealtimeDatabaseResult can be converted to the values as following.
263+
bool v1 = RTDB.to<bool>(i);
264+
int v2 = RTDB.to<int>(i);
265+
float v3 = RTDB.to<float>(i);
266+
double v4 = RTDB.to<double>(i);
267+
String v5 = RTDB.to<String>(i);
268+
}
261269
}
262270
else
263271
{

examples/RealtimeDatabase/Async/NoCallback/StreamPPP/StreamPPP.ino

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -318,17 +318,25 @@ void printResult(AsyncResult &aResult)
318318
{
319319
Serial.println("----------------------------");
320320
Firebase.printf("task: %s\n", aResult.uid().c_str());
321-
Firebase.printf("event: %s\n", RTDB.event().c_str());
322-
Firebase.printf("path: %s\n", RTDB.dataPath().c_str());
323-
Firebase.printf("data: %s\n", RTDB.to<const char *>());
324-
Firebase.printf("type: %d\n", RTDB.type());
325-
326-
// The stream event from RealtimeDatabaseResult can be converted to the values as following.
327-
bool v1 = RTDB.to<bool>();
328-
int v2 = RTDB.to<int>();
329-
float v3 = RTDB.to<float>();
330-
double v4 = RTDB.to<double>();
331-
String v5 = RTDB.to<String>();
321+
322+
// The Stream payload might contain many events data due to
323+
// the events are constantly changing.
324+
Firebase.printf("event count: %d\n", RTDB.eventCount());
325+
for (uint32_t i = 0; i < RTDB.eventCount(); i++)
326+
{
327+
Firebase.printf("event: %s\n", RTDB.event(i).c_str());
328+
Firebase.printf("path: %s\n", RTDB.dataPath(i).c_str());
329+
Firebase.printf("data: %s\n", RTDB.to<const char *>(i));
330+
Firebase.printf("type: %d\n", RTDB.type(i));
331+
Serial.println();
332+
333+
// The stream event from RealtimeDatabaseResult can be converted to the values as following.
334+
bool v1 = RTDB.to<bool>(i);
335+
int v2 = RTDB.to<int>(i);
336+
float v3 = RTDB.to<float>(i);
337+
double v4 = RTDB.to<double>(i);
338+
String v5 = RTDB.to<String>(i);
339+
}
332340
}
333341
else
334342
{

0 commit comments

Comments
 (0)