-1

I was wondering if it is possible to save lots of data( exp: one year data) in data logger shield and then read them from serial port without ejecting the SD card... this part of my question is fine... the main subject is that i want to read specific date's data from the logger... To explain this better, lets say you have a humidity sensor and saved it's data for a year. Now you want to send the last 6 month's data to your phone via bluetooth. Is it possible? Also, i wanted to use the circular buffer but that doesn't seem like a good idea because it's costly... any ideas will be such a great help.

  • how many lines are logged in one day? – Juraj Dec 5 '19 at 13:02
  • Is it important? i wanted to lower the daily sampling, so maybe 2 times... – 201 Dec 5 '19 at 13:47
  • ok, it is not too much for one year. to copy part of the file to Serial you would read the file line by line from the beginning and start printing after you find the line with the requested start date. – Juraj Dec 5 '19 at 14:15
0

I see a few questions (reading specific data from an SD) and the circular buffer; I think these are two different 'problems'.

Reading specific data from an SD

It depends how you save your data. Do you make one big file, or you create daily a new file for example?

Assuming the last, it's relatively easy, just sent the file contents of the files within a certain date.

In case you have a big file, you need to parse the file, in specific the time stamps you have to include in the file, and send everything within certain dates.

If this takes too long parsing, you could create a second file that contains the starting points (e.g. byte offset) for every day. So e.g. Jan 1 -> 0 means Jan 1 starts at byte 0, Jan 2 -> 3633 starts at byte 3633; you can use some kind of seek function to start reading the data file starting from date; and continuing also checking the end date's byte offset.

You can get the time stamp of a file:

void dateTime(uint16_t* date, uint16_t* time) 
{
    DateTime now = rtc.now(); 
    // return date using FAT_DATE macro to format fields 
    *date = FAT_DATE(now.year(), now.month(), now.day());
}

You can start reading from a certain position in a file by using the fseek function, see https://www.arduino.cc/en/Reference/FileSeek.

Circular buffer

This relates to sending bytes (via a peripheral/bluetooth). It is not costly at all. What you do is create a circular buffer (e.g. 50 bytes or whatever). Than you start writing bytes into it (which you copy from the SD file increasing the buffer space. Than you start sending bytes from it, decreasing the buffer space.

I never used Bluetooth, so I don't know how the packet (and size) is sent; if you can just sent packages of a certain or fixed length, you don't need a circular buffer, just keep reading e.g. 50 bytes, put it in a fixed array, send it, and load it again etc until all bytes are sent.

| improve this answer | |
  • The idea was to ask for any data history i want through mu cellphone... I wanted to make different files with specific time stamps but then if the period i want wasn't in the files it would be a problem... – 201 Dec 5 '19 at 13:51
  • And another thing i don't know is how can i specify a certain starting point for my files? – 201 Dec 5 '19 at 13:53
  • You can get the time by using: void dateTime(uint16_t* date, uint16_t* time) { DateTime now = rtc.now(); // return date using FAT_DATE macro to format fields *date = FAT_DATE(now.year(), now.month(), now.day()); – Michel Keijzers Dec 5 '19 at 14:00
  • Can i also get the period of different times? – 201 Dec 5 '19 at 14:00
  • So after you write a file (each day), or for the last time once per day, you can get the date back, although it might be even easier to write the date in the file name (data_yymmdd.log) – Michel Keijzers Dec 5 '19 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.