mobizt / Firebase-ESP32

[DEPRECATED]🔥 Firebase RTDB Arduino Library for ESP32. The complete, fast, secured and reliable Firebase Arduino client library that supports CRUD (create, read, update, delete) and Stream operations.
MIT License
415 stars 118 forks source link

Can esp32 handle simultaneous post different sensor data and stream the database changes? #106

Closed vamsikrishnaA9 closed 3 years ago

vamsikrishnaA9 commented 3 years ago

Hi, can esp32 post multiple sensors data and stream database data at one time on different cores? When i tried to post data simultaneously and streaming database changes, even on different cores, esp32 was resetting. I think i understand it was due to the bad management of ram or stack memory from my side.If it is, suggest me way to post data and stream data at same time on different cores. How much memory is needed to post a boolean data to firebase? I have 4 different sensors, they need to uplaod whenever they change . On the other core esp is handling firebase stream data. Thank you.

mobizt commented 3 years ago

Since the latest update, the simultaneously connection is disable by default and you can enable it via this function.

In PC environment that has a lot of memory, the simultaneously TCP/IP connection has no issue. In the embedded device, it may cause the issue during the SSL handshake which consumed large memory (PSRAM is not used).

When WiFi disconnected or the stream timeout occurred, any new http request from stream resuming or Firebase call (get, set, update or push), the time and memory consuming process SSL handshaking is required as the last connection was closed.

The WiFi client will hold the resources that uses in SSL handshake process as long as the last connection establish and stay connected to server (keep-alive connection) which this will minimize the time for the later data transmission as new SSL handshaking is not required as a connection is alive.

When you use only two Firebase Data objects, one for stream and other for Firebase calls, your free heap is about 160k - 180k during the server connection established and will return to 240k - 250k when connection closed due to WiFi disconnected or the method stopWiFiClient was called.

The Firebase Data object creates a socket connection at a time then you may need more Firebase Data objects to send the data simultaneously which your device may running out of memory and exception reset occurred.

Since ESP32 has single RF radio channel, the simultaneously connection is not true and the attempt to do this is nonsense.

The better way is storing all sensors data in a single JSON object and send it to the server frequently as wanted using a Firebase Data object.