mobizt / FirebaseClient

🔥Async Firebase Client for Arduino. Supports Realtime Database, Cloud Firestore Database, Firebase Storage, Cloud Messaging, Google Cloud Functions and Google Cloud Storage.
MIT License
134 stars 8 forks source link

How get Sync data AND stream data from setup #11

Closed jiperez11 closed 8 months ago

jiperez11 commented 8 months ago

I have error in the setup when use Sync function AND stream function

mobizt commented 8 months ago

You can get sync data in setup as in the sync example but for stream you need to polling in loop.

For multitasking that supported by ESP32 FreeRTOS, you can set the FreeRTOS task for stream and all polling tasks inside the setup.


void setup()
{

    // Set up code
    // ...

    ms = millis();
    while (app.isInitialized() && !app.ready() && millis() - ms < 120 * 1000)
        ;

    app.getApp<RealtimeDatabase>(Database);

    auto loopTask = [](void *pvParameters)
    {
        for (;;)
        {
            app.loop();

            Database.loop();

            if (app.ready())
            {
                // your other code here
                // For non-callback stream, you can check the information that provided from AsyncResult that assigned with the asyn function (stream) 
            }
            vTaskDelay(10 / portTICK_PERIOD_MS);
        }
    };

    xTaskCreatePinnedToCore(loopTask, "loopTask", 8000, NULL, 3, NULL, 1 /* must be core 1 for network task */);

}

Anyway, you should avoid using FreeRTOS as it required the memory reserved for stack.

Polling something in main loop is safer and use lesser memory.

FYI. I provide the discussions section which you can post a question there.