I have a project that will be receiving data from serial port, adding a timestamp and then saving records to SD card.
What I want to do next is to upload any records on the SD card when cloud is available and store them when it is not.
I am looking for ideas to implement the functionality below in firmware.
- Check cloud is available
- If available then start sending batches of records from log file to cloud
- If all records are sent then rewrite log file (start with clean 0 record file again)
- Otherwise, remove records that have been sent (only leave unsent records)
The thing that I am not sure about is how to write into a single record without having to read all data into ram first and not sure if there is a “getNumberOfLines” function. Maybe I read line by line into a single variable (to simply count number of items) and have a pointer at end of the file that indicates last line read.
Therefore I would open the file, determine how many lines exist and read the last line to get current lastSent pointer.
Then close and reopen the file and scan through until last lineSent and start sending more data.
If I reach end of file then the file can be re-written back to zero bytes?
Hopefully, I am missing something and it is more straight forward than this.