|
1 | 1 | /** |
2 | 2 | * ABOUT: |
3 | 3 | * |
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 |
5 | 5 | * via SSE Streaming connection. |
6 | 6 | * |
7 | 7 | * This example uses the UserAuth class for authentication, and the DefaultNetwork class for network interface configuration. |
@@ -212,17 +212,25 @@ void printResult(AsyncResult &aResult) |
212 | 212 | { |
213 | 213 | Serial.println("----------------------------"); |
214 | 214 | 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 | + } |
226 | 234 | } |
227 | 235 | else |
228 | 236 | { |
|
0 commit comments