Enable Javascript


Last Arduino/ESP project (click to open)

Gebruikerswaardering: 3 / 5

Ster actiefSter actiefSter actiefSter inactiefSter inactief
 


Information from header file:

// SimpleDB by Ewald Kendziorra sr, www.kendziorra.nl
// I use it with my Arduino NodeMCU v2 Shield
//
// SimpleDB is not writen as a real library, you can use it as a regular INO file.
//   Add the files 'db.ino' and 'db.h' to your own Arduino/ESP8266 project.
//   If desired, it is easy-to-edit.
//
//                 SIMPLE - FLEXIBLE - SMALL - QUICKLY? 
// Simple:   Create or Open a DB with only four parameters.
//           You do not create tables and fields.
// Flexible: One table with fixed record length and "flexible fields width".
//           We use the '|' char as field separator.
//           Records can be mixed with:
//            - "JSON"  style 'name|value|' fields
//            - "Table" style      'value|' fields
//           After reading a record we use tokenization to breaking 
//           the record data in fields.
//           (there is a simple JSON/Table style Parser in the demo.ino)
// Small:    ~2% of program storage space (NodeMCU v2/ESP8266-12E)
//           ~2% of dynamic memory
//           <250 lines off code
// Quickly?: sequential search, seek time to find the key on rec# 1000: ~280ms
// =================================================================================
//   initDb   | Create or Open the database with four values
//              (pin, dbFile, copyFile, max data width)
//   nrRec    | set 'int16_t dbR', the nummer of records
//              tombstone records are excluded
//   findRec  | key found? 'dbF.seek()' is set to the first byte of te record
//              sequential key search
//   addRec   | append a new record
//              auto update 'dbR'
//              if the key not exist then 'dbErr' is set, doubles are not allowed
//   writeRec | overwrite an existing record
//              if the key not exist then 'addRec()'
//   readRec  | find key in DB
//              if found then the record is in buffer 'char* dbB'
//   delRec   | mark a record as tombstone
//              auto update 'dbR'
//              delete tombstones with 'comprDb()'
//   listRec  | list DB to Serial
//              boolean data = false: list with keys
//              boolean data = true: list with keys and data
//   cmprDb   | copy the DB, then remove tombstone records (compress DB)
//   dbOpen   | test: SD and DB are open? if not: open SD and or DB
//   dbErr    | 'enum errCode{}'
//               _OK,         | no problems
//               SD_ERR,      | sd error
//               DB_EMPTY,    | no record(s) in db
//               MAX_REC,     | max records in db
//               MAX_CHARS,   | key or data: too many characters
//               REC_EXIST,   | record already exists
//               NOT_FOUND,   | record not found
//               REMOVE_ERR,  | delete file error
//               CORRUPT,     | db corrupt
//               DIF_NR,      | difference in number of records
//               NEW_ERR      | file not erased
// =================================================================================
// ################################################################################# 
// If the SD card is removed you'll have to restart the program (SD library problem)
// ################################################################################# 
// Max 32,767 records posible, but that is a lot for sequential search.
// Fields data: only chars, convert numbers to char* (use sprintf()).
// Keys fixed width: 3 chars, any combination of three characters is valid
//     (the fixed width can be changed in this header file)
//   For example:  000/999
//     or create a group code: a00/a99...z00/z99...A00\A99...Z00/Z99
//     I use 000/999 to save "program vars" and i use "group codes" for:
//       A(larm), G(arden), F(acade), M(ilieu) and R(ooms)
//   Keys must be UNIQUE, doubles are not allowed.
// Examples:
//   Use a '|' char as delimters between the fields and at the end of the string (use sprintf()).
//   After 'readRec()' parse string back in tokens with 'strtok_r()' (see Parser in the demo.ino).
//     char key[kyW + 1];      // (global var)  key string holder
//     char dataR[dataW + 1];  // (global var)  data string holder
//     enum {OFF, ON};         // (global enum) Room lamps: OFF or ON
//     strcpy(key, "R00");     // key: R(oom) #00
//     sprintf(dataR, "%s|%s|%s|%d|%s|%d|%s|%d|",  // format data string
//         "room", "Living",  // room name
//         "lamp1", OFF,      // is enum "0"
//         "lamp2", ON,       // is enum "1"
//         "dim2",  5);       // string in dataR = "room|Living|lamp1|0|lamp2|1|dim2|5|"
//     addRec(key, dataR);        // add record to DB
//   KEY: 3 chars (in next three examples: 'T00' - 'R00' - 't00')
//                     ** in JSON style: name|value, then you can use different field names **
//                     -----------------------------------------------------------------------
//                     max data width by example 50, trailing white spaces added in 'addRec()'
//   key               "T00"
//   data:             "tempIn|28.4|tempOut|11.1|time|1412345675|"
//   in db file: "T00|0|tempIn|28.4|tempOut|11.1|time|1412345675|   "< recEnd
//   key               "R00"
//   data:             "room|Living|lamp1|0|lamp2|1|dim2|5|"
//   in db file: "R00|0|room|Living|lamp1|0|lamp2|1|dim2|5|         "< recEnd
//                     ---------------------------------------------
//   can mixed with    ** Table style, fixed field names **
//   field names       (0):tempIn, (1):tempOut, (3):time
//                     ---------------------------------------------
//   key               "t00"
//   data:             "28.4|11.1|1412345675|"
//   in db file: "t00|0|28.4|11.1|1412345675|                       "< recEnd
//                    ^ = tombstone '|0|' marker (added by program)
// =================================================================================