-1

Good day! I seem to be having trouble creating multiple tables with EDB. I am using Arduino UNO and SD Card module to save my db.

Here is my Serial.

Here is my serial
Here is my table declaration.

struct LogEvent {
  int id;
  String fname;
  float temperature;
}
logEvent;

struct SecondEvent {
  int id;
  String lastname;
}
secondEvent;  

Here is my db.create() code.

db.create(0, TABLE_SIZE, (unsigned int)sizeof(logEvent));
db.create(0, TABLE_SIZE, (unsigned int)sizeof(secondEvent));

Now, when I try to retrieve, it is a whack. Here is my save and retrieve code.

void createRecords(int num_recs, float correctTemperature)
{
    Serial.print("Creating Records... ");
    for (int recno = 1; recno <= num_recs; recno++)
    {
      correctId++;
      logEvent.id = correctId;
      logEvent.fname = "Brix Nicholson";
      logEvent.temperature = correctTemperature;
      secondEvent.id = correctId;    
      EDB_Status result = db.appendRec(EDB_REC logEvent);
      if (result != EDB_OK) printError(result);   
    }
  Serial.println("DONE");
}

void createRecordSecondEvent()
 {
   correctId++;
   secondEvent.id = correctId;
   secondEvent.lastname = "Secretaria";
   EDB_Status result = db.appendRec(EDB_REC secondEvent);
   if (result != EDB_OK) printError(result);
 }  

void selectLastRecord()
{
  int lastRecNum = db.count();
  EDB_Status result = db.readRec(lastRecNum, EDB_REC logEvent);
  if(result == EDB_OK)
   {
     Serial.print(" ID: ");
     Serial.print(logEvent.id);
     Serial.print(" Name: ");
     Serial.print(logEvent.fname);
     Serial.print(" Temp: ");
     Serial.println(logEvent.temperature);
   }
   else printError(result);
}

void selectLastSecondRecord()
{
 int lastRecNum = db.count();
 EDB_Status result = db.readRec(lastRecNum, EDB_REC secondEvent);
 if(result == EDB_OK)
  {
   Serial.print("Second Event ID: ");
   Serial.print(secondEvent.id);
   Serial.print("Last Name: ");
   Serial.print(secondEvent.lastname);
  }
  else printError(result);
}
  • What's the trouble? – user31481 Jan 21 '18 at 9:24
  • I missed about the address, its all good now. Thank you! – Xirb Jan 21 '18 at 9:55
1

I think I have found the answer to my problem. I forgot to increase the address of the EDB_header.

I wrote:

db.create(0, TABLE_SIZE, (unsigned int)sizeof(logEvent));
db.create(0, TABLE_SIZE, (unsigned int)sizeof(secondEvent));  

Instead of:

db.create(0, TABLE_SIZE, (unsigned int)sizeof(logEvent));
db.create(1, TABLE_SIZE, (unsigned int)sizeof(secondEvent));
| improve this answer | |
1

I think I have found the answer to my problem. I forgot to increase the address of the EDB_header.

you're right about increasing the address of EDB_header. But the address is the position from where the library starting reading/writing.

if you have a look at https://github.com/jwhiddon/EDB/blob/master/EDB.cpp#L66 and https://github.com/jwhiddon/EDB/blob/master/EDB.cpp#L34

the library writes a fixed size of the header in the binary format which includes

  1. a magic byte to recognize the EDB header
  2. the number of records currently present in the table which is 0 at of this time
  3. size of your single record
  4. the size of the table (max amount of memory that the table is allowed to consume)

and to write a new record https://github.com/jwhiddon/EDB/blob/master/EDB.cpp#L93

so in

db.create(0, TABLE_SIZE, (unsigned int)sizeof(logEvent));
db.create(1, TABLE_SIZE, (unsigned int)sizeof(secondEvent));

the second statement will override the old header excluding the first byte (0'th position)

the solution to your problem will be

unsigned int FIRST_TABLE_HEADER_POSITION = 0;
db.create(FIRST_TABLE_HEADER_POSITION, FIRST_TABLE_SIZE, (unsigned int)sizeof(logEvent));

unsigned int SECOND_TABLE_HEADER_POSITION = FIRST_TABLE_HEADER_POSITION + (unsigned int)sizeof(EDB_Header) + FIRST_TABLE_SIZE;

db.create(SECOND_TABLE_HEADER_POSITION, SECOND_TABLE_SIZE, (unsigned int)sizeof(secondEvent));

now you can use

EDB_Status result = db.open(FIRST_TABLE_HEADER_POSITION );

and

db.close();
EDB_Status result = db.open(SECOND_TABLE_HEADER_POSITION );
| improve this answer | |

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.