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

Stream Event Type Patch #14

Closed GuilhermeKROSS closed 5 years ago

GuilhermeKROSS commented 5 years ago

Hi I'm having some problem to detect a incoming event using stream functions. I can only detect a stream data when the event type is "PUT". When it's "PATCH" i can't. I know this because i was using another firebase library where i could choose the event type to get the stream data. As this library is much more reliable, i'd like to know if there is a way to get PACHT event type on STREAM.

Thanks

mobizt commented 5 years ago

Actually this library catches put and patch event types already then trig the dataAvailable status and raise the callback function. But the put or patch event may miss in case of unreliable internet connection take place, stream timeout. The library will routinely check keep-alive event that missed more than 30 seconds to determine stream timeout. Cancel and auth_revoked event types are not catch.

mobizt commented 5 years ago

Now I add support the event type already in v 2.3.7 please update.

GuilhermeKROSS commented 5 years ago

Thanks for you answer. I have updated my lib, but the problem keeps occuring. I can only read PUT events. I have a ionic 3 framework app which posts the data for my esp32. When the app changes a existing value, or i do it manually on firebase, the Stream can identify the event. But when the app posts a new key, the stream does not catches the data

mobizt commented 5 years ago

Patch, put and post are some of many methods used in http request that was sent by client. Server processes client request and returns response based on its API.

Patch is not just you manual update or edit data using Firebase Console. The REST client should send patch http request to server to let server know the connection method or how to process and send back the proper response payload which generally the payload that client sent in case of Firebase RTDB.

In your app you need to send http header like this

GET /uri_that_points_to_endpoint HTTP/1.1 For GET http request when you want to read data.

PUT /uri_that_points_to_endpoint HTTP/1.1 For PUT http request when you want to set new data to the existing node or create new node with new data if that nod is not previously existed.

POST /uri_that_points_to_endpoint HTTP/1.1 For POST http request when you want to append new data to defined node but within the unique (random) parent key.

PATCH /uri_that_points_to_endpoint HTTP/1.1 For PATCH http request when you want to update any child node under the defined database path. If that path is not exist, it will create new one for you.

For our Firebase Client Library

Firebase.setXXX <- Perform PUT http request.

Firebase.pushXXX <- Perform POST http request.

Firebase.updateNode <- Perform PATCH http request.

Firebase.readStream <- Perform GET http request with header that let server know to keep the connection alive.

Please check the example Different_object_stream.ino

Firebase sever will send stream patch event to client when data of node or its child at database path get update by data from patch http request.

Firebase sever will send stream put event to client when data of node or its child at database path replaced by data from other put or post http request or you edit data in console.