Skip to content

Commit

Permalink
Update examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Jun 15, 2023
1 parent a560f0a commit 8fa1311
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
18 changes: 14 additions & 4 deletions examples/RTDB/DataChangesListener/Callback/Callback.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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))
Expand All @@ -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!
}
}
12 changes: 11 additions & 1 deletion examples/RTDB/DataChangesListener/MultiPath/MultiPath.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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!
}
}
12 changes: 11 additions & 1 deletion examples/RTDB/DataChangesListener/NoCallback/NoCallback.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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!
}
}

0 comments on commit 8fa1311

Please sign in to comment.