From 8fa13115d71ffe32f38796a26e3d332e56cc872b Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 15 Jun 2023 09:37:14 +0700 Subject: [PATCH] Update examples. --- .../DataChangesListener/Callback/Callback.ino | 18 ++++++++++++++---- .../MultiPath/MultiPath.ino | 12 +++++++++++- .../NoCallback/NoCallback.ino | 12 +++++++++++- .../SingleDataObject/SingleDataObject.ino | 12 +++++++++++- 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/examples/RTDB/DataChangesListener/Callback/Callback.ino b/examples/RTDB/DataChangesListener/Callback/Callback.ino index e2ac9598d..d3f03dfaf 100644 --- a/examples/RTDB/DataChangesListener/Callback/Callback.ino +++ b/examples/RTDB/DataChangesListener/Callback/Callback.ino @@ -153,9 +153,13 @@ void setup() stream.setBSSLBufferSize(2048 /* Rx in bytes, 512 - 16384 */, 512 /* Tx in bytes, 512 - 16384 */); #endif - // You can use TCP KeepAlive For more reliable stream operation and tracking the server connection status, please read this for detail. - // https://github.com/mobizt/Firebase-ESP-Client#enable-tcp-keepalive-for-reliable-http-streaming - // stream.keepAlive(5, 5, 1); +// You can use TCP KeepAlive For more reliable stream operation and tracking the server connection status, please read this for detail. +// https://github.com/mobizt/Firebase-ESP-Client#enable-tcp-keepalive-for-reliable-http-streaming +// You can use keepAlive in ESP8266 core version newer than v3.1.2. +// Or you can use git version (v3.1.2) https://github.com/esp8266/Arduino +#if defined(ESP32) + stream.keepAlive(5, 5, 1); +#endif if (!Firebase.RTDB.beginStream(&stream, "/test/stream/data")) Serial.printf("sream begin error, %s\n\n", stream.errorReason().c_str()); @@ -197,7 +201,7 @@ void loop() #if defined(ARDUINO_RASPBERRY_PI_PICO_W) Firebase.RTDB.runStream(); - + #endif if (Firebase.ready() && (millis() - sendDataPrevMillis > 15000 || sendDataPrevMillis == 0)) @@ -215,4 +219,10 @@ void loop() dataChanged = false; // When stream data is available, do anything here... } + + // After calling stream.keepAlive, now we can track the server connecting status + if (!stream.httpConnected()) + { + // Server was disconnected! + } } diff --git a/examples/RTDB/DataChangesListener/MultiPath/MultiPath.ino b/examples/RTDB/DataChangesListener/MultiPath/MultiPath.ino index a4c63a37c..d0e5319bf 100644 --- a/examples/RTDB/DataChangesListener/MultiPath/MultiPath.ino +++ b/examples/RTDB/DataChangesListener/MultiPath/MultiPath.ino @@ -162,7 +162,11 @@ void setup() // You can use TCP KeepAlive For more reliable stream operation and tracking the server connection status, please read this for detail. // https://github.com/mobizt/Firebase-ESP-Client#enable-tcp-keepalive-for-reliable-http-streaming - // stream.keepAlive(5, 5, 1); + // You can use keepAlive in ESP8266 core version newer than v3.1.2. + // Or you can use git version (v3.1.2) https://github.com/esp8266/Arduino +#if defined(ESP32) + stream.keepAlive(5, 5, 1); +#endif // The data under the node being stream (parent path) should keep small // Large stream payload leads to the parsing error due to memory allocation. @@ -240,4 +244,10 @@ void loop() dataChanged = false; // When stream data is available, do anything here... } + + // After calling stream.keepAlive, now we can track the server connecting status + if (!stream.httpConnected()) + { + // Server was disconnected! + } } diff --git a/examples/RTDB/DataChangesListener/NoCallback/NoCallback.ino b/examples/RTDB/DataChangesListener/NoCallback/NoCallback.ino index a7940e670..4cccbaa89 100644 --- a/examples/RTDB/DataChangesListener/NoCallback/NoCallback.ino +++ b/examples/RTDB/DataChangesListener/NoCallback/NoCallback.ino @@ -114,7 +114,11 @@ void setup() // You can use TCP KeepAlive For more reliable stream operation and tracking the server connection status, please read this for detail. // https://github.com/mobizt/Firebase-ESP-Client#enable-tcp-keepalive-for-reliable-http-streaming - // stream.keepAlive(5, 5, 1); + // You can use keepAlive in ESP8266 core version newer than v3.1.2. + // Or you can use git version (v3.1.2) https://github.com/esp8266/Arduino +#if defined(ESP32) + stream.keepAlive(5, 5, 1); +#endif if (!Firebase.RTDB.beginStream(&stream, "/test/stream/data")) Serial.printf("sream begin error, %s\n\n", stream.errorReason().c_str()); @@ -203,4 +207,10 @@ void loop() #endif Serial.println(); } + + // After calling stream.keepAlive, now we can track the server connecting status + if (!stream.httpConnected()) + { + // Server was disconnected! + } } \ No newline at end of file diff --git a/examples/RTDB/DataChangesListener/SingleDataObject/SingleDataObject.ino b/examples/RTDB/DataChangesListener/SingleDataObject/SingleDataObject.ino index 6c22b6b75..810bc6dc3 100644 --- a/examples/RTDB/DataChangesListener/SingleDataObject/SingleDataObject.ino +++ b/examples/RTDB/DataChangesListener/SingleDataObject/SingleDataObject.ino @@ -118,7 +118,11 @@ void setup() // You can use TCP KeepAlive For more reliable stream operation and tracking the server connection status, please read this for detail. // https://github.com/mobizt/Firebase-ESP-Client#enable-tcp-keepalive-for-reliable-http-streaming - // fbdo.keepAlive(5, 5, 1); + // You can use keepAlive in ESP8266 core version newer than v3.1.2. + // Or you can use git version (v3.1.2) https://github.com/esp8266/Arduino +#if defined(ESP32) + fbdo.keepAlive(5, 5, 1); +#endif // The data under the node being stream (parent path) should keep small // Large stream payload leads to the parsing error due to memory allocation. @@ -163,4 +167,10 @@ void loop() fbdo.stringData().c_str()); } } + + // After calling stream.keepAlive, now we can track the server connecting status + if (!fbdo.httpConnected()) + { + // Server was disconnected! + } } \ No newline at end of file