rykovv / spiffs_circular_queue

ESP-IDF and PlatformIO compatible library for a circular queue or circular FIFO buffer over SPIFFS.
https://rykovv.github.io/spiffs_circular_queue/
MIT License
13 stars 4 forks source link

Some doubts regarding the Library #2

Closed Thermelgy-Repo closed 2 years ago

Thermelgy-Repo commented 2 years ago

Dear @rykovv, Thank you for your support. I have a couple of questions regarding this library :

For me my application is to use this concept of circular queue to store data when the network is down. My data is 1KB of size in each message, I am planning to keep the size of 8MB for buffer memory which will be sufficient to store data for an adequate days.

  1. Plz give some of your suggession on this?
  2. Can I use the circular buffer memory to a particular file name.
  3. Can the size can be 8MB?
rykovv commented 2 years ago

Hi @Thermelgy-Repo

I am glad that it turned useful for you. Regarding your questions:

  1. I have tested the library with 256 elements of 256 bytes (64KB) and it worked well. It is mounted on SPIFFS which means it will reliably work as far as you keep the used (or intended to be used) space under 75% of assigned partition space. That is, if you want to have 8MB buffer, make sure you have 16MB flash and in the partition table you assigned 10MB to SPIFFS. If you want to use 100% of space having 8MB flash, then you will need to use EEPROM directly. In that case, the library will not be useful. It would be an interesting extension to add different mediums.
  2. Of course, you can modify next line in spiffs_circular_queue.cpp const char send_queue_filename[] = "/spiffs/send_queue.data"; ///< Path to store the queue data in SPIFFS with any other file name. Just keep consistency with the rest of code.
  3. Yes, as far as you have extra 2MB of space (see 1). But anyway, I would definitely make a test before using it in my project, it shouldn't be difficult. Make next changes in spiffs_circular_queue.h: `

    define SPIFFS_CIRCULAR_QUEUE_MAX_SIZE (8192)

    define SPIFFS_CIRCULAR_QUEUE_ITEM_SIZE (1024)

    ` You can further write a testbench writing a known value in each element throughout the whole queue, and then read it making comparisons. That will lead you out of the doubt.

Thermelgy-Repo commented 2 years ago

Thank you @rykovv for your answers,

It will be great, if you clarify some more doubts :

I found the front and rear is initialized to 0 everytime.

I suspect that we can lost the track of next queue after a restart? Do we need to store front & rear in SPIFFS?

Thermelgy-Repo commented 2 years ago

Also tried to compile the code using Arduino IDE, but missing the <sys/stat.h>. I thought it is the standard C library. Kindly help.

rykovv commented 2 years ago

@Thermelgy-Repo,

Do we need to store front & rear in SPIFFS?

Absolutely. We have to store y retrieve them manually. In the current implementation, they are not written into the SPIFFS. You have to handle them separately. This peculiarity is given due to my project specifics. I used EEPROM for storing the config (queue pointers included) and the SPIFFS for the pending data. In a future version, I will make the pointers seamless to the user and improve the storage space usage.

Also tried to compile the code using Arduino IDE, but missing the <sys/stat.h>. I thought it is the standard C library. Kindly help.

The library was initially designed to work with the ESP32 MCU. Make sure Arduino IDE makes use of the xtensa toolchain for your project to be compiled. If you are not working with the ESP MCUs, then you will have to modify the library or check compatibility of your project with the current implementation. stat() function from <sys/stat.h> is used to check if the file exists. It is implemented in the ESP core (xtensa toolchain). You may be interested in this issue. See also this example.

rykovv commented 2 years ago

I am working on the next version of the library, in which I will seamlessly add EEPROM as a storage medium and make queue nodes with variable size, so the resources are better exploited. Stay tuned!